M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Practical Exercise 11b: Basic Logical Volume Management 21-3-19

Practical Exercise 11b:  Basic Logical Volume Management

GENERAL CONDITIONS
1- Deadline DAW1
    PART I: 21
-02-2020.
    PART II: 27-02-2020
    PART III: 27-02-2020
2-
Deadline ASI1
    PART I: 25-02-2020.
    PART II: 25-02-2020
    PART III: 2-03-2020

1- DOCUMENTATION

1.1.- What is LVM.?. Concepts 

a) Basic ideas:
1- LVM stands for Logical Volume Management.
2- LVM allows administrators or developers to easily combine  multiple physical hard drives and/or physical partitions with the purpose of  creating  logical drives.
3- LVM shows to your operating system logical drives and volume groups  and "hides" physical hard drives and physical partitions.
4- LVM, logical volumes and volume group provide multiples advantages to users, developers and administrators with respect to the system of working directly with partitions and physical drives.

b) Some Advantges
1- Most operations can be done on the fly, while the system is running . It means that you can dynamically expand, shrink, move and create volumes. For instance: 
    * You can create a small logical volume and  resize it dynnamically as it get filled up.
    * With LVM, if your system is running out of disk space, you can just add another disk and extend the logical volume on the fly.
2- Adding and replacing disks without service disruption (in combination with hot swaping)
3- Snapshopts of logical volumes at any moment, even while the system is running. A snapshot is the state of a system at a particular point in time, in other words, a read-only copy of the data set frozen at a point in time.
4- Use any number of disks as one big disk.
5- Filesystem encrytion
6- Caching of frequently used data.
7- Logical volumes can span across multiple disks, and do not have to be physically contiguous.
8- Online operation such as resize , move, creates disks, or move data onto newer drives, or taking old drives out of service.
9- Reallocate data (databases, user data, etc...).

c) LVM concepts and definitions

1-  Physical Volume: Physical Volumes correspond to physical disks or partitions. They are physical block devices such as /dev/sda, /dev/sdb, /dev/sdc1....

2- Volume Group:  It is a named collection of physical  volumes. 
A volume  group is  the LVM equivalent of a hard disk. It' s a kind of "logical hard drive". You can name Volume Groups however you like but it's highly recommended to provide  your volume groups with unique and  meaningful names. File systems can NOT be installed on a volume group. Volume groups can NOT be mounted.

3- Logical Volume: Logical volumes are the LVM equivalent of partitions: they hold a filesystem. Unlike partitions though, logical volumes get names rather than numbers, they can span across multiple disks, and do not have to be physically contiguous.
File systems can be installed on a logical volume. Logical volumes can be mounted.

1.3.- Commands. Steps required to configure LVM

In ordet to manage LVM there are a set the command line tools available. Most of the commands in LVM are very similar to each other. Each valid command is preceded by:

The physical volume commands are for adding or removing hard drives in volume groups. Volume group commands are for changing what abstracted set of physical partitions are presented to your operating in logical volumes. Logical volume commands will present the volume groups as partitions so that your operating system can use the designated space.

The steps required to configure LVM include:

1st  step --> Initialize a block divice to be used as a physical volume (pvcreate)
2nd step --> Create  volume groups (vgcreate)
3rd step (no mandatory) -->  Add additional physical volumes to an exisiting volume group (vgextend)
4th  step --> Create logical volumes (lvcreate)
5th  step -->  Build filesystems  (mkfs)
6th  step --> Mount  filesystems (mount)

The steps required to remove logical, group and physcal volumes LVM include:

1st  step -->  Umount  filesystems (umount)
2nd step -->  Remove logical volumes (lvremove)
3rd  step 
(no mandatory) -->  Reduce a volume grroup or in other words, remove physical volumes from a volume group (vgreduce)
4th  step -->  Remove  a volume group (vgremove)
5th  step -->  Remove physical voumes if a device is no longer required for use by LVM (pvremove)

In order to display properties or attributes of:

a) Logical volumes -->  Run lvdisplay
b) Volume groups --> Run vgdisplay
c) Physical volumes --> Run pvdisplay


1.4.- Installation

All tools to manage a LVM volume are available in lvm2 package ==> Run: sudo  aptitude  install  lvm2


1.5.- Creating physical volumes

a) To declare the /dev/sda2 as a physical volume available for the LVM:   sudo  pvcreate  /dev/sda2
b)
In order to remove the physical volume on  /dev/sda2: sudo  pvremove  /dev/sda2  
c)
To check a physycal volume: sudo  pvdisplay  /dev/sda2

