===Snapshots===
To **Create** snapshots:
lvcreate (Volumn) -s -n (name of the snapshot) (location to store the snapshot)
e.g. lvcreate -L300G -s -n ecc-b-01v.snap /dev/vm/ecc-b-01v
To **Remove** snapshots:
lvremove (name of snapshot @ stored location)
e.g. lvremove /dev/vm/ecc-b-01v.snap
To **Restore** snapshots:
lvconvert --merge (Logical Volume Path)
e.g. lvconvert --merge /dev/vg0/win10.snap
===Required Packages===
```
sudo apt install nano \
util-linux linux-tools-common cpufrequtils lm-sensors libusb-dev \
git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev git-email \
libcap-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev valgrind \
xfslibs-dev -y git-email libnfs-dev libiscsi-dev libsdl2-dev libncurses5-dev \
libaio-dev libjemalloc-dev libjemalloc* libusb-1.0-0-dev
```
===Test Environment==
```
ecc-admin@lkramer:~$ dd if=/dev/zero of=./disc.img bs=1M count=8096 #Copies 8096 blocks from /dev/zero to ./disc.img at 1MB
"...."
ecc-admin@lkramer:~$ sudo -i #Switch to super user
[sudo] password for ecc-admin:
root@lkramer:~# apt install lvm2 #Installs the lvm2 package
"...."
Do you want to continue? [Y/n] y
"...."
ecc-admin@lkramer:~$ pwd #Prints working directory
ecc-admin@lkramer:~$ sudo pvcreate /home/ecc-admin/disc.img
/home/ecc-admin
ecc-admin@lkramer:~$ pvcreate /home/ecc-admin/disc.img
ecc-admin@lkramer:~$ sudo !! #Repeats previous command as super user
sudo pvcreate /home/ecc-admin/disc.img#Creates physical volume at file location
ecc-admin@lkramer:~$ sudo losetup /dev/loop0 disc.img
ecc-admin@lkramer:~$ sudo fdisk -l /dev/loop0
Disk /dev/loop0: 7.9 GiB, 8489271296 bytes, 16580608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes#Creates a "fake" file that acts as a block-device
ecc-admin@lkramer:~$ sudo pvcreatefdisk -l /dev/loop0
Physical volume "/dev/loop0" successfully created #Lists the partition tables for the loop
ecc-admin@lkramer:~$ sudo pvdisplay
"/dev/loop0" is a new physical volume of "7.91 GiB"
--- NEW Physical volume ---
PV Name /dev/loop0
VG Name
PV Size 7.91 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID eMNWVe-qniS-mQmv-e9bc-xh7g-Haxr-khcRwKcreate /dev/loop0 #Creates physical volume
ecc-admin@lkramer:~$ sudo pvdisplay #Shows details of physical volume
ecc-admin@lkramer:~$ vgcreate vg37 /dev/loop0
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lvm/lvmetad.socket: connect failed: Permission denied
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lock/lvm/V_vg37:aux: open failed: Permission denied
Can't get lock for vg37.
ecc-admin@lkramer:~$ sudo vgcreate vg37 /dev/loop0
V
#Creates a new volume group named "vg37" successfully createdin the directory /dev/loop0
ecc-admin@lkramer:~$ sudo lvcreate -L 2G -nVol vg37
Logical volume "Vol" created.
ecc-admin@lkramer:~$ sudo mkfs.ext4 /dev/mapper/
control vg37-Vol
ecc-admin@lkramer:~$ sudo mkfs.ext4 /dev/mapper/
control vg37-Vol#Creates logical volume. Size 2G, named Vol, placed in vg37 volume group.
ecc-admin@lkramer:~$ sudo mkfs.ext4 /dev/mapper/vg37-Vol
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 8ef98944-f257-45ec-8eda-43d12f82b3b0
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done#Creates an ext4 file system /dev/mapper/vg37-Vol
ecc-admin@lkramer:~$ sudo mount /dev/mapper/vg37-Vol /mnt
ecc-admin@lkramer:~$ mount
"...."
ecc-admin@lkramer:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 799M 8.6M 790M 2% /run
/dev/vda1 63G 7.2G 53G 12% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 799M 0 799M 0% /run/user/1000
/dev/mapper/vg37-Vol 2.0G 3.0M 1.8G 1% /mnt
ecc-admin@lkramer:~$ ls
automate_life.sh disc.img mount_life.sh unmount_life.sh
ecc-admin@lkramer:~$ cat automate_life.sh
```
===LVM Setup ===
```
lang=bash
#!/bin/bash
DISK=/dev/sdd #Setting up the disk drive
#Partitions the disk
parted ${DISK} -s mklabel gpt #Scripts to make a new disk label of type gpt
parted ${DISK} -s mkpart "" fat32 0% 512MB #Scripts to make a partition of filesystem fat32 that starts at the beginning of the existing disk and ends at 512MB
parted ${DISK} -s mkpart "" ext4 512MB 100% #Scripts to make a partition of filesystem ext4 that starts at 512MB and stops at the end of the existing disk
parted ${DISK} -s set 1 boot on #Scripts the first partition flag to "boot" and the state to "on"
parted ${DISK} -s set 2 lvm on #Scripts the second partition flag to "lvm" (logical volume management) and the state to "on"
sync #Writes data in the buffer to the disk
mkfs.vfat ${DISK}1 #Creates a FAT file system??
pvcreate ${DISK}2 #Creates physical volume
vgcreate vg1 ${DISK}2 #Creates 1 copy of a new volume group
lvcreate -L 60GB -n root vg1 #Creates a new logical volume in the volume group created in the last command. Allocates 60GB named "root".
lvcreate -L 16GB -n var vg1 #Creates a new logical volume. Allocates 16GB named "var".
dd if=/dev/mapper/vg0-root of=/dev/mapper/vg1-root bs=1M status=progress
#Copies data from /dev/mapper/vg0-root to /dev/mapper/vg1-root at 1M
#Gives a warning if the previous copy command failed and exits the program
if [[ $? != 0 ]]; then
echo "root dd failed"
exit 1
fi
dd if=/dev/mapper/vg0-var of=/dev/mapper/vg1-var bs=1M status=progress
#Copies data from /dev/mapper/vg0-var to /dev/mapper/vg1-var at 1M
#Gives a warning if the previous copy command failed and exits the program
if [[ $? != 0 ]]; then
echo "var dd failed"
exit 1
fi
mount /dev/mapper/vg1-root /mnt && \ #Mounts the filesystem /dev/mapper/vg1-root to the directory /mnt
mount /dev/mapper/vg1-var /mnt/var && \ #Mounts the filesystem /dev/mapper/vg1-var to the directory /mnt/var
mount ${DISK}1 /mnt/boot/efi && \ #Mounts the created file system to the EFI partition
mount --bind /dev /mnt/dev && \ #Connects the file systems /dev and /mnt/dev to make them both accessible from either location
mount --bind /run /mnt/run && \ #Connects the file systems /run and /mnt/run to make them both accessible from either location
mount --bind /sys /mnt/sys && \ #Connects the file systems /sys and /mnt/sys to make them both accessible from either location
mount --bind /proc /mnt/proc #Connects the file systems /proc and /mnt/proc to make them both accessible from either location
#Gives a warning if the mount failed and exits the program
if [[ $? != 0 ]]; then
echo "failed to mount"
exit 1
fi
# Modify /etc/hostnmae
# Modify /etc/hosts
# Modify /etc/fstab
# Install grub
# Update grub
```