实验:使用fdisk创建简单磁盘分区
实验要求:
/dev/sdb8 100M
/dev/sdb9 100M
[root@shaoping ~]# fdisk -l /dev/sdb #查看当前磁盘分区情况
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: 0xe7a49488
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 2610 20442712+ 5 Extended
/dev/sdb5 66 79 112423+ 8e Linux LVM
/dev/sdb6 80 93 112423+ fd Linux raid autodetect
/dev/sdb7 94 107 112423+ fd Linux raid autodetect
[root@shaoping ~]# fdisk /dev/sdb
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 #显示所有可选项
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l #这里选择l 表示要创建一个额外的逻辑分区
First cylinder (108-2610, default 108):
Using default value 108
Last cylinder, +cylinders or +size{K,M,G} (108-2610, default 2610): +100M #这里指定新分区的大小是100M
Command (m for help): w #指定大小后,选w回车保存分区操作后退出
The partition table has been altered!
[root@shaoping ~]# partprobe #使用此命令更新分区表,如果出错,需要重启来成功更新分区表
[root@shaoping ~]# fdisk -l /dev/sdb #再次查看硬盘分区情况就可以看到新分区/dev/sdb8,但是此时还不可以使用,因为还没有指定文件系统格式,和挂载
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: 0xe7a49488
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 2610 20442712+ 5 Extended
/dev/sdb5 66 79 112423+ 8e Linux LVM
/dev/sdb6 80 93 112423+ fd Linux raid autodetect
/dev/sdb7 94 107 112423+ fd Linux raid autodetect
/dev/sdb8 108 121 112423+ 83 Linux
重复以上步骤,再新建另一个分区/dev/sdb9
[root@shaoping ~]# fdisk -l /dev/sdb
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: 0xe7a49488
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 2610 20442712+ 5 Extended
/dev/sdb5 66 79 112423+ 8e Linux LVM
/dev/sdb6 80 93 112423+ fd Linux raid autodetect
/dev/sdb7 94 107 112423+ fd Linux raid autodetect
/dev/sdb8 108 121 112423+ 83 Linux
/dev/sdb9 122 135 112423+ 83 Linux
此时,/dev/sdb8 /dev/sdb9还无法使用,因为还没有指定文件系统类型,和挂载
[root@shaoping ~]# mount /dev/sdb8 /mnt #因为还没有指定文件系统格式, 所以挂载会失败,无法识别文件类型
mount: you must specify the filesystem type
为了使该分区可以使用,下面对其进行格式化
[root@shaoping ~]# mkfs -t ext4 /dev/sdb8 #用ext4格式格式化分区
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
28112 inodes, 112420 blocks
5621 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
14 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@shaoping ~]# mount /dev/sdb8 /mnt #mount 到/mnt目录下以供使用
如要使该分区可以在系统启动时自动挂载,可以修改/etc/fstab文件来实现