Wednesday, November 6, 2013

LVM snapshot and volume creation


I test this on my CentOS VirtualBox. Went well for me.
Increase the virtual disk size in Windows 7. Make sure you shut down the virtual machine (As it give me errors, may be if I have two disks I can do it on the non-primary)
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "C:\Users\kasun\VirtualBox VMs\centOS1\centOS1.vdi" --resize 20000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Login to the CentOS(virtual machine)
fdisk /edv/sda
n
primary partition
3
2089
2300
w
--------------------------
Reboot so it will be written to the partition table
--------------------------
n
primary partition
4
2301
2549
w
reboot
--------------------------

Two physical volumes.
pvcreate /dev/sda3
pvcreate /dev/sda4


pvscan
pvdisplay - display the physical volume

Create the volume group
vgcreate vol_grp_k /dev/sda3 /dev/sda4

vgscan
vgdisplay – will display the volume group

Create the logical volume
lvcreate -v -L 900MB -n vol_k_one vol_grp_k

Create the file system
mkfs.ext4 /dev/vol_grp_k/lv_one_k
Create a dir
mkdir /back
Mount so can be use for,
mount /dev/vol_grp_k/lv_one_k /back

Take a snapshot
Getting the snapshot from previously created partition
lvcreate --snapshot –-size=100M --name=Snap /dev/vol_grp_k

Snap will be mounted to this
mkdir /snap_shot

Mounting
mount -o ro /dev/vol_grp_k/lv_one_k /snap_shot
<Do what ever you want to do>
then remove the snapshot as you dont need it anymore

umount /dev/vol_grp_k/lv_one_k
lvremove /dev/vol_grp_k/lv_one_k


No comments:

Post a Comment