Command (m forhelp): n ## 新建 Command action e extended p primary partition (1-4) p ## 主分区
Partition number (1-4): 1 ## 分区号 First cylinder (1-1044, default 1): ## 回车用默认的 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +1G ## 大小
Command (m forhelp): t ## 改变类型 Selected partition 1 Hex code (type L to list codes): 8e ## LVM 的分区代码 Changed system type of partition 1 to 8e (Linux LVM)
重复上面的操作来创建其他两个分区。分区创建完成后,我们应该有类似如下的输出:
1
# fdisk -l
1 2 3 4
Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 8e Linux LVM /dev/sdb2 133 264 1060290 8e Linux LVM /dev/sdb3 265 396 1060290 8e Linux LVM
--- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 1.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID jszvzz-ENA2-g5Pd-irhV-T9wi-ZfA3-0xo092
--- Volume group --- VG Name volume-group1 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 3.02 GiB PE Size 4.00 MiB Total PE 774 Alloc PE / Size 0 / 0 Free PE / Size 774 / 3.02 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
--- Logical volume --- LV Name /dev/volume-group1/lv1 VG Name volume-group1 LV UUID YNQ1aa-QVt1-hEj6-ArJX-I1Q4-y1h1-OFEtlW LV Write Access read/write LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
现在逻辑卷已经准备好了,我们可以格式化和挂载逻辑卷,就像其它 ext3/4 分区一样!
1 2 3
# mkfs.ext4 /dev/volume-group1/lv1 # mkdir /lvm-mount # mount /dev/volume-group1/lv1 /lvm-mount/
--- Logical volume --- LV Name /dev/volume-group1/lv1 VG Name volume-group1 LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa LV Write Access read/write LV Status available # open 0 LV Size 200.00 MiB Current LE 50 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
# lvresize -L 100M /dev/volume-group1/lv1 WARNING: Reducing active logical volume to 100.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv1? [y/n]: y Reducing logical volume lv1 to 100.00 MiB Logical volume lv1 successfully resized
最后,验证调整后的逻辑卷大小。
1
# lvdisplay
1 2 3 4 5 6 7 8 9 10 11 12 13 14
--- Logical volume --- LV Name /dev/volume-group1/lv1 VG Name volume-group1 LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa LV Write Access read/write LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
--- Volume group --- VG Name volume-group1 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 3.02 GiB PE Size 4.00 MiB Total PE 774 Alloc PE / Size 25 / 100.00 MiB Free PE / Size 749 / 2.93 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
首先,我们创建一个 2GB 分区 sdc1,类型为 LVM(8e),如教程前所述。
1
# fdisk /dev/sdc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1044, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +2G
Command (m forhelp): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM)
Command (m forhelp): w The partition table has been altered!
--- Volume group --- VG Name volume-group1 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 9 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size 5.03 GiB PE Size 4.00 MiB Total PE 1287 Alloc PE / Size 25 / 100.00 MiB Free PE / Size 1262 / 4.93 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK