//Slightly edited (trimmed), commented/annotated (I show my comments as //lines beginning with two slashes (//)), and interleaved (super-user //(root) and non-superuser (non-root)) script(1) outputs merged in //their respective chronological ordering. The superuser prompt here is //"# ", and the prompt for our mere mortal user is "$ ". //The interleaving chronology may not precisely match the original //demonstration (I don't have data handy to clearly disambiguate among //some various alternative logical possibilities). //First I show some partition data information. //For demonstration purposes, we can "pretend" that these partitions //are individual distinct disks - or LUNs, or meta devices, or loop //devices - the demonstration and behavior would work the same in such //cases, ... just happens for demonstration purposes from a laptop, //I only had the one internal hard drive set up to work with. //I don't show all the partitions here (some of them uninteresting and //irrelevant for this demonstration), but I do show all the LVM partitions. # sfdisk -uS -l /dev/hda | grep -v 'hda[1-6] ' Disk /dev/hda: 4764 cylinders, 240 heads, 63 sectors/track Units = sectors of 512 bytes, counting from 0 Device Boot Start End #sectors Id System /dev/hda7 41459040 43636318 2177279 8e Linux LVM /dev/hda8 43636320 45813598 2177279 8e Linux LVM /dev/hda9 45813600 47990878 2177279 8e Linux LVM /dev/hda10 47990880 50168158 2177279 8e Linux LVM /dev/hda11 50168160 52345438 2177279 8e Linux LVM /dev/hda12 52345440 54522718 2177279 8e Linux LVM /dev/hda13 54522720 56699998 2177279 8e Linux LVM /dev/hda14 56700000 58877278 2177279 8e Linux LVM /dev/hda15 58877280 61054558 2177279 8e Linux LVM /dev/hda16 61054560 63231838 2177279 8e Linux LVM /dev/hda17 63231840 65409118 2177279 8e Linux LVM /dev/hda18 65409120 67586398 2177279 8e Linux LVM /dev/hda19 67586400 69763678 2177279 8e Linux LVM /dev/hda20 69763680 71940958 2177279 8e Linux LVM //For the demonstration, we had /dev/hda18, /dev/hda19 and /dev/hda20 //to work with - all the others being in use in an existing Volume Group (VG). //We use pvcreate(8) to initialize our Physical Volumes (PVs) # pvcreate /dev/hda1[89] /dev/hda20 pvcreate -- physical volume "/dev/hda18" successfully created pvcreate -- physical volume "/dev/hda19" successfully created pvcreate -- physical volume "/dev/hda20" successfully created //We create a VG, naming it "VG1", using PV /dev/hda18. # vgcreate VG1 /dev/hda18 vgcreate -- INFO: using default physical extent size 32 MB vgcreate -- INFO: maximum logical volume size is 2 Terabyte vgcreate -- doing automatic backup of volume group "VG1" vgcreate -- volume group "VG1" successfully created and activated //We take a look at some information on our newly created VG VG1. //Note the Physical Extent (PE) size of 32 MiB. That's the default size we //got. When creating a VG, one may want to give careful consideration to the //PE size, and potentially other items which can be optionally configured, //as some of these can't be changed once the VG is created. Although LVM //is quite flexible, it does have some limits, and some things can be //difficult to change. Note the MAX LV and Max PV. There's also a limit on //maximum number of PEs per LV (see vgcreate(8)). //Our VG VG1 also happens to be precisely 1 GiB in size (VG Size). # vgdisplay -v VG1 | less --- Volume group --- VG Name VG1 VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 0 Open LV 0 MAX LV Size 2 TB Max PV 256 Cur PV 1 Act PV 1 VG Size 1 GB PE Size 32 MB Total PE 32 Alloc PE / Size 0 / 0 Free PE / Size 32 / 1 GB VG UUID NXIGYF-3g5t-wAEZ-xddi-sQWk-4LDt-TrRyfc --- No logical volumes defined in "VG1" --- //quit less(1) //Now we create a 128 MiB Logical Volume (LV) on our VG VG1 which we name "LV1". # lvcreate --size 128M --name LV1 VG1 lvcreate -- doing automatic backup of "VG1" lvcreate -- logical volume "/dev/VG1/LV1" successfully created //Now we create a filesystem on our LV LV1. # mkreiserfs /dev/VG1/LV1 //at least by default mkreiserfs(8) is rather chatty, //much of that output has been omitted Continue (y/n):y //We make our mount point. # (umask 022 && mkdir /var/tmp/1) //We mount our new filesystem on our new mount point. # mount -t reiserfs /dev/VG1/LV1 /var/tmp/1 //I did also show display from kdf(1) (GUI) (via xzoom(1x)) at various points //through the demonstration, but I didn't capture those kdf(1) displays. //It was my intent to also run df(1) at those times (at least when //demonstration filesystem(s) were mounted), but I may not have always //run and thus caught and matched those one-for-one. //I wouldn't typically set non-superuser (non-root) ownership of the root of //a filesystem, but for demonstration purposes, etc., we hand this ownership //to our mere mortal user. # chown michael /var/tmp/1 //Our mere mortal user takes a look at space on the filesystem. $ df -k /var/tmp/1 Filesystem 1k-blocks Used Available Use% Mounted on /dev/VG1/LV1 131064 32840 98224 26% /var/tmp/1 //reiserfs does have a fair amount of overhead for a relatively small //filesystem (we haven't put anything onto the filesystem yet). //Our mere mortal user changes directory into the filesystem, has a look about, //copies a file into the filesystem and touch(1)es it, and computes and //saves an md5sum(1) of the copied file. $ cd /var/tmp/1 $ pwd /var/tmp/1 $ ls -ld . drwxr-xr-x 3 michael root 48 May 17 20:50 . $ ls -alb total 5 drwxr-xr-x 3 michael root 48 May 17 20:50 . drwxrwxrwt 15 root root 440 May 17 20:54 .. $ cp /var/tmp/cdrom/cdrom/Linuxcare_bootable_toolbox_V2.0.raw Linuxcare_bootable_toolbox_V2.0.raw $ ls -alb total 48061 drwxr-xr-x 3 michael root 104 May 17 20:57 . drwxrwxrwt 15 root root 440 May 17 20:54 .. -rw------- 1 michael users 49211392 May 17 20:57 Linuxcare_bootable_toolbox_V2.0.raw $ touch -r /var/tmp/cdrom/cdrom/Linuxcare_bootable_toolbox_V2.0.raw Linuxcare_bootable_toolbox_V2.0.raw $ ls -alb total 48061 drwxr-xr-x 3 michael root 104 May 17 20:57 . drwxrwxrwt 15 root root 440 May 17 20:54 .. -rw------- 1 michael users 49211392 Jul 24 2003 Linuxcare_bootable_toolbox_V2.0.raw $ md5sum < Linuxcare_bootable_toolbox_V2.0.raw > Linuxcare_bootable_toolbox_V2.0.raw.md5sum //We take a look at our LV with lvdisplay(8). //Note that it's 128 MiB (LV Size) and entirely on our PV /dev/hda18. # lvdisplay -v /dev/VG1/LV1 | less --- Logical volume --- LV Name /dev/VG1/LV1 VG Name VG1 LV Write Access read/write LV Status available LV # 1 # open 1 LV Size 128 MB Current LE 4 Allocated LE 4 Allocation next free Read ahead sectors 1024 Block device 58:1 --- Distribution of logical volume on 1 physical volume --- PV Name PE on PV reads writes /dev/hda18 4 8402 44954 --- logical volume i/o statistic --- 8402 reads 44954 writes --- Logical extents --- //quit less(1) //We add PV /dev/hda19 to our VG VG1. # vgextend VG1 /dev/hda19 vgextend -- INFO: maximum logical volume size is 2 Terabyte vgextend -- doing automatic backup of volume group "VG1" vgextend -- volume group "VG1" successfully extended //We take a peek at our VG VG1 with vgdisplay(8). //Note that our VG VG1 has increased from 1 GiB to 2 GiB (VG Size). # vgdisplay -v VG1 | less --- Volume group --- VG Name VG1 VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 1 Open LV 1 MAX LV Size 2 TB Max PV 256 Cur PV 2 Act PV 2 VG Size 2 GB PE Size 32 MB Total PE 64 Alloc PE / Size 4 / 128 MB Free PE / Size 60 / 1.88 GB VG UUID NXIGYF-3g5t-wAEZ-xddi-sQWk-4LDt-TrRyfc --- Logical volume --- LV Name /dev/VG1/LV1 VG Name VG1 //quit less(1) //We take a look at our LV with lvdisplay(8). //Note that our LV LV1 is still entirely on PV /dev/hda18. # lvdisplay -v /dev/VG1/LV1 | less --- Logical volume --- LV Name /dev/VG1/LV1 VG Name VG1 LV Write Access read/write LV Status available LV # 1 # open 1 LV Size 128 MB Current LE 4 Allocated LE 4 Allocation next free Read ahead sectors 1024 Block device 58:1 --- Distribution of logical volume on 1 physical volume --- PV Name PE on PV reads writes /dev/hda18 4 8402 44954 --- logical volume i/o statistic --- 8402 reads 44954 writes --- Logical extents --- //quit less(1) //We move all of our LVs in VG VG1 off of PV /dev/hda18 //The --verbose option allows us to watch information on each PE movement. //It shows us the PV the PE is being moved from, which PE is being moved //and which LV that PE is in, and which LE of the LV it is, and it shows //us to which PV, and which PE on that PV, it is placed - and also a //progress counter for the move. //The --verbose option also allows us to see lots of other details of what //pvmove(8) does. # pvmove --verbose /dev/hda18 pvmove -- checking name of source physical volume "/dev/hda18" pvmove -- locking logical volume manager pvmove -- reading data of source physical volume from "/dev/hda18" pvmove -- checking volume group existence pvmove -- reading data of volume group "VG1" from lvmtab pvmove -- checking volume group consistency of "VG1" pvmove -- searching for source physical volume "/dev/hda18" in volume group "VG1" pvmove -- building list of possible destination physical volumes pvmove -- checking volume group activity pvmove -- moving physical extents in active volume group "VG1" pvmove -- WARNING: if you lose power during the move you may need to restore your LVM metadata from backup! pvmove -- do you want to continue? [y/n] y pvmove -- starting to move extents away from physical volume "/dev/hda18" pvmove -- checking for enough free physical extents in "VG1" pvmove -- /dev/hda18 [PE 0 [LV1 [LE 0]]] -> /dev/hda19 [PE 0] [1/4] pvmove -- /dev/hda18 [PE 1 [LV1 [LE 1]]] -> /dev/hda19 [PE 1] [2/4] pvmove -- /dev/hda18 [PE 2 [LV1 [LE 2]]] -> /dev/hda19 [PE 2] [3/4] pvmove -- /dev/hda18 [PE 3 [LV1 [LE 3]]] -> /dev/hda19 [PE 3] [4/4] pvmove -- changing lvmtab pvmove -- checking volume group name "VG1" pvmove -- checking volume group consistency of "VG1" pvmove -- checking existence of "/etc/lvmtab.d" pvmove -- storing volume group data of "VG1" in "/etc/lvmtab.d/VG1.tmp" pvmove -- storing physical volume data of "VG1" in "/etc/lvmtab.d/VG1.tmp" pvmove -- storing logical volume data of volume group "VG1" in "/etc/lvmtab.d/VG1.tmp" pvmove -- renaming "/etc/lvmtab.d/VG1.tmp" to "/etc/lvmtab.d/VG1" pvmove -- doing automatic backup of volume group "VG1" pvmove -- checking volume group name "VG1" pvmove -- checking volume group consistency of "VG1" pvmove -- checking existence of "/etc/lvmconf" pvmove -- storing volume group data of "VG1" in "/etc/lvmconf/VG1.conf.tmp" pvmove -- storing physical volume data of "VG1" in "/etc/lvmconf/VG1.conf.tmp" pvmove -- storing logical volume data of volume group "VG1" in "/etc/lvmconf/VG1.conf.tmp" pvmove -- checking existence of "/etc/lvmconf/VG1.conf.tmp" pvmove -- checking existence of "/etc/lvmconf/VG1.conf" pvmove -- checking for "/etc/lvmconf/VG1.conf.9.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.8.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.8.old" to "/etc/lvmconf/VG1.conf.9.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.8.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.7.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.7.old" to "/etc/lvmconf/VG1.conf.8.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.7.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.6.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.6.old" to "/etc/lvmconf/VG1.conf.7.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.6.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.5.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.5.old" to "/etc/lvmconf/VG1.conf.6.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.5.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.4.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.4.old" to "/etc/lvmconf/VG1.conf.5.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.4.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.3.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.3.old" to "/etc/lvmconf/VG1.conf.4.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.3.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.2.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.2.old" to "/etc/lvmconf/VG1.conf.3.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.2.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.1.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.1.old" to "/etc/lvmconf/VG1.conf.2.old" pvmove -- checking for "/etc/lvmconf/VG1.conf.1.old" pvmove -- checking for "/etc/lvmconf/VG1.conf" pvmove -- renaming "/etc/lvmconf/VG1.conf" to "/etc/lvmconf/VG1.conf.1.old" pvmove -- renaming "/etc/lvmconf/VG1.conf.tmp" to "/etc/lvmconf/VG1.conf" pvmove -- unlocking logical volume manager pvmove -- 4 extents of physical volume "/dev/hda18" successfully moved //We take a look at our LV with lvdisplay(8). //Note that all of our LVs (only one) are now off of PV /dev/hda18 (they're //now on PV /dev/hda19). # lvdisplay -v /dev/VG1/LV1 | less --- Logical volume --- LV Name /dev/VG1/LV1 VG Name VG1 LV Write Access read/write LV Status available LV # 1 # open 1 LV Size 128 MB Current LE 4 Allocated LE 4 Allocation next free Read ahead sectors 1024 Block device 58:1 --- Distribution of logical volume on 1 physical volume --- PV Name PE on PV reads writes /dev/hda19 4 8402 44954 --- logical volume i/o statistic --- 8402 reads 44954 writes --- Logical extents --- //quit less(1) //Meanwhile, back in the land of mere mortal userdom, as far as our user is //concerned, everything still looks the same. $ pwd /var/tmp/1 $ ls Linuxcare_bootable_toolbox_V2.0.raw Linuxcare_bootable_toolbox_V2.0.raw.md5sum $ ls -al total 48065 drwxr-xr-x 3 michael root 168 May 17 20:58 . drwxrwxrwt 15 root root 440 May 17 21:02 .. -rw------- 1 michael users 49211392 Jul 24 2003 Linuxcare_bootable_toolbox_V2.0.raw -rw------- 1 michael users 33 May 17 20:58 Linuxcare_bootable_toolbox_V2.0.raw.md5sum $ md5sum < Linuxcare_bootable_toolbox_V2.0.raw bdf50130010a5453a4d9649a560f6356 $ ls Linuxcare_bootable_toolbox_V2.0.raw Linuxcare_bootable_toolbox_V2.0.raw.md5sum $ cat Linuxcare_bootable_toolbox_V2.0.raw.md5sum bdf50130010a5453a4d9649a560f6356 //even the md5sum(1)s still look perfectly matched. //Our user attempts to copy in an additional fairly big file. $ cp /var/local/pub/mirrored/cdimage.debian.org/pub/cdimage-testing/sarge_d-i/i386/rc1/sarge-i386-netinst.iso sarge-i386-netinst.iso cp: writing `sarge-i386-netinst.iso': No space left on device //It doesn't fit on the filesystem currently. $ ls Linuxcare_bootable_toolbox_V2.0.raw Linuxcare_bootable_toolbox_V2.0.raw.md5sum sarge-i386-netinst.iso //So, at least for the moment, our user removes (rm(1)) the partial copy. $ rm sarge-i386-netinst.iso //So, ... superuser comes to the rescue :-) //We grow the LV LV1 by an additional 64 MiB # lvextend -L +64M /dev/VG1/LV1 lvextend -- extending logical volume "/dev/VG1/LV1" to 192 MB lvextend -- doing automatic backup of volume group "VG1" lvextend -- logical volume "/dev/VG1/LV1" successfully extended //We take a look at our LV with lvdisplay(8). //Note that the size (LV Size) has gone from 128 MiB to 192 MiB. # lvdisplay -v /dev/VG1/LV1 | less --- Logical volume --- LV Name /dev/VG1/LV1 VG Name VG1 LV Write Access read/write LV Status available LV # 1 # open 1 LV Size 192 MB Current LE 6 Allocated LE 6 Allocation next free Read ahead sectors 1024 Block device 58:1 --- Distribution of logical volume on 1 physical volume --- PV Name PE on PV reads writes /dev/hda19 6 8402 45063 --- logical volume i/o statistic --- 8402 reads 45063 writes --- Logical extents --- //quit less(1) //Now we grow the mounted filesystem - at least with reiserfs we can do this. //We use expr(1) to help us with the math a bit, ... reiserfs (at least this //version and filesystem) has a block size of 4 KiB ... so, 1 MiB would be //256 blocks. Since we grew our LV LV1 to 192 MiB, we want 192 MiB, hence //192 * 256 blocks - the resize option wants size given in blocks for this //reiserfs filesystem. # mount -o remount,resize=`expr 192 '*' 256` /dev/VG1/LV1 //Now our user looks at the filesystem space and size again - certainly //expanded from the original 128 MiB LV the filesystem was - and still is - on. $ df -k /var/tmp/1 Filesystem 1k-blocks Used Available Use% Mounted on /dev/VG1/LV1 196596 80952 115644 42% /var/tmp/1 //Again, for our user, things are still looking about the same - most notable //difference is the filesystem is now larger ... and our user's been in this //directory the whole time, uninterrupted, and no need to stop using or //accessing the files at any time. $ ls -al total 48065 drwxr-xr-x 3 michael root 168 May 17 21:03 . drwxrwxrwt 15 root root 440 May 17 21:02 .. -rw------- 1 michael users 49211392 Jul 24 2003 Linuxcare_bootable_toolbox_V2.0.raw -rw------- 1 michael users 33 May 17 20:58 Linuxcare_bootable_toolbox_V2.0.raw.md5sum //Our user tries copying that large file again - this time succeeding, now that //the LV LV1 and the filesystem on it have been grown. $ cp /var/local/pub/mirrored/cdimage.debian.org/pub/cdimage-testing/sarge_d-i/i386/rc1/sarge-i386-netinst.iso sarge-i386-netinst.iso //Our user takes a look about again and touch(1)es the copied file. $ ls -alb total 162849 drwxr-xr-x 3 michael root 208 May 17 21:05 . drwxrwxrwt 15 root root 440 May 17 21:02 .. -rw------- 1 michael users 49211392 Jul 24 2003 Linuxcare_bootable_toolbox_V2.0.raw -rw------- 1 michael users 33 May 17 20:58 Linuxcare_bootable_toolbox_V2.0.raw.md5sum -rw------- 1 michael users 117538816 May 17 21:06 sarge-i386-netinst.iso $ touch -r /var/local/pub/mirrored/cdimage.debian.org/pub/cdimage-testing/sarge_d-i/i386/rc1/sarge-i386-netinst.iso sarge-i386-netinst.iso //Our user did get that file copied in fine ... though we didn't give them //much extra room. That could also be quite intentional (while some //filesystems can be grown on-line, there isn't yet a filesystem that's freely //available for LINUX that can be shrunk on-line (while mounted). $ df -k /var/tmp/1 Filesystem 1k-blocks Used Available Use% Mounted on /dev/VG1/LV1 196596 195852 744 100% /var/tmp/1 //So, ... now in our demonstration our superuser wants to export the VG VG1 //at this time, and that means the filesystem must be unmounted, and thus //our user has to get out of there - at least for now. //So, ... our user gets out of there. $ pwd /var/tmp/1 $ cd $ pwd /home/m/michael //We unmount the filesystem. # umount /dev/VG1/LV1 //We attempt to export the VG VG1. # vgexport VG1 vgexport -- can't export active volume group "VG1" //That doesn't work quite yet, though, as the VG VG1 is still in an //active state. //So we deactivate it. # vgchange -a n VG1 vgchange -- volume group "VG1" successfully deactivated //Now we're able to successfully export VG VG1. # vgexport VG1 vgexport -- volume group "VG1" sucessfully exported //We take another peek with vgdisplay(8). # vgdisplay | less --- Volume group --- VG Name vg00 VG Access read/write VG Status available/resizable VG # 1 MAX LV 256 Cur LV 8 Open LV 6 MAX LV Size 255.99 GB Max PV 256 Cur PV 11 Act PV 11 VG Size 11.34 GB PE Size 4 MB Total PE 2904 Alloc PE / Size 2803 / 10.95 GB Free PE / Size 101 / 404 MB VG UUID gYQFWD-wb9h-IdYr-nxlC-Xp0l-2Uzh-uAf702 //we quit less(1) at the end - note no other volume groups - we just see //our prior existing VG vg00 (which we haven't been dealing with), but VG1 //is no longer seen in this manner, as it has been exported. //Now we proceed to reimport our VG ... except we import it giving it a new //name, calling it "VG2" this time. //If we had moved this disk (or its availability) to some other system, //we could just as easily have imported the VG on that other system. # vgimport VG2 /dev/hda18 /dev/hda19 vgimport -- doing automatic backup of volume group "VG2" vgimport -- volume group "VG2" successfully imported and activated //We take a peek with vgdisplay(8). //Note that the 2 GiB VG we exported (then VG1) is now back (as VG2), again //with 2 GiB (VG Size). # vgdisplay | less --- Volume group --- VG Name VG2 VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 1 Open LV 0 MAX LV Size 2 TB Max PV 256 Cur PV 2 Act PV 2 VG Size 2 GB PE Size 32 MB Total PE 64 Alloc PE / Size 6 / 192 MB Free PE / Size 58 / 1.81 GB VG UUID NXIGYF-3g5t-wAEZ-xddi-sQWk-4LDt-TrRyfc --- Volume group --- VG Name vg00 VG Access read/write //quit less(1) //We remount our same filesystem again - except now it's in VG VG2, instead of //VG1. Note also that the LV still has the same name (LV1) as before. # mount -t reiserfs /dev/VG2/LV1 /var/tmp/1 //Meanwhile, back in the land of mortal userdom, we go back to that //directory, now that the filesystem is mounted again. $ cd /var/tmp/1 //Our user looks about again ... as far as the user's concerned, everything //in that filesystem is precisely the same as it was before the VG was //exported. $ ls -alb total 162849 drwxr-xr-x 3 michael root 208 May 17 21:05 . drwxrwxrwt 15 root root 440 May 17 21:02 .. -rw------- 1 michael users 49211392 Jul 24 2003 Linuxcare_bootable_toolbox_V2.0.raw -rw------- 1 michael users 33 May 17 20:58 Linuxcare_bootable_toolbox_V2.0.raw.md5sum -rw------- 1 michael users 117538816 Aug 6 2004 sarge-i386-netinst.iso $