fdisk命令详解

fdisk命令的常用格式是:


(1)# fdisk <硬盘设备名>
进入fdisk的交互操作方式,对指定的硬盘进行分区操作。


(2)# fdisk –l <硬盘设备名>
在命令行方式下显示指定硬盘的分区表信息。


在fdisk的交互操作方式下可以使用若干子命令说明

a   调整硬盘的启动分区
d   删除一个硬盘分区
l    列出所有支持的分区类型
m  列出所有命令
n   创建一个新的分区
p   列出硬盘分区表
q   退出fdisk,不保存更改
t    更改分区类型
u   切换所显示的分区大小的单位
w  把设置写入硬盘分区表,然后退出

—————————————————————————————
fdisk 命令使用举例


# fdisk /dev/sdb # 对系统中第二块SCSI接口的硬盘进行分区
Command (m for help): n # 创建新的分区
Command action
e extended
p primary partition (1-4)
p # 键入p 创建主分区
Partition number (1-4): 1 # 输入分区编号1
First cylinder (1-522, default 1): # 直接回车,从硬盘起始柱面创建分区
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522):
# 直接回车,分区大小截至到最后一个柱面
Using default value 522
Command (m for help): p # 显示当前分区表
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 522 4192933+ 83 Linux


Command (m for help): d # 删除已经存在的分区
Selected partition 1
# 由于当前只有一个分区,所以没有被删除分区的编号提示选择,直接将此分区删除
# 若当前存在多个分区,将出现分区的编号提示选择
Command (m for help): p # 显示当前分区表,分区已经被删除
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n # 创建大小为500M的1号主分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +500M
Command (m for help): n # 对所有磁盘剩余空间创建编号为2的扩展分区
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (63-522, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-522, default 522):
Using default value 522
Command (m for help): n # 创建大小为400M的逻辑分区
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (63-522, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-522, default 522): +400M
Command (m for help): n # 创建大小为256M的逻辑分区
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (113-522, default 113):
Using default value 113
Last cylinder or +size or +sizeM or +sizeK (113-522, default 522): +256M
Command (m for help): p # 显示当前分区表
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 62 497983+ 83 Linux
/dev/sdb2 63 522 3694950 5 Extended
/dev/sdb5 63 112 401593+ 83 Linux
/dev/sdb6 113 144 257008+ 83 Linux
Command (m for help): t # 将5号分区更改为FAT32类型
Partition number (1-6): 5
Hex code (type L to list codes): C
Changed system type of partition 5 to c (Win95 FAT32 (LBA))
Command (m for help): t # 将6号分区更改为swap类型
Partition number (1-6): 6
Hex code (type L to list codes): 82
Changed system type of partition 6 to 82 (Linux swap)
Command (m for help): p # 显示当前分区表,类型已经更改
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 62 497983+ 83 Linux
/dev/sdb2 63 522 3694950 5 Extended
/dev/sdb5 63 112 401593+ c Win95 FAT32 (LBA)
/dev/sdb6 113 144 257008+ 82 Linux swap
Command (m for help): w # 将当前的分区设置保存,并退出fdisk
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
# fdisk -l /dev/sdb # 在非交互状态下显示当前的分区表信息
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 62 497983+ 83 Linux
/dev/sdb2 63 522 3694950 5 Extended
/dev/sdb5 63 112 401593+ c Win95 FAT32 (LBA)
/dev/sdb6 113 144 257008+ 82 Linux swap

猜你喜欢

转载自sky425509.iteye.com/blog/1996101