Directory and Files |
|
Directories and Files | ## Directories /etc/lvm - default lvm directory location /etc/lvm/backup - where the automatic backups go /etc/lvm/cache - persistent filter cache /etc/lvm/archive - where automatic archives go after a volume group change /var/lock/lvm - lock files to prevent metadata corruption # Files /etc/lvm/lvm.conf - main lvm configuration file $HOME/.lvm - lvm history |
Tools |
|
Diagnostic | lvmdump lvmdump -d <dir> dmsetup [info|ls|status] Note: by default the lvmdump command creates a tar ball |
Physical Volumes |
|
Display |
pvdisplay -v |
Scanning | pvscan -v Note: scans for disks for non-LVM and LVM disks |
adding | pvcreate /dev/sdb1 ## Create physical volume with specific UUID, used to recover volume groups (see miscellaneous section) pvcreate --uuid <UUID> /dev/sdb1 Common Attributes that you may want to use: -M2 create a LVM2 physical volume |
removing | pvremove /dev/sdb1 |
checking | pvck -v /dev/sdb1 Note: check the consistency of the LVM metadata |
change physical attributes |
## do not allow allocation of extents on this drive, however the partition must be in a vg otherwise you get an error --addtag add a tag |
moving | pvmove -v /dev/sdb2 /dev/sdb3 Note: moves any used extents from this volume to another volume, in readiness to remove that volume. However you cannot use this on mirrored volumes, you must convert back to non-mirror using "lvconvert -m 0" |
Volume Groups |
|
display | vgdisplay -v vgs -v vgs -a -o +devices vgs flags: #PV - number of physical devices #LV - number of configured volumes vgs attributes are: 1. permissions (r)|(w) 2. resi(z)eable 3. e(x)ported 4. (p)artial 5. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited 6. (c)luster |
scanning | vgscan -v |
creating |
vgcreate VolData00 /dev/sdb1 /dev/sdb2 /dev/sdb3 |
extending | vgextend VolData00 /dev/sdb3 |
reducing | vgreduce VolData00 /dev/sdb3 vgreduce --removemissing --force VolData00 |
removing | vgremove VolData00 Common Attributes that you may want to use: -f force the removal of any logical volumes |
checking | vgck VolData00 Note: check the consistency of the LVM metadata |
change volume attributes | vgchange -a n VolData00 Common Attributes that you may want to use: -a control availability of volumes within the group -l maximum logical volumes -p maximum physical volumes -s physical extent size (default is 4MB) -x resizable yes or no (see VG status in vxdisplay) |
renaming | vgrename VolData00 Data_Vol_01 note: the volume group must not have any active logical volumes |
converting metadata type | vgconvert -M2 VolData00 Note: vgconvert allows you to convert from one type of metadata format to another for example from LVM1 to LVM2, LVM2 offers bigger capacity, clustering and mirroring |
merging | # the old volumes group will be merged into the new volume group vgmerge New_Vol_Group Old_Vol_Group Note: you must unmount any fielsystems and deactivate the vg that is being merged "vgchange -a n <vg>", then you can activiate it again afterwards "vgchange -a y <vg>", then perform a vgscan, dont forget to backup the configuration |
spliting | vgsplit Old_Vol_Group New_Vol_Group [physical volumes] [-n logical volume name] |
importing | vgimport VolData00 Common Attributes that you may want to use: -a import all exported volume groups |
exporting | ## to see if a volume has already been export use "vgs" and look at the third attribute should be a x vgexport VolData00 Common Attributes that you may want to use: -a export all inactive volume groups |
backing up |
## Backup to default location (/etc/lvm/backup) # Backup to specific location all volume groups (notice the %s) |
restoring | vgcfgrestore -f /var/backup/VolData00_bkup VolData00 Common Attributes that you may want to use: -l list backups of file -f backup file -M metadataype 1 or 2 |
cloning | vgimportclone /dev/sdb1 Note: used to import and rename duplicated volume group |
special files | vgmknodes VolData00 Note: recreates volume group directory and logical volume special files in /dev |
Logical Volumes |
|
display |
lvdisplay -v ## Stripe size ## use complex command |
scanning | lvscan -v lvmdiskscan |
creating |
## plain old volume ## plain old volume but use extents, use 10 4MB extents (if extent size is 4MB) ## Mirrored volume |
extending |
lvextend -L 20M /dev/VolData00/vol01 Common Attributes that you may want to use: -L size of the volume [kKmMgGtT]
|
reducing/resizing |
lvreduce -L 5M /dev/VolData00/vol01 fsadm resize /dev/VolData01/data01 [size] |
removing | lvremove /dev/VolData00/vol01 |
adding a mirror to a non-mirrored volume |
lvconvert -m1 --mirrorlog core /dev/VolData00/vol01 /dev/sdb2 Note: you can also use the above command to remove a unwanted log |
removing a mirror from a mirrored volume |
lvconvert -m0 /dev/VolData00/vol01 /dev/sdb2 Note: the disk in the command is the one you want to remove |
Mirror a volume that has stripes | lvconvert --stripes 3 -m1 --mirrorlog core /dev/VolData00/data01 /dev/sdd1 /dev/sde1 /devsdf1 |
change volume attributes |
lvchange -a n /dev/VolData00/vol01 -a availability |
renaming | lvrename /dev/VolData00/vol_old /dev/VolData00/vol_new |
snapshotting | lvcreate --size 100M --snapshot -name snap /dev/vg01/data01 |
Miscellaneous |
|
Simulating a disk failure | dd if=/dev/zero of=/dev/sdb2 count=10 |
reparing a failed mirror no LVM corruption | ## check volume, persume /dev/sdb2 has failed lvs -a -o +devices # remove the failed disk from the volume (if not already done so) , this will convert volume into a non-mirrored volume vgreduce --removemissing --force VolData00 ## replace the disk physically, remember to partion it with type 8e fdisk /dev/sdb ........ ## add new disk to LVM pvcreate /dev/sdb2 ## add the disk back into volume group vgextend VolData00 /dev/sdb2 ## mirror up the volume lvconvert -m1 --mirrorlog core /dev/VolData00/vol02 /dev/sdb2 |
corrupt LVM metadata without replacing drive | # attempt to bring the volume group online vgchange -a y VolData00 # Restore the LVM configation vgcfgrestore VolData00 # attempt to bring the volume grou online vgchange -a y VolData00 # file system check e2fsck /dev/VolData00/data01 |
corrupt LVM metadata but replacing the faulty disk |
# attempt to bring the volume group online but you get UUID conflict errors make note of the UUID number Note: if you have backed the volume group configuration you can obtain the UUID number in the backup file by default located in /etc/lvm/backup or running "pvs -v" |