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

来源:互联网 发布:中国能源战略知乎 编辑:程序博客网 时间:2024/06/02 00:50

添加一块硬盘

1
2
3
4
5
6
7
# fdisk -l
Disk /dev/vdb53.7 GB53687091200 bytes
16 heads63 sectors/track104025 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 identifier0x00000000


用fdisk命令进入分区界面

1
2
3
4
5
6
7
8
9
10
# fdisk /dev/vdb
Device contains neither a valid DOS partition tablenor SunSGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb5f18769.
Changes will remain in memory onlyuntil you decide to write them.
After thatof coursethe 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-104025default 1):     //
Using default value 1
Last cylinder+cylinders or +size{K,M,G} (1-104025default 104025)25600M  //25G
          //Supported10^NKB (KiloByte)MB (MegaByte)GB (GigaByte)
            2^NK  (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-104025default 52015)
Using default value 52015
Last cylinder+cylinders or +size{K,M,G} (52015-104025default 104025):        //
Using default value 104025


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

1
2
3
4
5
6
7
8
9
10
11
Command (m for help)p    //p
Disk /dev/vdb53.7 GB53687091200 bytes
16 heads63 sectors/track104025 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 identifier0xb7a8f045
   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/vdb53.7 GB53687091200 bytes
16 heads63 sectors/track104025 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 identifier0xb7a8f045
   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
mount /dev/vdb1 /vdb1mount /dev/vdb2 /vdb2


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


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

1
2
3
4
5
6
7
8
# 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  


原创粉丝点击