Skip to content

Instantly share code, notes, and snippets.

@SudeepParajuli
Last active July 25, 2018 04:41
Show Gist options
  • Save SudeepParajuli/6c6277593b43f017dde843b3fd5d1559 to your computer and use it in GitHub Desktop.
Save SudeepParajuli/6c6277593b43f017dde843b3fd5d1559 to your computer and use it in GitHub Desktop.
LVM and creating a snapshot

#LVM

  1. There are multiple physical disk in your system . use lsblk command to see it . Eg : /sda /sdb
  2. Each of the physical disk has partition like /sda1 /sda2
  3. use any of the physical disk partition to create a phyical volume . we can use only one disk or more . To create a physical disk use : pvcreate /dev/sdb 4.put these physical volume in the volume group by " vgcreate <vg-name> <physical-disk> vgcreate test /dev/sda1 /dev/sda2 5.we can use pvdisplay and vgdisplay to see information about physical and volume group . similarly we can find information regarding volume group via vgscan.
  4. we will create a new logical volume from volume group . lvcreate -n <lv-new name> --size 1G <vg-name> lvcreate -n helloworld --size 1G test
  5. Make a appropriate filesystem to recently created logical volume . mkfs.xfs /dev/<vg-name/<logical-volume-name>> mkfs.xfs /dev/test/sudeep 8.Make a directory and mount the newly created partition over there to use : mkdir /home/hello mount /dev/test/sudeep /home/hello 9.use lvdispaly to see the list of all logical volume.
  6. For checking and resizing e2fsck -f /dev/test/sudeep resize2fs /dev/test/sudeep

Note : creating a raid0 mdadm -v --create /dev/md0 --level=0 --raid-device=2 /dev/sda /dev/sdb

creating a snapshot

Lvm snapshot will create new block device .

Two types :

LVM 1 = readonly(2.4) LVM 2 = r/w (2.6) = no downtime

  1. use vgs command to view . Here we have to see the size of Vfree . If the size is 0 we have to attach a new physical disk .
  2. use df -h command to see the file system .
  3. pvcreate /dev/sde
  4. vgextend <vgname to extend> <physical volume name> vgextend vg-desk8 /dev/sde This command adds the block device /dev/sde to this volume group .
  5. create a snapshot now. lvcreate -s <name of volume group> -n <name of snapshot> -L <size of it > lvcreate -s /dev/mapper/vg-desk-root -n rootsnap -L512M 6.lvs 7.mount /dev/vg-desk8/rootsnap /mnt 8.ls -l /mnt

https://linuxconfig.org/linux-lvm-logical-volume-manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment