m #菜单menu选项提示 n #创建新分区 p #主分区 (需要确认位置、分区起始位、分区结束位) t #变更分区类型 8e # 8e 对应 Linux LVM p #打印分区信息(已变更类型) w #保存退出
完整步骤(详细):
[root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xaf2c1952.
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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xaf2c1952
Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 83 Linux
Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xaf2c1952
Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]#
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xaf2c1952
Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM
创建分区
[root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (41943040-83886079, default 41943040): Using default value 41943040 Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): Using default value 83886079 Partition 2 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xaf2c1952
Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM /dev/sdb2 41943040 83886079 20971520 83 Linux
Command (m for help): w 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 or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost ~]#
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 49.99 GiB PE Size 4.00 MiB Total PE 12798 Alloc PE / Size 12798 / 49.99 GiB Free PE / Size 0 / 0 VG UUID 8yvHrE-6M4Y-6qNb-dunc-2gD5-vRnR-kKRfTZ ...
将物理券扩展到卷组
[root@localhost ~]# vgextend vg1 /dev/sdb2 Volume group "vg1" successfully extended
扩展逻辑卷
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/vg1-lv1 Size of logical volume vg1/lv1 changed from 49.99 GiB (12798 extents) to <69.99 GiB (17917 extents). Logical volume vg1/lv1 successfully resized.
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <20.00 GiB PE Size 4.00 MiB Total PE 5119 Alloc PE / Size 5119 / <20.00 GiB Free PE / Size 0 / 0 VG UUID 8yvHrE-6M4Y-6qNb-dunc-2gD5-vRnR-kKRfTZ [root@localhost ~]#
[root@localhost ~]# vgdisplay vg1 --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 49.99 GiB PE Size 4.00 MiB Total PE 12798 Alloc PE / Size 5119 / <20.00 GiB Free PE / Size 7679 / <30.00 GiB VG UUID 8yvHrE-6M4Y-6qNb-dunc-2gD5-vRnR-kKRfTZ [root@localhost ~]#