linux下使用fdisk命令进行硬盘分区

简介:

添加一块硬盘

1
2
3
4
5
6
7
# fdisk -l
Disk  / dev / vdb:  53.7  GB,  53687091200  bytes
16  heads,  63  sectors / track,  104025  cylinders
Units  =  cylinders of  1008  *  512  =  516096  bytes
Sector size (logical / physical):  512  bytes  /  512  bytes
I / O size (minimum / optimal):  512  bytes  /  512  bytes
Disk identifier:  0x00000000


用fdisk命令进入分区界面

1
2
3
4
5
6
7
8
9
10
# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a  new  DOS disklabel  with  disk identifier 0xb5f18769.
Changes will remain  in  memory only, until you decide to write them.
After that, of course, the previous content won 't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It' s strongly recommended to
          switch  off the mode (command  'c' ) and change display units to
          sectors (command  'u' ).
Command (m  for  help):



1
2
3
4
5
6
7
8
9
10
11
12
13
Command (m  for  help): n     // 输入n新建一个分区
Command action
    e   extended     //e是扩展分区
    p   primary partition (1-4)     //p是主分区
p    //选择p
Partition number (1-4): 1      //分区号
First cylinder (1-104025,  default  1):      //默认回车就行
Using  default  value 1
Last cylinder, +cylinders or +size{K,M,G} (1-104025,  default  104025): 25600M   //可以输入具体要分多少空间给这个分区,这里我分25G
 
参考:
           //Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
             2^N: K  (KibiByte), M (MebiByte), G  (GibiByte)


分第二个分区

1
2
3
4
5
6
7
8
9
10
Command (m  for  help): n
Command action
    e   extended
    p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (52015-104025,  default  52015): 
Using  default  value 52015
Last cylinder, +cylinders or +size{K,M,G} (52015-104025,  default  104025):         //这里直接回车默认所有空间
Using  default  value 104025


查看刚刚分的2个区。可以看到vdb1和vdb2

1
2
3
4
5
6
7
8
9
10
Command (m  for  help): p     //输入p查看分区
Disk /dev/vdb: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7a8f045
    Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       52014    26215024+  83  Linux
/dev/vdb2           52015      104025    26213544   83  Linux


保存分区退出(一定要保存,不然得重来了。)

1
2
3
4
Command (m  for  help): w     //输入w保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.


查看分好的分区

1
2
3
4
5
6
7
8
9
10
# fdisk -l
Disk /dev/vdb: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7a8f045
    Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       52014    26215024+  83  Linux
/dev/vdb2           52015      104025    26213544   83  Linux


格式化分区

1
# mkfs.ext3 /dev/vdb1
1
# mkfs.ext3 /dev/vdb2


创建挂载文件夹

1
# mkdir /vdb1 /vdb2


挂载分区到文件夹

1
2
# mount /dev/vdb1 /vdb1
# mount /dev/vdb2 /vdb2


分区完成,数据写入挂载的文件夹就写入到硬盘了。


但是重启之后linux不会自动挂载,需要在/etc/fstab文件添加后面2条。保存之后下次重启就会自动挂载了。

1
2
3
4
5
6
7
# vim /etc/fstab
tmpfs          /dev/shm        tmpfs   defaults        0 0
devpts          /dev/pts        devpts   gid=5,mode=620        0 0
sysfs          /sys          sysfs   defaults        0 0
proc           /proc           proc   defaults        0 0
/dev/vdb1        /vdb1          ext3   defaults        1 2
/dev/vdb2        /vdb2          ext3   defaults        1 2


另外:可通过cat /proc/partitions 查看分区信息

1
2
3
4
5
6
7
8
9
10
[root@myslaver ~] # cat /proc/partitions
major    minor   #blocks name
  252        0   52428800 vda
  252        1     512000 vda1
  252        2    7875584 vda2
  252       16   52428800 vdb
  252       17   26215024 vdb1
  252       18   26213544 vdb2
  253        0    7036928 dm-0
  253        1     835584 dm-1


      本文转自谢育政 51CTO博客,原文链接:http://blog.51cto.com/kurolz/1873063 ,如需转载请自行联系原作者






相关文章
|
16小时前
|
Linux Windows
虚拟机添加新硬盘之linux系统篇
虚拟机添加新硬盘之linux系统篇
|
1天前
|
安全 Linux 测试技术
|
1天前
|
安全 Linux Windows
Linux中Shutdown命令使用介绍
Linux中Shutdown命令使用介绍
|
2天前
|
缓存 关系型数据库 Linux
Linux目录结构:深入理解与命令创建指南
Linux目录结构:深入理解与命令创建指南
|
2天前
|
数据挖掘 Linux vr&ar
Linux命令实战:解决日常问题的利器
Linux命令实战:解决日常问题的利器
|
2天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
15 0
|
2天前
|
安全 Linux Shell
linux基础命令详解
linux基础命令详解
8 0
|
3天前
|
Linux
Linux常用命令2
Linux常用命令2
5 0
|
3天前
|
Linux
Linux常用命令1
Linux常用命令1
9 0