1.6.- Creating volume groups

a) To create a volume group called vg1 made of  /dev/sda2 and sdb3:   sudo  vgcreate  vg1  /dev/sda2  /dev/sdb3
b)
In order to remove /dev/sda2 from the volume group vg1: sudo  vgreduce  vg1  /dev/sda2
c) In order to remove all the physical volumes from the volume group vg1: sudo  vgreduce  -a  vg1
d)
In order to remove a volume group called vg1: sudo  vgremove  vg1
e) To check a volume group called vg1: sudo  vgdisplay  vg1

1.7.- Creating logical volume

a) To create a 4GB logical volume called logvol1 in a volume group called vg1:   sudo  lvcreate  -n  logvol1  -L  4g  /dev/vg1
b)
In order to remove a logical volume called logvol1 from a volume group called vg1: sudo  lvremove  /dev/vg1/logvol1
e) To check a logical volume
called logvol1 in a volume group called vg1: sudo  lvdisplay  /dev/vg1/logvol1

1.8.- Formatting a logical volume

a) To format a logical volume called logvol1 created in a volume group called vg1: sudo  mkfs  -t  ext4  /dev/vg1/logvol1

1.9.- Mounting a logical volume

a) To mount an Ext4 logical volume called logvol1 created in a volume group called vg1 using as a mount point /mnt/logvol1: sudo  mount   -t  ext4  /dev/vg1/logvol1  /mnt/logvol1

References
a)
https://wiki.debian.org/LVM
b)
https://wiki.ubuntu.com/Lvm
c)
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Cluster_Logical_Volume_Manager/LVM_CLI.html

2- PRACTICAL EXERCISE

PART I

1-
Shutdown your virtual machine. Make the following changes on your virtual machine:
    a) Select Storage --> Controller: SATA -->  "Port Count". Change Port Count to 6 (It means that you can plug 4 SATA disks into your virtual machine).
    b) Select disk01 --> Attributes. Tick the Hot-pluggable option.

    c) Select disk02 --> Attributes. Tick the Hot-pluggable option.
2- Install and start lvm2 on your system. Run the following command: sudo aptitude install lvm2
3- Run  fdisk and
     a)
Create a new empty  MBR (also called DOS) partition table on /dev/sdb and /dev/sdc
     b) Create one single primary partition for the full size of the SATA1 and SATA2 hard drives.
     c) Change the partition type to 8e - Linux LVM.
4- Declare /dev/sdb1 and /dev/sdc1 as LVM physical volumes. Show information about both LVM physycal volumes.
5- Create a volume group called vg01 made of  /dev/sdb1 and /dev/sdc1. Show information about the LVM volume group.
6- Create a 25GiB logical volume called lv1 in the volume group  previously created.  Show information about the LVM logical volume.
7-
Create a 10GiB logical volume called lv2 in the volume group previously created. Show information about the LVM logical volume.
8-  Format  lv1 and lv2.  The format will be ext4.
9-  Mount  lv1 on /mnt/lv1 (if /mnt/lv1 does not exist then, create it). Check that lv1 has been mounted.
10- Mount  lv2 on /mnt/lv2 (if /mnt/lv2 does not exist then, create it). Check that lv2 has been mounted.
11- Take the following screenshots:
   NOTE: Capture names start with asix1 or daw1 depending on what your group is.
    a) An screenshot of the results shown by your system after running: sudo fdisk -l /dev/sdb. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part1_cap1.jpg 
    b)
An screenshot of the results shown by your system after running: sudo pvdisplay  /dev/sdb1. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part1_cap2.jpg
    c)
An screenshot of the results shown by your system after running: sudo vgdisplay  /dev/vg01. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part1_cap3.jpg
    d)
An screenshot of the results shown by your system after running: sudo lvdisplay  /dev/vg01/lv1. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part1_cap4.jpg
   
e) An screenshot of the results shown by your system after running: df -Th -t ext4. . Capture name: asix1/daw1_surname_name_m01tu1ex11b_part1_cap5.jpg
12- Send your screenshots attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending on who your teacher is.
     b
) Subject:  asix1_surname_name_m01tu01pr11b_part1 or
daw1_surname_name_m01tu01pr11b_part1 depending on what your group is.         

