CentOS6.8 使用 fdisk 命令 手动硬盘分区
一、前言
二、fdisk命令手动分区步骤
第一步、 新增一块磁盘
第二步、查看所有硬盘及分区 fdisk -l
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000db990
Device Boot Start End Blocks Id System
/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 392 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 392 2611 17824768 83 Linux
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
第三步、开始分区
- 使用 fdisk /dev/sdb 进行分区
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x692e7205.
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):
#命令提示输入 m 获取帮助
- 输入 m 获取命令帮助
- 查看分区情况 p
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x692e7205
Device Boot Start End Blocks Id System
- 新建第一主分区 p
#新建主分区
Command (m for help): n
Command action
e extended #扩展分区
p primary partition (1-4) #主分区(1-4)
#创建主分区
p
#创建并指定第一主分区
Partition number (1-4): 1
#起始柱面从 1 开始
First cylinder (1-2610, default 1): 1
#结束柱面,不加单位代表柱面,加K,M,G表示SIZE
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G
#查看分区情况
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x692e7205
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
#已创建第一主分区
- 新建扩展分区 e
Command (m for help): n
Command action
e extended #扩展分区
p primary partition (1-4) #主分区(1-4)
#选择扩展分区
e
#第2主分区设置为扩展分区
Partition number (1-4): 2
#起始柱面263
First cylinder (263-2610, default 263): 263
#结束柱面,不选择用默认 2610
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610):
Using default value 2610
#查看当前分区情况
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x692e7205
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 2610 18860310 5 Extended
- 新建第一个逻辑分区 l
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
#选择逻辑分区 l
l
#起始柱面263
First cylinder (263-2610, default 263): 263
#结束柱面 525 ( 263 + 262 )
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +262
#查看逻辑分区
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x692e7205
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 2610 18860310 5 Extended
/dev/sdb5 263 525 2112516 83 Linux
Command (m for help):
- 保存退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第四步、格式化 mkfs
- 格式化 /dev/sdb1
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override
- 格式化 /dev/sdb5
[root@localhost ~]# mkfs -t ext4 /dev/sdb5
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
132192 inodes, 528129 blocks
26406 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7776 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
第五步、建立挂载点
- 根目录下 / 建立挂载空目录 /disk1 和 /disk5
[root@localhost /]# mkdir /disk1
[root@localhost /]# mkdir /disk5
第六步、挂载
[root@localhost /]# mount /dev/sdb1 /disk1
[root@localhost /]# mount /dev/sdb5 /disk5
第七步、查看挂载情况
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 17G 2.2G 14G 14% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 976M 33M 892M 4% /boot
/dev/sdb1 2.0G 3.1M 1.9G 1% /disk1
/dev/sdb5 2.0G 3.1M 1.9G 1% /disk5
三、小结
如文章内有错误,欢迎批评指正