[root@test:/home/robot/test] # dd if=/dev/zero of=/home/robot/test/lvm1 bs=1M count=512 512+0 records in 512+0 records out 536870912 bytes (537 MB, 512 MiB) copied, 0.474638 s, 1.1 GB/s [root@test:/home/robot/test] # dd if=/dev/zero of=/home/robot/test/lvm2 bs=1M count=512 512+0 records in 512+0 records out 536870912 bytes (537 MB, 512 MiB) copied, 0.49283 s, 1.1 GB/s [root@test:/home/robot/test] # dd if=/dev/zero of=/home/robot/test/lvm3 bs=1M count=512 512+0 records in 512+0 records out 536870912 bytes (537 MB, 512 MiB) copied, 0.48691 s, 1.1 GB/s [root@test:/home/robot/test] # [root@test:/home/robot/test] # losetup /dev/loop1 /home/robot/test/lvm1 [root@test:/home/robot/test] # losetup /dev/loop2 /home/robot/test/lvm2 [root@test:/home/robot/test] # losetup /dev/loop3 /home/robot/test/lvm3 [root@test:/home/robot/test] # ll total 1572876 -rw-r--r-- 1 root root 536870912 Mar 16 12:28 lvm1 -rw-r--r-- 1 root root 536870912 Mar 16 12:28 lvm2 -rw-r--r-- 1 root root 536870912 Mar 16 12:28 lvm3
[root@test:/home/robot/test] # pvdisplay [root@test:/home/robot/test] # pvcreate /dev/loop1 Physical volume "/dev/loop1" successfully created. [root@test:/home/robot/test] # pvcreate /dev/loop2 Physical volume "/dev/loop2" successfully created. [root@test:/home/robot/test] # pvcreate /dev/loop3 Physical volume "/dev/loop3" successfully created. [root@test:/home/robot/test] # pvdisplay "/dev/loop3" is a new physical volume of "512.00 MiB" --- NEW Physical volume --- PV Name /dev/loop3 VG Name PV Size 512.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID PpWfyJ-1lSY-iNZY-MU0K-wQfz-zrh0-n9YnCF "/dev/loop1" is a new physical volume of "512.00 MiB" --- NEW Physical volume --- PV Name /dev/loop1 VG Name PV Size 512.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 9cUDS8-9VGN-cvnS-8tCF-prIy-eRYS-Y83es9 "/dev/loop2" is a new physical volume of "512.00 MiB" --- NEW Physical volume --- PV Name /dev/loop2 VG Name PV Size 512.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID fi632i-W46C-dvfw-9YCt-Z08g-rUZB-Hmakox
[root@test:/home/robot/test] # vgdisplay [root@test:/home/robot/test] # vgcreate -s 4M lianhuasheng /dev/loop{1,2,3} Volume group "lianhuasheng" successfully created [root@test:/home/robot/test] # vgdisplay --- Volume group --- VG Name lianhuasheng 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 <1.49 GiB PE Size 4.00 MiB Total PE 381 Alloc PE / Size 0 / 0 Free PE / Size 381 / <1.49 GiB VG UUID Y4l3Ad-bdIJ-7V5A-3FI1-kR74-QwDg-DbRdJ0
[root@test:/home/robot/test] # lvcreate -l 50 -n lv1 lianhuasheng Logical volume "lv1" created. [root@test:/home/robot/test] # lvdisplay --- Logical volume --- LV Path /dev/lianhuasheng/lv1 LV Name lv1 VG Name lianhuasheng LV UUID jQU1SV-tIzt-SRet-L5XK-rk1K-YC3h-o7YT7Q LV Write Access read/write LV Creation host, time test, 2020-03-16 22:27:14 +0800 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 252:8
[root@test:/home/robot/test] # mkfs -t ext4 /dev/lianhuasheng/lv1 mke2fs 1.45.5 (07-Jan-2020) Discarding device blocks: done Creating filesystem with 204800 1k blocks and 51200 inodes Filesystem UUID: 39a25411-b81c-42c0-b1d4-cb7dd1119e87 Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done [root@test:/home/robot/test] # ls lvm1 lvm2 lvm3 [root@test:/home/robot/test] # mkdir mountPoint [root@test:/home/robot/test] # mount /dev/lianhuasheng/lv1 /home/robot/test/mountPoint/ [root@test:/home/robot/test] # df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40G 8.9G 29G 24% / /dev/mapper/lianhuasheng-lv1 ext4 190M 1.6M 175M 1% /home/robot/test/mountPoint
[root@test:/home/robot/test/mountPoint] # lvdisplay --- Logical volume --- LV Path /dev/lianhuasheng/lv1 LV Name lv1 VG Name lianhuasheng LV UUID jQU1SV-tIzt-SRet-L5XK-rk1K-YC3h-o7YT7Q LV Write Access read/write LV Creation host, time test, 2020-03-16 22:27:14 +0800 LV Status available # open 1 LV Size 200.00 MiB Current LE 50 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:8 [root@test:/home/robot/test/mountPoint] # df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40G 8.9G 29G 24% / /dev/mapper/lianhuasheng-lv1 ext4 190M 1.6M 175M 1% /home/robot/test/mountPoint [root@test:/home/robot/test/mountPoint] # touch test.log [root@test:/home/robot/test/mountPoint] # ll -hi total 12K 11 drwx------ 2 root root 12K Mar 16 22:31 lost+found 12 -rw-r--r-- 1 root root 0 Mar 16 22:43 test.log [root@test:/home/robot/test/mountPoint] # lvresize -l +50 /dev/lianhuasheng/lv1 [root@test:/home/robot/test/mountPoint] # lvdisplay --- Logical volume --- LV Path /dev/lianhuasheng/lv1 LV Name lv1 VG Name lianhuasheng LV UUID jQU1SV-tIzt-SRet-L5XK-rk1K-YC3h-o7YT7Q LV Write Access read/write LV Creation host, time test, 2020-03-16 22:27:14 +0800 LV Status available # open 1 LV Size 400.00 MiB Current LE 100 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:8 [root@test:/home/robot/test/mountPoint] # df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40G 8.9G 29G 24% / /dev/mapper/lianhuasheng-lv1 ext4 190M 1.6M 175M 1% /home/robot/test/mountPoint
[root@test:/home/robot/test/mountPoint] # resize2fs /dev/mapper/lianhuasheng-lv1 resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/mapper/lianhuasheng-lv1 is mounted on /home/robot/test/mountPoint; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/mapper/lianhuasheng-lv1 is now 409600 (1k) blocks long. [root@test:/home/robot/test/mountPoint] # df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40G 8.9G 29G 24% / /dev/mapper/lianhuasheng-lv1 ext4 384M 2.3M 360M 1% /home/robot/test/mountPoint [root@test:/home/robot/test/mountPoint] # ll -hi total 12K 11 drwx------ 2 root root 12K Mar 16 22:31 lost+found 12 -rw-r--r-- 1 root root 0 Mar 16 22:43 test.log
[root@test:/home/robot/test/mountPoint] # df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40G 8.9G 29G 24% / /dev/mapper/lianhuasheng-lv1 ext4 384M 2.3M 360M 1% /home/robot/test/mountPoint [root@test:/home/robot/test/mountPoint] # cd .. [root@test:/home/robot/test] # umount /home/robot/test/mountPoint/ [root@test:/home/robot/test] # lvremove /dev/lianhuasheng/lv1 Do you really want to remove active logical volume lianhuasheng/lv1? [y/n]: y Logical volume "lv1" successfully removed [root@test:/home/robot/test] # vgremove lianhuasheng Volume group "lianhuasheng" successfully removed [root@test:/home/robot/test] # pvremove /dev/loop{1,2,3} Labels on physical volume "/dev/loop1" successfully wiped. Labels on physical volume "/dev/loop2" successfully wiped. Labels on physical volume "/dev/loop3" successfully wiped. [root@test:/home/robot/test] # ll -hi total 1.4G 656227 -rw-r--r-- 1 root root 512M Mar 16 22:58 lvm1 656229 -rw-r--r-- 1 root root 512M Mar 16 22:58 lvm2 656230 -rw-r--r-- 1 root root 512M Mar 16 22:58 lvm3 [root@test:/home/robot/test] # rm -rf lvm{1,2,3} [root@test:/home/robot/test] # ll -hi
pvcreate 建立實體 partition 爲 PV
pvscan 搜尋系統磁盤是否有 PV
pvdisplay 顯示 PV 狀態
pvremove 移除 PV 移除,partition 不具備 PV 屬性
vgcreate 建立 VG
vgscan 搜尋系統是否有 VG
vgdisplay 顯示 VG 狀態
vgextend 在 VG 內添加額外的 PV
vgreduce 在 VG 內移除 PV
vgchange 配置 VG 是否啓動 (active)
vgremove 移除 VG
lvcreate 建立 LV
lvscan 查詢系統是否有 LV
lvdisplay 顯示 LV 狀態
lvextend 擴展 LV 容量
lvreduce 縮小 LV 容量
lvremove 刪除 LV
lvresize 調整 LV 容量大小