Linux LVM Tips
Resize a partition
- lvextend –size +15g /dev/vg-name/vol-name - increase a volume by 15GB
- resize2fs /dev/vg-name/vol-name - resize the filesystem to the same size as the volume
Extending a filesystem using a new LUN - (Linux VM example)
- Format the disk with fdisk as a linux VM fstype
- vgextend vgname /dev/sdxx - add the newdisk to a volume group
- Check the volume group by running vgdisplay -v vgname
- Move the disk: pvmove /dev/old-disk /dev/new-disk
- Now extend the volume: lvextend -l +nnnnn /dev/vg-name/lv-name
- Extend the filesystem: resize2fs /dev/vg-name/lv-name
- Remove the old disk: vgreduce vg-name /dev/sdxx
- Delete the device: echo “1” > /sys/block/device-namedevice/delete
- In the vSphere client, for the VM, edit settings → select drive → remove
Creating a logical volume that will use all available space in a volume group
- lvcreate -n vol-name -L 1m /dev/vg-name - create a 1MB volume
- lvextend -l +100%FREE /dev/vg-name/vol-name - extend the volume using all available space
- mkfs -t ext3 /dev/vg-name/vol-name - create the filesystem
Importing a LVM Volume
- vgscan - make sure the volume group is visible to the target server
- vgchange -a y my-vg - activate the volume group my-vg
- ls /dev/mapper - LVM devices in the volume group should now be present
- mount /dev/mapper/my-vg-lv /mnt - mount the logical volume
Importing a volume with a conflicting volume group name (the VG name already exists on target server)
- Present the volume containing the VG to the server
- Run lvmdiskscan to check the disk is visible
- vgdisplay -v - make a note of the conflicting VG UUID
- Rename the VG by using the UUID e.g. vgrename VG-UUID vg00-import
- Activate the renamed VG: vgchange -a y vg00-import
- You can now mount the logical volume(s)
Migrating a volume with pvmove e.g. to a LUN on a different disk array
- pvcreate the new disk: pvcreate /dev/mapper/mpathNEW
- Add to the volume group used by the volume to migrate: vgextent my_vg /dev/mapper/mpathNEW
- Start moving the data: pvmove -b /dev/mapper/mpathOLD /dev/mapper/mpathNEW
- You can check the progress as follows: lvs -a -o+devices
- Once the move is complete, remove the old LUN from the volume group: vgreduce my_vg /dev/mapper/mpathOLD
- Finally, one it's confirmed everything is working as expected, you can run: pvremove /dev/mapper/mpathOLD
If you get stuck with old devices, this page Useful Linux Storage stuff will tell you how to delete them
Still stuck? Maybe we can help. Contact us at Upwork
Never miss a thing subscribe to our newsletter
or follow us on twitter
For more super cool techie stuff check out our blog!!
Recent Changes
Contribute to this wiki
Why not help others by sharing your knowledge? Contribute something to this wiki and
join out hall of fame!
Contact us for a user name and password