|
fdisk
fdisk [选项] 改变分区表
fdisk [选项] –l 列出所有分区表
fdisk –s 以分区块为单位,给出指定分区的大小
这是一个创建和维护分区的命令,兼容DOS类型的分区表、BSD或SUN类型的磁盘列表。
相关了解:
磁头数(Heads)表示硬盘有几个磁头,也就是有几面盘片,一个硬盘最多有255个磁头
柱面数(Cylinders)表示硬盘每面盘片上有几条磁道
扇区数(Sectors)表示每条磁道上有几个扇区,每条磁道最多有63个扇区
(1).选项
-b 指定扇区大小(512,1024,2048或4096 B)
-c 关闭DOS兼容模式
-u 以扇区编号取代柱面编号来表示每个分区的起始地址,一般与-l选项联合使用
-C 指定柱面编号
-H 指定磁头编号
-S 指定磁道扇区编号
(2).菜单操作说明:
a 设置可引导标记(活动分区/引导分区之间切换)
b 编辑BSD磁盘标签
c 设置DOS操作系统兼容标记(兼容/不兼容之间切换)
d 删除一个分区
l 显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
m 显示帮助信息
n 增加一个新的分区
o 创建一个新的空白的DOS分区表
p 显示磁盘当前的分区表
q 退出fdisk程序,不保存任何修改
s 创建一个新的空白的Sun磁盘标签
t 改变一个分区的系统ID,就是改变分区类型(比如把Linux Swap分区改为Linux分区)
u 改变显示或输入单位
v 验证磁盘分区表
w 将分区表写入磁盘并退出(保存并退出)
x 额外功能(专家级)
(3).实例
sda和hda的区别
sd代表的是SCSI,SATA接口硬盘
hd代表IDE接口的硬盘
sda和hda最后面的a都代表的是第一块硬盘
sda1和hda1则代表的是该硬盘的第一分区
fdisk -l
/盘/dev/sda:107.4G,107374182400字节(B),255个磁头,63个扇区,13054柱面(磁道) 1单位=16065柱面(磁道)512=8225280字节(B) 扇区大小(逻辑/物理):512字节(B)/512字节(B)输入/输出大小(最小/最佳):512字节(B)/512字节(B)磁盘标识:0x00079700/Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 512 = 8225280 bytes
Sector>
I/O>
Disk> /设备 启动标识 开始位置 结束位置 分区块的大小 分区ID 系统(分区类型) /dev/sda1 1 64 512000 83 Linux 分区1不以柱面边界结束 /dev/sda2 64 13055 104344576 8e Linux LVM/
Device Boot Start End Blocks > /dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
255 heads, 63 sectors/track, 5952 cylinders
Units = cylinders of 16065 512 = 8225280 bytes
Sector>
I/O>
Disk> fdisk -lu
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 512 = 512 bytes
Sector>
I/O>
Disk>
Device Boot Start End Blocks > /dev/sda1 * 2048 1026047 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 1026048 209715199 104344576 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 cylinders, total 8192000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector>
I/O>
Disk> Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
255 heads, 63 sectors/track, 5952 cylinders, total 95633408 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector>
I/O>
Disk> 你们也看到了,我的/dev/sdb还没有开始使用,下面就用这个硬盘简单的演示下fdisk主要用到的操作菜单
创建一个新的分区
[root@CentOS6 桌面]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk> 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): n
Command action
e extended //扩展分区,创建扩展分区会占用一个主分区,并且只有创建扩展分区后才能创建逻辑分区
p primary partition (1-4) //主分区,最多创建4个
e
Partition number (1-4): 1
First cylinder (1-2610, default 1): //起始柱面,默认为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): //终止柱面,默认为最后一个数
Using default value 2610
Command (m for help): n
Command action
l logical (5 or over) //逻辑分区
p primary partition (1-4) //主分区
l
First cylinder (1-2610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G //终止柱面不仅可以用柱面数表示,还可以用+[数值][单位]的格式表示
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1307-2610, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-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>
I/O>
Disk>
Device Boot Start End Blocks > /dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux
/dev/sdb6 1307 2610 10474348+ 83 Linux
Command (m for help): w //写入磁盘,保存并退出,否则之前的操作都无效。如果不想写入磁盘就使用qThe partition table has been> 同样在/dev/sdb下操作, 删除一个分区
[root@CentOS6 桌面]# 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): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector>
I/O>
Disk>
Device Boot Start End Blocks > /dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux
/dev/sdb6 1307 2610 10474348+ 83 Linux
Command (m for help): d
Partition number (1-6): 6 //这里输入的始分区编号,如果删除扩展分区,那扩展分区下的逻辑分区也会被删除
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>
I/O>
Disk>
Device Boot Start End Blocks > /dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux
Command (m for help): w
The partition table has been> Calling ioctl() to re-read partition table.
Syncing disks.
最后展示下修改分区类型
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): t
Partition number (1-5): 5 //操作哪一个分区
Hex code (type L to list codes): L //这里会提示你使用L查看类型列表
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FA×××2 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FA×××6 |
|