M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Practical. Exercise 11: Working with File Systems. Working with Logical Volumes (LVM) 22-2-21

Practical Exercise 11:  Working with File Systems. Working with Logical Volumes (LVM)

GENERAL CONDITIONS

1- Deadline: 14-3-2021.
2- Send your report as a PDF file 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 is your teacher
     b) File Name:

        b.1)
ASIX1 (English): asix1_surname_name_m01tu01pr11.pdf and asix1_surname_name_m01tu01pr11.odt
        b2.) DAW1 (English): daw1_surname_name_m01tu01pr11.pdf and daw1_surname_name_m01tu01pr11.odt   
     c)
Subject:
        
c.1) ASIX1 (Engish): asix1_surname_name_m01tu01pr11
         c.2)
DAW1 (English): daw1_surname_name_m01tu01pr11
3- Make this report individually.
4- Left, right, top and bottom margins: 2cm.
5- Character format: a) Font: Arial, b) Size: 10, c) Questions typeface: Bold, d) Answers typeface: Regular


DOCUMENTATION


1- Basic ideas about filesystems

a) A secondary storage device is a non-volatile (data stored is not lost when the computer is swtiched off)  and long-term (years or decades) storage device.  There are three main types of secondary storage devicess:

b) Before you can work with any Solid State or Magnetic secondary storage device you have to do the following steps:


c)
Before you can work with any Optical secondary storage device you have to do the following steps:

d) Command-line tools to work with  partitions and filesystems:  fdisk, gdisk, mkfs, mount, umount, mkswap, swapon and swapoff.



2- Basic ideas about LVM

a) Concepts:

b) Some Advantges:

c) Definitions:

d) Command-line tools to work with  LVMpartitions and filesystems:

e) Steps required to configure and remove LVM:


3- Partitioning a Solid State or Electromecanical secondary storage device with command-line tools: fdisk and gdisk

a) Typical command-line (CLI) partition tools:
b) Working with fdisk:

c) Working with gdisk:

4- Building (or installing) a filesystem on a hard disk partition: Gparted, mkfs and mkswap

a) Typical programs and command to build filesystems:
b) Working with mkfs:
c) Working with mkswap:

5- Mounting and unmounting a filesystem found on a hard disk partition or. Enabling a disabling a SWAP partition


5.1- Working with mount


a) Description: The mount command serves to attach the filesystem found on some device to the Linux directory structure.

b) Synopsis:  mount  -t  filesystem  device  mountpoint
   
c) Typical filesystems:
    * For Windows --> vfat (fat32), ntfs
    * For Linux Linux --> ext2, ext3 and ext4
       
d) Typical devices:
    * For hard disks and USB drives --> sda1, sda2,........sdb1,.....
     
e) Typical mountpoints:
    *  Any folder in /media
    * Any folder in /mnt

f) Examples:
   * Example 1:   mount  -t  vfat  /dev/sdb1  /media/usb  --> Attaching a FAT32 filesystem build on /dev/sdb1 to the /media/usb folder. 
  
* Example 2:   mount  -t  ext4  /dev/sdc2  /mnt/disk  --> Attaching a Ext4 filesystem build on /dev/sdc2 to  /mnt/disk folder. 


5.2- Setting permissions
5.3- Working with umount

a) Description: The umount command detaches a filesystem from the Linux directory structure.

b) Synopsis 1:  umount  device

c)
Synopsis 2:  umount  mountpoint
 

d) Examples
    * Example 1:   umount  /dev/sdb1 --> Detach /dev/sdb1 from the Linux directory structure
    * Example 2:   umount  /media/usb --> Detach a filesystem on /media/usb from the Linux directory structure


5.4- Working with swapon and swapoff

a) Description: The swapon command enables a SWAP partition  or show a list of enabled swap partitions. The swapoff command disables a SWAP partition.

b) Synopsis 1: swaponswapon  device  --> Enables a SWAP partition

c)
Synopsis 2: swaponswapon  -s --> Show a list of enabled SWAP partition

d)
Synopsis 3: swapoff:  swapoff  device --> Disables a SWAP partition
 

e) Examples
    * Example 1:   swapon  /dev/sdb1 --> Enable the SWAP filesystem build on  /dev/sdb1.
    * Example 2:   swapoff /dev/sdb1 --> Disable the SWAP filesystem build on  /dev/sdb1.
    * Example 3:   swapon -s  --> Show a list of enabled swap partitions, size, priority and used space.


6- Working with Logical Volumes

6.1- Declaring physical volumes

a) To declare the /dev/sda1 as a physical volume available for the LVM:   sudo  pvcreate  /dev/sda1
b)
In order to remove LVM labels from  /dev/sda1 so it will no longer recognized as a physical volume: sudo  pvremove  /dev/sda1  
c)
To check a physycal volume: sudo  pvdisplay  /dev/sda1

