LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > sag47
User Name
Password

Notices

Rate this Entry

Extending an LVM volume on a VMWare host

Posted 08-23-2012 at 12:17 PM by sag47
Updated 03-25-2013 at 08:28 AM by sag47
Tags lvm, snapshot

Back story
This is going to be a short blog post. Mostly with commands. Basically I run a media server for online courses/lectures called Echo360 ESS. At some point the LVM volume which holds the lecture captures nearly filled up. I was getting Icinga alerts on it and by looking at the rate of data generation in munin showed me I had better hop to it. So that's what this post is about.

The fun stuff

Add disk to VM

I added a disk to the virtual machine and then rescanned disks so that it would be apparent in the VM.

Code:
#Add the disk to VMWare disk in VM settings
#then rescan the disks so it shows up
echo "- - -" > /sys/class/scsi_host/host0/scan
#check out what the new device is called
dmesg
#in my case the new device is /dev/sdf
Extending an LVM volume

Code:
#look at the devices in the volume
lvdisplay
#look at each device
pvdisplay /dev/sdb
pvdisplay /dev/sdd
#deactivate the logical volumes in the volume group
vgchange -an vg_echo360
#initialize the disk for use by LVM
pvcreate /dev/sdf
#get the VG Name and extend it
vgdisplay
vgextend vg_echo360 /dev/sdd
#get the LV name
lvdisplay
#now that we have the LV name let's extend it with the new LV in our LV group
lvextend /dev/vg_echo360/lv_echo360 /dev/sdf
#check that the volume has been successfully extended
vgdisplay -v
lvdisplay
#activate the logical volumes in the volume group vg_echo360
vgchange -ay vg_echo360
#check the filesystem before resizing
e2fsck -f /dev/mapper/vg_echo360-lv_echo360
#proceed to resize the ext2/3 filesystem to the new volume size
resize2fs /dev/mapper/vg_echo360-lv_echo360
Taking LVM snapshots for recovering changes

Take a snapshot of the disk before removing raw files older than 120 days. Here is the find command which will be used.

Code:
find . -mtime +120 -type f -name '*.h264' -o -mtime +120 -type f -name '*.aac' -exec rm {} \;
dd if=/dev/zero of=/app/loop bs=1 count=1 seek=10737418240
losetup -f /app/loop
pvcreate /dev/loop0
vgextend vg_echo360 /dev/loop0
#create the snapshot
lvcreate -s -n echo_snapshot1 /dev/vg_echo360/lv_echo360 -L 9.9G
Recover data from the snapshot

Code:
mkdir /mnt/snapshot_recovery
mount /dev/vg_echo360/echo_snapshot1 /mnt/snapshot_recovery
#Now the path /mnt/snapshot_recovery contains the filesystem at a state from when the snapshot was taken.
Removing the snapshot

Code:
lvremove /dev/vg_echo360/echo_snapshot1
#Do not allow the LVG to allocate data to /dev/loop0 any longer.  This sets the PV Status to NOT allocatable.
pvchange -xn /dev/loop0
#Check out the status of /dev/loop0 compared to the other devices.
vgdisplay -v
#Remove the loopback device from the LVG entirely.
vgreduce vg_echo360 /dev/loop0
#See that the device is missing in the following command?
vgdisplay -v
#Now that the device is removed from the LVG you can remove the loopback device from the system entirely.
losetup -a
#/dev/loop0 is the device I want to remove which is using /app/loop.
losetup -d /dev/loop0
rm /app/loop

#If you accidentally removed the loopback device before removing it from the LVM that's okay.  Just be sure to run the following command on the LVG.
vgreduce --removemissing vg_echo360
That's about it. Use the man pages to exercise a better understanding!

SAM
Posted in Uncategorized
Views 717 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:17 AM.

Main Menu

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration