多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
Fdisk功能介绍: fdisk是linux系统下常用的磁盘分区工具,受mbr分区表的限制,fdisk工具只能给小于2TB的磁盘划分分区,若磁盘空间大于2TB,就需要使用parted分区工具 语法格式: fdisk [option] [device] 常用选项: -l 显示所有磁盘分区信息 范例: 1)显示磁盘分区列表(-l 参数) [root@fenfa ~]# fdisk -l (查看当前系统所有磁盘的分区信息) Disk /dev/vda: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 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: 0x0003bb0f Device Boot Start End Blocks Id System /dev/vda1 * 3 1018 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 1018 41611 20458496 8e Linux LVM Partition 2 does not end on cylinder boundary. 范例2: 添加一款硬盘,使用fdisk磁盘分区 Disk /dev/vdb: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 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命令不加任何参数,表示,直接进行分区操作,具体如下 [root@fenfa ~]# 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 0x438dbabe. 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 -》查看帮助 Command action a toggle a bootable flag 设置引导扇区 b edit bsd disklabel 编辑bsd卷标 c toggle the dos compatibility flag 设置dos兼容扇区 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 创建一个新的空DOS分区表 p print the partition table 打印分区表 q quit without saving changes 退出不保存 s create a new empty Sun disklabel 创建新的空sun卷标 t change a partition's system id 更改分区表的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 e extended----扩展分区 p primary partition (1-4)----主分区(1-4) p 创建一个主分区,需要人工输入p后回车 Partition number (1-4): 1---设置分区编号1,需要人工输入 First cylinder (1-41610, default 1): 设置开始柱面,默认为1 Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610): +2G 设置结束柱面,例如这个划分2G的空间 Command (m for help): p 打印分过的分区表 Disk /dev/vdb: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 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: 0x438dbabe Device Boot Start End Blocks Id System /dev/vdb1 1 4162 2097616+ 83 Linux 如果要需要创建分区,我们具体输入n,然后编号设置为2 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (4163-41610, default 4163): Using default value 4163 Last cylinder, +cylinders or +size{K,M,G} (4163-41610, default 41610): +2G Command (m for help): p Disk /dev/vdb: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 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: 0x438dbabe Device Boot Start End Blocks Id System /dev/vdb1 1 4162 2097616+ 83 Linux /dev/vdb2 4163 8324 2097648 83 Linux 创建逻辑分区: Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 3 First cylinder (8325-41610, default 8325): Using default value 8325 Last cylinder, +cylinders or +size{K,M,G} (8325-41610, default 41610): Using default value 41610 Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (8325-41610, default 8325): Using default value 8325 Last cylinder, +cylinders or +size{K,M,G} (8325-41610, default 41610): +2G Command (m for help): p Disk /dev/vdb: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 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: 0x438dbabe Device Boot Start End Blocks Id System /dev/vdb1 1 4162 2097616+ 83 Linux /dev/vdb2 4163 8324 2097648 83 Linux /dev/vdb3 8325 41610 16776144 5 Extended /dev/vdb5 8325 12486 2097616+ 83 Linux Command (m for help): w 保存退出 The partition table has been altered! [root@fenfa ~]# partx /dev/vdb # 1: 63- 4195295 ( 4195233 sectors, 2147 MB) # 2: 4195296- 8390591 ( 4195296 sectors, 2147 MB) # 3: 8390592- 41942879 ( 33552288 sectors, 17178 MB) # 4: 0- -1 ( 0 sectors, 0 MB) # 5: 8390655- 12585887 ( 4195233 sectors, 2147 MB) 格式化分区 [root@fenfa ~]# mkfs.ext4 /dev/vdb1 避免磁盘挂载自动检测磁盘 [root@fenfa ~]# tune2fs -c -1 /dev/vdb1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1 挂载: 临时:mount /dev/vdb1 /test 持久: 编写/etc/fstab配置文件 /dev/vdb1 /test ext4 defaults 0 0 范例3: 自动划分逻辑分区 [root@fenfa test]# fdisk /dev/vdb <<EOF > n > l > > +1G > p > w > EOF (如果不需要输入的,就直接回车)