M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Practical. Exercise 11: Working with File Systems 20-2-19

Practical Exercise 11:  Working with File Systems

GENERAL CONDITIONS
1- Deadline: 10-03-2019 . Please take note that  we will subtract one point to your final mark  for each day of delay. After 5 days, your maximum score will be 5 points.
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 who is your teacher
     b) File Name:

        b.1)
ASIX1 (Catalan): asix1_surname_name_m01tu01pr11.pdf
        b2.) DAW1 (English): daw1_surname_name_m01tu01pr11.pdf
        Please  take note that working with the tools provided by Debian is mandatory. Any report written with Microsoft Office will be returned to the student.

     c)
Subject:
         c.1)
ASIX1 (Catalan): asix1_surname_name_m01tu01pr11
         c.2)
DAW1 (English): daw1_surname_name_m01tu01pr11
 
        Please  take note that this subject format is mandatory. Any report with a wrong subject format  will be returned to the student.
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 ABOUT FILE SYSTEMS

1- Partitioning a secondary storage device (drive) : GParted, fdisk and gdisk

a)
You can create and manipulate partitions with the following secondary storage devices (or drives):
b) You can not create and manipulate partitions with any kind od optical storage device such as CD, DVD or Blu-rays.

c) Typical partition managers:
d) Working with fdisk:

e) Working with gdisk:

2- 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:

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


3.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
    * For CDROM/DVD --> iso9660
   
d) Typical devices:
    * For hard disks and USB drives --> sda1, sda2,........sdb1,.....
    * For CD/DVD --> sr0,sr1,.....
   
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  iso9660  /dev/sr0  /mnt/cdrom --> Attaching a ISO9660 filesystem build on /dev/sr0 to the /mnt/cdrom folder.

3.2- 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 /dev/sdb1 from the Linux directory structure


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

4- Some useful commands

4.1- Get the device block size: blockdev

a) Description: Whenever a new file or directory is created on a linux filesystem (ext4, ext3..), the system  allocates, (in other words, it  reserves), disk space to store such file or directory. The minimum amount of reserved space is called a block. The block size is set during when the command mksfs is run. The block size is a value between 1KiB and 64KiB. By default is 4KiB or 4096 bytes. In order to check the block size, you can run the command blockdev. Block size can different for each partition created on a hard disk (or any other storage device).

b) Synopsis:  blockdev  --getbsz  partition  where partition could be for instance /dev/sda1, /dev/sdc2,....

c) Exemple:
sudo   blockdev   --getbsz   /dev/sda1
4096 --> Block size = 4096 bytes.

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

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

4.4- 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

PRACTICAL EXERCISE


PART 1


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

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

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 extenden 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) 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
    d) Ext4
filesystem on the first primary partition of /dev/sdc
   
e) Swap filesystem on the third primary partition of /dev/sdc
    f)
NTFS filesystem on the first logical partition of /dev/sdc
    g) FAT32
filesystem on the second logical partition of /dev/sdc 

5.- Mount the following filesystems:
    a)
The NTFS file system installed on the first partition of  /dev/sdb on a new directory called /mnt/disk2/ntfs.
    b)
The Ext4 file system installed on the second partition of  /dev/sdb on a new directory called /mnt/disk2/ext4.
    c
) The Ext4 file system installed on the first partition of  /dev/sdc on a new directory called /mnt/disk3/ext4.
    d) The NTFS file system installed on the first logical partition of  /dev/sdc on a new directory called /mnt/disk3/ntfs.
    e)
The FAT32 file system installed on the second logical partition of  /dev/sdc on a new directory called /mnt/disk3/fat32.

6- Enable the swap filesystem build on the third primary partition of /dev/sdb and the /dev/sdc.

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

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

9- Umount the filesysteme mounted in question 5. List again information about the mounted filesystem on your system.

10- Disable
the swap filesystem build on the third partition of /dev/sdb and /dev/sdc. Show again a list of enabled swap partitions, size, priority and used space.

PART 2

1- Mount /dev/sdb1 on /mnt/disk2 and  /dev/sdc1 on /mnt/disk3.

2- Show the block size of /dev/sdc1.


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

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

5- Show mounted filesystems and their disk usage with the help of MATE System Monitor.

PART 3

1- As your user by default, change to /mnt/disk3. Afterwards, open a new terminal and,  with root  privileges, try to unmount /mnt/disk3. Can you unmount it?.

2- Run as a root user the following command:  lsof /mnt/disk3. Why can not you unmount /mnt/disk3?

2- As your user by default, leave /mnt/disk3 and change to your personal folder.   Afterwards, open a new terminal and,  with root  privileges, try to unmount /mnt/disk3. Can you unmount it?. Why?.