6.2- Creating volume groups

a) To create a volume group called vg1 made of  /dev/sda1 and sdb1:   sudo  vgcreate  vg1  /dev/sda1  /dev/sdb1
b)
In order to remove /dev/sda1 from the volume group vg1: sudo  vgreduce  vg1  /dev/sda1
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

6.3.- Creating logical volume

a) To create a logical volume called logvol1 in a volume group called vg1 that fills up its total size:   sudo  lvcreate  -n  logvol1  /dev/vg1  --extents   100%VG
b)
In order to remove a logical volume called logvol1 from a volume group called vg1: sudo  lvremove  /dev/vg1/logvol1
c)
To check a logical volume
called logvol1 in a volume group called vg1: sudo  lvdisplay  /dev/vg1/logvol1

6.4.- 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

6.5.- 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


7- Some extra useful commands

7.1- Show the disk usage of files and folders: du

a) Description: Shows the real disk usage of a file or directory. In other words, the disk space allocated to store such file or directory. Works recursively for directories. By default, du  displays the number of 1K-blocks allocated by the system to a file or directory. 

b) Important: Be careful, because file size and disk usage could be diferent. For instance, if you are working with a partition where a block size equal to 4096 was set and you have created a file whose size is 7432 bytes, the command du will show a disk usage of 8 (8KiB or 8192 bytes).

c) Useful options:
    -s --> Summarize: Display only a total. Particularly interesting for directories.
    -h --> Human readable: Print sizes in human readable format (K,M,G..)

d) Examples:
    *  du  -h /etc/passwd  -->  Show disk usage of  /etc/passwd  in a human readable format.
    *  du  -sh  /etc  --> Show the  summarized disk usage of /etc in a human readable format.
   
7.2- Show the disk usage of files and folders (user-friendly): ncdu

a) Description: It is a curses-based, fast and user-friendly version of du. It is a really useful and poweful command. It analyses any directory on your system and you can easily navigate from one directory to another directory using the arrow keys.

b) Important: In order to install ncdu run  aptitude install ncdu as the root user.

c) Examples:
    * ncdu  /home  --> Analyse and show information about the /home directory.
    * ncdu / -->  Analyse and show information about the / directory.

d) Use the arrow keys to navigate, press ? for help and q to quit.

7.3- Display a detailed report for each mounted file system: df

a) Description: The df  command allows you to display a detailed report on the disk space usage for each mounted filesystem. The command displays the filesystem name, filesystem type, size, how much space is used, how much space is still available, the percentage of space usage, and where is the file system mounted.

b) Useful options:
    -T --> Print filesystem type (ext4, vfat,...)
    -h --> Human readable: Print sizes in human readable format (K,M,G..)

c) Examples: df  -Th

7.4- Checking filesystems: lsblk -f

a) Description: The lsblk -f command checks filesystem types built on partitions.

b) Examples:
     * Check filesystem install on partition /dev/sda1 -->  lsblk  -f  /dev/sda1
    * Check filesystem installed on any partition of /dev/sda -->  lsblk  -f  /dev/sda
     *
Check filesystem installed on any partition of any device --> lsblk -f


PRACTICAL EXERCISE


PART 1

0.- Before starting (do not take screenshots):
    a) With the exceptcion of debian10v5.vdi, remove attachments of any existent SATA hard drive attached to your virtual machine.
    b) Make sure that debian10v5.vdi is attached to SATA0.

1.- Shutdown your system. Create a new SATA hard drive with the following characteristics:
     a) Hard drive file type: VDI
     b) Dinamically allocated
     c) Name: disk01
     d) Size: 20GiB
     e) 
Attached to  SATA 1
   

2.-  Install lsscsi.
List SCSI/SATA device attached to your system.

3.- Run gdisk on /dev/sdb and:
    a
) Create a new  GPT partition table on the selected disk.
    b) Create a primary - 10GB - NTFS (Microsoft basic data).
    c)
Create a primary - 9GB - Linux  partition.
    d)
Create a primary - Free space left - Swap  partition
    e) Show the /dev/sdb partition table
information (partitions, size, number of blocks and supposedly installed file system type).

4- Build the following filesystems:

    a) NTFS filesystem on the first partition of /dev/sdb
    b) Ext4
filesystem on the second partition of /dev/sdb
    c) Swap
filesystem on the third primary partition of /dev/sdb

5.- Mount the following filesystems:
    a)
The NTFS file system installed on the first partition of  /dev/sdb on a new directory called /mnt/disk01/p1.
    b)
The Ext4 file system installed on the second partition of  /dev/sdb on a new directory called /mnt/disk01/p2. 

