Extending an LVM volume on a VMWare host
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.
Extending an LVM volume
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.
Recover data from the snapshot
Removing the snapshot
That's about it. Use the man pages to exercise a better understanding!
SAM
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
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
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
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.
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
SAM
Total Comments 0




