Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

RedHat - LVM Cheatsheet

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5
At a glance
Powered by AI
The key takeaways from the document are that LVM (Logical Volume Manager) allows for dynamic resizing and management of logical volumes on Linux. It discusses the main components of LVM including physical volumes, volume groups and logical volumes. It also provides an overview of many common LVM commands.

The main components of LVM are physical volumes (PVs), volume groups (VGs), and logical volumes (LVs). Physical volumes represent individual disk partitions. Volume groups allow combining multiple physical volumes into a single logical storage area. Logical volumes are what the filesystem sees and mounts - they are created within volume groups from physical extents.

Some common commands used to manage physical volumes include pvdisplay to view details, pvcreate to initialize a PV, pvremove to remove a PV, pvchange to modify attributes, and pvmove to move data from one PV to another prior to removal.

Logical Volume Manager (LVM)

This is a quick and dirty cheat sheet on LVM using Linux, I have highlighted many of the common attributes for each command however this is not an extensive list, make sure you look up the command. With the pvs, vgs and lvs commands, the number of verboses added the more verbose information for example pvs -vvvvv
Directory and Files ## Directories /etc/lvm /etc/lvm/backup /etc/lvm/cache /etc/lvm/archive /var/lock/lvm # Files /etc/lvm/lvm.conf $HOM E/.lvm - default lvm directory location - where the automatic backups go - persistent filter cache - where automatic archives go after a volume group change - lock files to prevent metadata corruption

Directories and Files

- main lvm configuration file - lvm history Tools

lvmdump diagnostic lvmdump -d <dir> dmsetup [info|ls|status] Note: by default the lvmdump command creates a tar ball Physical Volumes pvdisplay -v pvs -v pvs -a display pvs attributes are: 1. (a)llocatable 2. e(x)ported pvscan -v scanning Note: scans for disks for non-LVM and LVM disks 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: -M 2 create a LVM 2 physical volume removing pvremove /dev/sdb1 pvck -v /dev/sdb1 checking Note: check the consistency of the LVM metadata ## do not allow allocation of extents on this drive pvchange -x n /dev/sdb1 change physical attributes Common Attributes that you may want to use: --addtag add a tag -x allowed to allocate extents -u change the uuid pvmove -v /dev/sdb2 /dev/sdb3 moving

adding

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 vgdisplay -v vgs -v vgs -a -o +devices vgs flags: #PV - number of physical devices #LV - number of configured volumes display 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 vgcreate VolData00 /dev/sdb1 /dev/sdb2 /dev/sdb3 vgcreate VolData00 /dev/sdb[123] ## Use 32M B extent size vgcreate VolData00 -s 32 /dev/sdb1 creating Common Attributes that you may want to use: -l maximum logical volumes -p maximum physical volumes -s physical extent size (default is 4M B) -A autobackup extending vgextend VolData00 /dev/sdb3 vgreduce VolData00 /dev/sdb3 reducing vgreduce --removemissing --force VolData00 vgremove VolData00 removing Common Attributes that you may want to use: -f force the removal of any logical volumes vgck VolData00 checking Note: check the consistency of the LVM metadata vgchange -a n VolData00 Common Attributes that you may want to use: change volume attributes -a control availability of volumes within the group -l maximum logical volumes -p maximum physical volumes -s physical extent size (default is 4M B) -x resizable yes or no (see VG status in vxdisplay) vgrename VolData00 Data_Vol_01 renaming note: the volume group must not have any active logical volumes vgconvert -M 2 VolData00 converting metadata type Note: vgconvert allows you to convert from one type of metadata format to another for example from LVM 1 to LVM 2 vgmerge New_Vol_Group Old_Vol_Group merging

Note: the old volumes group will be merged into the new volume group spliting vgsplit Old_Vol_Group New_Vol_Group [physical volumes] [-n logical volume name] vgimport VolData00 importing Common Attributes that you may want to use: -a import all exported volume groups ## to see if a volume has already been export use "vgs" and look at the third attribute should be a x vgexport VolData00 exporting Common Attributes that you may want to use: -a export all inactive volume groups ## Backup to default location (/etc/lvm/backup) vgcfgbackup VolData00 backing up # Backup to specific location vgcfgbackup -f /var/backup/VolData00_bkup VolData00 Note: the backup is written in plain text and are by default located in /etc/lvm/backup vgcfgrestore -f /var/backup/VolData00_bkup VolData00 Common Attributes that you may want to use: restoring -l list backups of file -f backup file -M metadataype 1 or 2 vgimportclone /dev/sdb1 cloning Note: used to import and rename duplicated volume group vgmknodes VolData00 special files Note: recreates volume group directory and logical volume special files in /dev Logical Volumes lvdisplay -v lvdisplay --maps lvs -v lvs -a -o +devices ## lvs commands for mirror volumes lvs -a -o +devices lvs -a -o +seg_pe_ranges --segments display lvs attributes are: 1. volume type: (m)irrored, (M )irrored without initail sync, (o)rigin, (p)vmove, (s)napshot, invalid (S)napshot, (v)irtual, mirror (i)mage mirror (I)mage out-of-sync, under (c)onversion 2. permissions: (w)rite, (r)ead-only 3. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited 4. fixed (m)inor 5. state: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid (S)uspended snapshot, mapped (d)evice present with-out tables, mapped device present with (i)nactive table 6. device (o)pen (mounted in other words) lvscan -v lvmdiskscan ## plain old volume lvcreate -L 10M VolData00 ## plain old volume but with a specific name web01 lvcreate -L 10M -n web01 VolData00 display mirror volumes

scanning

## plain old volume but on a specific disk lvcreate -L 10M VolData00 /dev/sdb1 ## a striped volume called lvol1 (note the captial i for the stripe size) lvcreate -i 3 -I 32 -L 24M -n lvol1 vg01 ## M irrored volume creating lvcreate -L 10M -m1 -n data01 vg01 ## M irrored volume without a mirror log file lvcreate -L 10M -m1 --mirrorlog core -n data01 vg01 Common Attributes that you may want to use: -L size of the volume [kKmM gGtT] -l number of extents -C contiguous [y|n] -i stripes -I stripe size -m mirrors --mirrorlog -n volume name

lvextend -L 20M /dev/VolData00/vol01 Common Attributes that you may want to use: -L size of the volume [kKmM gGtT] -l number of extents -C contiguous [y|n] -i stripes extending -I stripe size Note: you can extend a ext2/ext3 filesystem using the "resize2fs" or "fsadm" command fsadm resize /dev/VolData01/data01 resize2fs -p /dev/mapper/VolData01-data01 [size] The -p option displays bars of progress while extendingthe filesystem

lvreduce -L 5M /dev/VolData00/vol01 lvresize -L 5M /dev/VolData00/vol01 reducing/resizing Note: rounding will occur when extending and reducing volumes to the next extent (4M B by default), you can use resize2fs or fsadm to shrink the filesystem fsadm resize /dev/VolData01/data01 [size] resize2fs -p /dev/mapper/VolData01-data01 [size] removing adding a mirror to a nonmirrored volume lvremove /dev/VolData00/vol01 lvconvert -m1 --mirrorlog core /dev/VolData00/vol01 /dev/sdb2

lvchange -a n /dev/VolData00/vol01 Common Attributes that you may want to use: -a availability -C contiguous [y|n]

change volume attributes

renaming snapshotting

lvrename /dev/VolData00/vol_old /dev/VolData00/vol_new lvcreate --size 100M --snapshot -name snap /dev/vg01/data01 Miscellaneous

Simulating a disk failure

dd if=/dev/zero of=/dev/sdb2 count=10

## 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 reparing a failed mirror no LVM corruption ........ ## 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 # attempt to bring the volume group online vgchange -a y VolData00 # Restore the LVM configation corrupt LVM metadata without replacing drive vgcfgrestore VolData00 # attempt to bring the volume grou online vgchange -a y VolData00 # file system check e2fsck /dev/VolData00/data01 # attempt to bring the volume group online but you get UUID conflict errors make note of the UUID number vgchange -a y VolData00 vgchange -a n VolData00 ## sometimes it my only be a logical volume problem lvchange -a y /dev/VolData00/web02 lvchange -a n /dev/Voldata00/web02 ## replace the disk physically, remember to partion it with type 8e fdisk /dev/sdb ........ corrupt LVM metadata but # after replacing the faulty drive the disk must have the previuos UUID number or you can get it from /etc/lvm directory replacing the faulty disk pvcreate --uuid <previous UUID number taken from above command> /dev/sdb2 # Restore the LVM configation vgcfgrestore VolData00 # attempt to bring the volume group online or logical volume vgchange -a y VolData00 lvchange -a y /dev/VolData00/web02 # file system check e2fsck /dev/VolData00/data01 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"

For other LVM's and Array utilities see my LVM central page

You might also like