6.- Enable the swap filesystem built on the third primary partition of /dev/sdb.

7.- Do the following tasks:
    a) Add your default user to the group adm
    b) Change permissions of /mnt/disk01/p1 and /mnt/disk01/p2 to: owner rwx, group rwx and others ---
    c) Change group of
/mnt/disk01/p1 and /mnt/disk01/p2 to adm
    d) Check that as your default user you can create a folder called default on /mnt/disk01/p1 and /mnt/disk01/p2
    e) Become fje.
Check that as fje you can not create a folder called default on /mnt/disk01/p1 and /mnt/disk01/p2

8.- Umount  /mnt/disk01/p1. Check permissions and ownership. What happens?

9.- Mount again  /mnt/disk01/p1. Check permissions and ownership. What happens?


PART 2

1.- Shutdown your system. Create two new SATA hard diska with the following characteristics:
     
a) Hard drive file type: VDI
      b) Dinamically allocated
      c) Name: disk02
      d) Size: 20GiB
      e) 
Attached to  SATA 2

2.- 
List SCSI/SATA device attached to your system.

3.- Run  fdisk on /dev/sdc and:
   
a) Create a new  MBR (DOS) partition table on the selected disk.
    b) Create a primary / 10GB / Linux / Boot partition
    c)
Create an extended / 9GB partition
   
d) Create a primary / Free space left / Swap  partition
    e) Create a logical / 7GB / NTFS partition
    f
) Create a logical  / Free extendend partition space left / FAT32 partition   
    g) Show the /dev/sdc partition table information (
partitions, size, number of blocks and supposedly installed file system type).

4- Build the following filesystems:
    a) Ext4 filesystem on the first primary partition of /dev/sdc
   
b) Swap filesystem on the third primary partition of /dev/sdc
    c)
NTFS filesystem on the first logical partition of /dev/sdc
    d) FAT32
filesystem on the second logical partition of /dev/sdc 

5.- Mount the following filesystems:
    a
) The Ext4 file system installed on the first partition of  /dev/sdc on a new directory called /mnt/disk02/p1.
    b) The NTFS file system installed on the first logical partition of  /dev/sdc on a new directory called /mnt/disk02/p2.
    c)
The FAT32 file system installed on the second logical partition of  /dev/sdc on a new directory called /mnt/disk02/p3.

6- Enable the swap filesystem built on the third primary partition of  /dev/sdc.


PART 3

1.- Display a detailed report on the disk space usage for each mounted filesystem.

2.- Check filesystems built on /dev/sdb and /dev/sdc.

3.-  Show a list of enabled swap partitions, size, priority and used space.

4.- Show the summarized disk usage of /var,  /home and /etc in a human readable format.

5.- Show the total,  /var and /var/log disk usages with the help of ncdu.



PART 4

1.- Umount:  /mnt/disk01/p1, /mnt/disk02/p2, /mnt/disk02/p1, /mnt/disk02/p2 and /mnt/disk02/p3

2.- Disable the swap filesystem built on /dev/sdb3 and /dev/sdc3

3.- Display a detailed report on the disk space usage for each mounted filesystem. Check that filesystems have been unmounted.

4.-  Show a list of enabled swap partitions, size, priority and used space. Check that swap filesystems have been disabled.


PART 5


1- Install and start lvm2 on your system. Run the following command: sudo aptitude install lvm2

2-
Run  fdisk and:
     a) Remove any partition created on /dev/sdb1 and /dev/sdc1
     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.


3.-
Declare /dev/sdb1 and /dev/sdc1 as LVM physical volumes. Show information about LVM physical volumes declared on your system.

4.-
Create a volume group called vg5 made of  /dev/sdb1 and /dev/sdc1. Show information about vg5.

5.-
Create a logical volume called lv5 that fills up the total size of vg5. Check that lv5 has been properly created.

6.-
Install an ext4 filesystem on lv5
Check the logical volum filesystem.    

7.-
Mount lv5 on /mnt/lv5.
Check that lv5 has been properly mounted.

8.- Display a detailed report on the disk space usage for each mounted filesystem.


PART 6

1.- Umount /mnt/lv5. Check that lv5 has been properly and successfully umounted.

2.-  Remove lv5. Check that lv5 has been properly and successfully removed.

3.- Remove vg5. Check that vg5 has been properly and successfully removed.

4.- Remove  physical volumes declaration from /dev/sdb1 and /dev/sdc1. Show that physical volumes have been properly and successfully wiped.

5.-
Change /dev/sdb1 and /dev/sdc1  partition type to 83 - Linux. Check that que partitions types have been successfully changed.

6.-
Build a ext4 filesystem on /dev/sdb1 and /dev/sdc1. Check that the partitions filesystem have been successfully built.