This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If your disks melt and your company fires you - its never our fault. Sorry. Make frequent backups and do your experiments on non-mission critical systems.
Furthermore, Richard Allen does not speak for his employer.
Linux is a registered trademark of Linus Torvalds.
+-----[ Physical Volume ]------+ | PE | PE | PE | PE | PE | PE | +------------------------------+
一个卷组,包含了2个物理卷(PV)有6个物理分区:
+------[ Volume Group ]-----------------+ | +--[PV]--------+ +--[PV]---------+ | | | PE | PE | PE | | PE | PE | PE | | | +--------------+ +---------------+ | +---------------------------------------+
Disk /dev/hda: 255 heads, 63 sectors, 623 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/hda1 1 2 16033+ 83 Linux /dev/hda2 3 600 4803435 83 Linux /dev/hda3 601 607 56227+ 83 Linux /dev/hda4 608 614 56227+ 83 Linux
Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e
Command (m for help): p
Disk /dev/hda: 255 heads, 63 sectors, 623 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/hda1 1 2 16033+ 83 Linux /dev/hda2 3 600 4803435 83 Linux /dev/hda3 601 607 56227+ 8e Unknown /dev/hda4 608 614 56227+ 83 Linux
# pvcreate /dev/hda3 pvcreate -- physical volume "/dev/hda3" successfully created # pvcreate /dev/hdb2 pvcreate -- physical volume "/dev/hdb2" successfully created
我们再将这两个物理卷(PV)加到一个叫做“test”的卷组(VG)中:
# vgcreate test /dev/hdb2 /dev/hda3 vgcreate -- INFO: using default physical extent size 4 MB vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte vgcreate -- doing automatic backup of volume group "test" vgcreate -- volume group "test" successfully created and activated
现在我们有一个空的卷组(VG),让我们来检查一下:
# vgdisplay -v test --- Volume group --- VG Name test VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 0 Open LV 0 MAX LV Size 255.99 GB Max PV 256 Cur PV 2 Act PV 2 VG Size 184 MB PE Size 4 MB Total PE 46 Alloc PE / Size 0 / 0 Free PE / Size 46 / 184 MB
--- No logical volumes defined in test ---
--- Physical volumes --- PV Name (#) /dev/hda3 (2) PV Status available / allocatable Total PE / Free PE 13 / 13
PV Name (#) /dev/hdb2 (1) PV Status available / allocatable Total PE / Free PE 33 / 33
# lvcreate -L 50M -n HOWTO test lvcreate -- rounding up size to physical extent boundary "52 MB" lvcreate -- doing automatic backup of "test" lvcreate -- logical volume "/dev/test/HOWTO" successfully created
Ok,到这里,我们创建一个文件系统:
# mke2fs /dev/test/HOWTO mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09 Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 13328 inodes, 53248 blocks 2662 blocks (5.00%) reserved for the super user First data block=1 7 block groups 8192 blocks per group, 8192 fragments per group 1904 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961
Writing inode tables: done Writing superblocks and filesystem accounting information: done # mount /dev/test/HOWTO /mnt # ls /mnt lost+found
我们做完了!让我们回顾我们的卷组(VG),它现在充满了一些东西:
# vgdisplay test -v --- Volume group --- VG Name test VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 1 Open LV 1 MAX LV Size 255.99 GB Max PV 256 Cur PV 2 Act PV 2 VG Size 184 MB PE Size 4 MB Total PE 46 Alloc PE / Size 13 / 52 MB Free PE / Size 33 / 132 MB
--- Logical volume --- LV Name /dev/test/HOWTO VG Name test LV Write Access read/write LV Status available LV # 1 # open 1 LV Size 52 MB Current LE 13 Allocated LE 13 Allocation next free Read ahead sectors 120 Block device 58:0
--- Physical volumes --- PV Name (#) /dev/hda3 (2) PV Status available / allocatable Total PE / Free PE 13 / 13
PV Name (#) /dev/hdb2 (1) PV Status available / allocatable Total PE / Free PE 33 / 20
# pvmove /dev/hda1 pvmove -- moving physical extents in active volume group "test1" pvmove -- WARNING: moving of active logical volumes may cause data loss! pvmove -- do you want to continue? [y/n] y pvmove -- doing automatic backup of volume group "test1" pvmove -- 12 extents of physical volume "/dev/hda1" successfully moved
# mount /dev/test/HOWTO /mnt # echo >; /mnt/a.test.file # ls /mnt/ a.test.file lost+found # ls -l /mnt/ total 13 -rw-r--r-- 1 root root 1 Apr 2 00:28 a.test.file drwxr-xr-x 2 root root 12288 Apr 2 00:28 lost+found
Ok,我们现在有些事情要用它一起做。让我们产生这个快照:
# lvcreate --size 16m --snapshot --name snap /dev/test/HOWTO lvcreate -- WARNING: all snapshots will be disabled if more than 16 MB are changed lvcreate -- INFO: using default snapshot chunk size of 64 KB lvcreate -- doing automatic backup of "test" lvcreate -- logical volume "/dev/test/HOWTO" successfully created
对于“--size”参数以后再详述。让我们mount这个快照:
# mount /dev/test/snap /snap # ls /snap total 13 -rw-r--r-- 1 root root 1 Apr 2 00:28 a.test.file drwxr-xr-x 2 root root 12288 Apr 2 00:28 lost+found