~~socialite:icon reddit googleplus stumbleupon twitter~~ =====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/sd//xx//** - 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/sd//xx//** - Delete the device: **echo "1" > /sys/block///device-name//device/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 [[linux_storage]] will tell you how to delete them **Still stuck? Maybe we can help.** Contact us [[https://www.upwork.com/o/profiles/users/_~01207a4bc438b48c6e|at Upwork]] Never miss a thing [[http://www.justsomestuff.co.uk/subscribe.php|subscribe to our newsletter]] {{glyphicon>envelope}} or follow us [[http://twitter.com/itsjustsomestuf|on twitter]] {{glyphicon>hand-left}} For more super cool techie stuff [[http://www.justsomestuff.co.uk/theblog|check out our blog!!]] ===Recent Changes=== {{changes>}} ====Contribute to this wiki==== Why not help others by sharing your knowledge? Contribute something to this wiki and [[http://www.justsomestuff.co.uk/hall_of_fame.html|join out hall of fame!]]\\ [[http://www.justsomestuff.co.uk/theblog/contact-page|Contact us]] for a user name and password