fdisk
基本说明:
fdisk 分区命令适合2T一下的分区设置
fdisk -l 跟设备名列出当前分区信息,不跟信息列出所有系统能找到的分区。
命令格式:fdisk /dev/sdx
对sdb磁盘进行分区管理
[root@bear ~]# fdisk /dev/sdb
Device contains neither a validDOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabelwith disk identifier 0x3dc1c21e.
Changes will remain in memoryonly, until you decide to write them.
After that, of course, theprevious content won't be recoverable.
Warning: invalid flag 0x0000 ofpartition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode isdeprecated. It's strongly recommended to
switch off the mode (command 'c') andchange display units to
sectors (command 'u').
Command (m for help): m m调出帮助菜单
Command action
atoggle a bootable flag
bedit bsd disklabel
ctoggle the dos compatibility flag
ddelete a partition 删除一个分区
llist known partition types 列出已知的分区类型
mprint this menu 打印帮助菜单
nadd a new partition 添加一个新的分区
ocreate a new empty DOS partition table
pprint the partition table 打印分区表信息
qquit without saving changes
screate a new empty Sun disklabel
tchange a partition's system id 更改分区类型
uchange display/entry units
vverify the partition table
wwrite table to disk and exit 保存分区表信息并退出
xextra functionality (experts only)
实际案列:
1. 创建一个柱面号从1到50的主分区
Command (m for help): n n创建新分区
Command action
eextended e 扩展分区
pprimary partition (1-4) p 主分区
p
Partition number (1-4): 1 主分区的编号(1-4)
First cylinder (1-261, default1): 起始柱面号
Using default value 1 默认使用1
Last cylinder, +cylinders or+size{K,M,G} (1-261, default 261): 50 结束柱面号
Command (m for help): p 查询分区结果
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0x3dc1c21e
Device BootStartEndBlocksIdSystem
/dev/sdb1150401593+83Linux 分区结果
2. 创建3个主分区一个逻辑分区,主分区大小分别为100M,200M,300M,逻辑分区为剩余所有容量。
[root@bear ~]#fdisk /dev/sdb 对/sdb进行分区操作
Device contains neither a validDOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabelwith disk identifier 0xe9eba6de.
Changes will remain in memoryonly, until you decide to write them.
After that, of course, theprevious content won't be recoverable.
Warning: invalid flag 0x0000 ofpartition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode isdeprecated. It's strongly recommended to
switch off the mode (command 'c') andchange display units to
sectors (command 'u').
Command (m for help): n
Command action 创建一个新的分区
eextended
pprimary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default1):
Using default value 1
Last cylinder,+cylinders or +size{K,M,G} (1-261, default 261): +100
分区大小可以在这里直接设置设置多少就+多少,单位M,G,T
Command (m for help): p
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
Command (m for help): n
Command action
eextended
pprimary partition (1-4)
p
Partition number (1-4): 2
First cylinder (15-261, default15):
Using default value 15
Last cylinder, +cylinders or+size{K,M,G} (15-261, default 261): +200M
Command (m for help): p
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
/dev/sdb2154020884583Linux
Command (m for help): n
Command action
eextended
pprimary partition (1-4)
p
Partition number (1-4): 3
First cylinder (41-261, default41):
Using default value 41
Last cylinder, +cylinders or+size{K,M,G} (41-261, default 261): +300M
Command (m for help): n
Command action
eextended
pprimary partition (1-4)
e
Selected partition 4
First cylinder (80-261, default80):
Using default value 80
Last cylinder, +cylinders or+size{K,M,G} (80-261, default 261):
Using default value 261
Command (m for help): p
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
/dev/sdb2154020884583Linux
/dev/sdb34179313267+83Linux
/dev/sdb48026114619155Extended
3. 将主分区2的分区类型换位lvm格式
Command (m for help): t
Partition number (1-5): 2
Hex code (type L to listcodes): 8e
Changed system type ofpartition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
/dev/sdb215402088458eLinux LVM修改成了lvm格式
/dev/sdb34179313267+83Linux
/dev/sdb48026114619155Extended
4.删除扩展分区
Command (m for help): p 查看当前分区信息
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
/dev/sdb215402088458eLinux LVM
/dev/sdb34179313267+83Linux
/dev/sdb48026114619155Extended 扩展分区编号为4
Command (m forhelp): d 删除一个分区
Partition number(1-5): 4 选择编号,4为扩展分区
Command (m forhelp): p 查看分区信息
Disk /dev/sdb: 2147 MB,2147483648 bytes
255 heads, 63 sectors/track,261 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0xe9eba6de
Device BootStartEndBlocksIdSystem
/dev/sdb1114112423+83Linux
/dev/sdb215402088458eLinux LVM
/dev/sdb34179313267+83Linux 扩展分区已被删除