Practice Exercise: Understanding Filesystems
Objectives
- Learn about filesystems and their importance in Linux.
- Explore different types of filesystems used in Linux.
- Understand how to check and manage filesystems.
Scenario
As a Linux enthusiast, you want to deepen your understanding of filesystems and how they play a crucial role in organizing and managing data on your Linux system. This exercise will help you gain insights into various filesystem types and how to interact with them.
Tasks
Task 1: Understanding Filesystems
- Begin by researching and making a list of at least five different filesystems commonly used in Linux.
- For each filesystem, note down its key features, advantages, and use cases.
Task 2: Checking the Current Filesystem
- Open a terminal on your Linux system.
- Use the
df
command to display information about the currently mounted filesystems. - Identify the root filesystem and note down its size, used space, and available space.
[intern@intern-a1t-inf-lnx1 ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 20568532 5187056 14316552 27% /
devtmpfs 480788 0 480788 0% /dev
tmpfs 484544 0 484544 0% /dev/shm
tmpfs 484544 6768 477776 2% /run
tmpfs 484544 0 484544 0% /sys/fs/cgroup
tmpfs 96908 0 96908 0% /run/user/1015
tmpfs 96908 0 96908 0% /run/user/1001
[intern@intern-a1t-inf-lnx1 ~]$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/root 20G 5.0G 14G 27% /
Task 3: Creating and Mounting a Filesystem
- Create a new ext4 filesystem on a spare storage device
/dev/sdb
. You can use themkfs.ext4
command. - Create a directory (e.g.,
/mnt/new_drive
) to mount your new filesystem. - For this task to be possible we'll be needing to add another disk to our instance and use it to create a new filesystem
- After adding another disk to the instance you can now run
mkfs.ext4
- Mount the new disk using
mount
- Confirm that it is now mounted using
df
[intern@intern-a1t-inf-lnx1 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk /
sdb 8:16 0 1G 0 disk
sdc 8:32 0 512M 0 disk
[intern@intern-a1t-inf-lnx1 ~]$ sudo mkfs.ext4 /dev/sdb
[sudo] password for intern:
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: e45a2d40-bf51-4794-ba15-483a4e61ec90
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[intern@intern-a1t-inf-lnx1 ~]$ sudo mkdir /mnt/new_drive
[intern@intern-a1t-inf-lnx1 ~]$ sudo mount /dev/sdb /mnt/new_drive
[intern@intern-a1t-inf-lnx1 ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 4096 0 4096 0% /dev
tmpfs 493376 0 493376 0% /dev/shm
tmpfs 197352 5412 191940 3% /run
/dev/sda 20568532 1244472 18259148 7% /
tmpfs 98672 0 98672 0% /run/user/1000
/dev/sdb 996780 24 927944 1% /mnt/new_drive
/dev/sdb
is now mounted in /mnt/new_drive
- Create a test file within your new filesystem:
[intern@intern-a1t-inf-lnx1 ~]$ touch /mnt/new_drive/testfile
[intern@intern-a1t-inf-lnx1 ~]$ ls -lrt /mnt/new_drive/
total 16
drwx------. 2 root root 16384 Oct 1 23:22 lost+found
-rw-r--r--. 1 root root 0 Oct 1 23:24 testfile
Task 4: Modifying Filesystem Properties
- Experiment with changing the properties of your mounted filesystem. You can try changing the filesystem label or resizing it (if it's on a loopback device).
[intern@intern-a1t-inf-lnx1 ~]$ sudo tune2fs -L "New Filesystem" /dev/sdb
[sudo] password for intern:
tune2fs 1.46.5 (30-Dec-2021)
[intern@intern-a1t-inf-lnx1 ~]$ sudo e2label /dev/sdb
New Filesystem
Task 5: Unmounting and Removing a Filesystem
- Unmount the filesystem you created in Task 3 using the
umount
command. - Verify that the filesystem is no longer mounted using
df
. - If it was a loopback device, you can remove it using the
losetup -d
command.[intern@intern-a1t-inf-lnx1 ~]$ sudo umount /mnt/new_drive
- Run
df
to see if it was properly unmounted[intern@intern-a1t-inf-lnx1 ~]$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 4096 0 4096 0% /dev tmpfs 493376 0 493376 0% /dev/shm tmpfs 197352 5412 191940 3% /run /dev/sda 20568532 1244484 18259136 7% / tmpfs 98672 0 98672 0% /run/user/1000
- Check the test file you've created. Now that you have unmounted the filesystem, it should be gone, unless the filesystem will be remounted:
[intern@intern-a1t-inf-lnx1 ~]$ ls -l /mnt/new_drive/ total 0
Task 6: Checking and Repairing Filesystems
- Use the
fsck
command to check the integrity of a filesystem (e.g.,fsck /dev/sdb
where/dev/sdb
is your filesystem device). - Make sure that the device you are trying to check is unmounted
[intern@intern-a1t-inf-lnx1 ~]$ sudo fsck /dev/sdb fsck from util-linux 2.37.4
- No meaningful output here since the filesystem is healthy and there's nothing to be repaired
Conclusion
By completing this exercise, you've gained valuable insights into Linux filesystems, including their types, creation, modification, and maintenance. Understanding filesystems is crucial for managing data effectively on your Linux system.