PART II
1- Unmount lv1 and lv2. Check that lv1 and lv2 have been unmounted.
2- Remove the logical  lv1 and   lv2. Check that lv1 and  lv2 have been removed.
3- Remove the volume group vg01. Check that the volume group has been removed.
4- Remove the physical volumes /dev/sdb1 and /dev/sdc1. Check that both physical volumes have been successfully wiped.
5- Change partitions type to 83 - Linux. Check it.
6- Take the following screenshots:
   NOTE: Capture names start with asix1 or daw1 depending on what your group is.
    a) An screenshot after unmounting lv1 and lv2. Run the following command: sudo df -Th -t ext4. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part2_cap1.jpg 
    b)
An screenshot after removing lv1. Run the following command:  sudo lvdisplay  /dev/vg01/lv1. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part2_cap2.jpg
    c)
An screenshot after removing vg01. Run the following command: sudo vgdisplay  /dev/vg01. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part2_cap3.jpg
    d)
An screenshot after wiping /dev/sdb1.
Run the following command:  sudo pvdisplay  /dev/sdb1. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part2_cap4.jpg
   
e) An screenshot after changing the partition type of /dev/sdb1 and sdc1.
Run the following command: sudo fdisk -l. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part2_cap5.jpg
7- Send your screenshots attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending on who your teacher is.
     b
) Subject:  asix1_surname_name_m01tu01pr11b_part2 or
daw1_surname_name_m01tu01pr11b_part2 depending on what your group is.   

PART III

1-
Run  fdisk and:
     a) Create one single primary partition for the full size of the SATA1 and SATA2 hard drives.
     b) Change /dev/sdb1 and /dev/sdc1  partition type to 8e - Linux LVM.

2- Create a new logical volumen lv3:
    a)
Declare /dev/sdb1 and /dev/sdc1 as LVM physical volumes.
    b)
Create a volume group called vg3 made of  /dev/sdb1 and /dev/sdc1.
    c)
Create a logical volume called lv3 that fills up the total size of vg3. Check that lv3 has been properly created.
    HELP!!!!!: In order to create a logical volume that fills up the total size of a volume group, you should use --extents   100%VG 
    d) Install an ext4 filesystem on lv3.
    e) Mount lv3 on /mnt/lv3.
Check that lv3 has been properly mounted.
3- Do not poweroff your computer and:
    a) Add a new hard drive into your system with the following features: VDI, dinamically allocated, 40GiB size, called disk3.
    b) Check that the new hard drive is  attached to SATA3 and that the "Hot-pluggable"  attribute has been checked.
4- Run lsscsi. Check that the new hard drive is listed in your system.
5-
Run  fdisk and:
     a) Create one single primary partition for the full size of the SATA3 hard drive.
     b) Change /dev/sdd1 partition type to 8e - Linux LVM.
6- Declare /dev/sdd1 as a LVM physical volume. Add /dev/sdd1 to the volume group vg3.
Show information about the LVM volume group. Read the following link: Adding Physical Volumes to a Volume Group
7- Extends lv3 to fill up the total size of vg3. Read the following link: 
Growing Logical Volumes (3rd example) . Check the new lv3 size.
8- Extend the filesystem installed on lv3. Read  Resizing an Ext4 filesystem or  Extending a Linux File System after Resizing the Volume (AWS). Check the new size of the filesystem installed on lv3.

9- Take the following screenshots:
   NOTE: Capture names start with asix1 or daw1 depending on what your group is.
    a) An screenshot after mounting lv3 in question 2. Run the following command: sudo df -Th -t ext4. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part3_cap1.jpg 
    b)
An screenshot after adding the new hard drive to SATA3Capture name: asix1/daw1_surname_name_m01tu1ex11b_part3_cap2.jpg
    c)
An screenshot after adding /dev/sdd1 to  vg3. Run the following command: sudo vgdisplay  /dev/vg3. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part3_cap3.jpg
    d)
An screenshot after extending lv3.
Run the following command:  sudo lvdisplay  /dev/vg3/lv3. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part3_cap4.jpg
   
e) An screenshot after extending the filesystem of lv3.
Run the following command: sudo df -Th - ext4. Capture name: asix1/daw1_surname_name_m01tu1ex11b_part3_cap5.jpg
10- Send your screenshots attached to an e-mail with the following specifications:
     a) E-mail address: cf(at)collados.org or jordi.binefa(at)fje.edu depending on who your teacher is.
     b
) Subject:  asix1_surname_name_m01tu01pr11b_part3 or
daw1_surname_name_m01tu01pr11b_part3 depending on what your group is.