Linux 101 : An overview of the Linux filesystem (mkfs, mkswap, fstab, lsblk, df,...).



The filesystem is a structure that helps an operating system to manage files on partitions.
To be able to use a partition, Linux needs to have a filesystem on it.
Linux supports a number of filesystems ext2, ext3 and ext4 for example.
It supports other filesystems like the below:

  • ReiserFS
  • JFS
  • ZFS
Creating a filesystem:


The filesystem manages the data on the disk.
To create a filesystem on a partition, we use:


Example:


We could also use mkfs.ext3 to create an ext3 filesystem on /dev/sda1 partition:


To display the list of commands that create different types of filesystems (ext2,ext3,...), we use:


Mounting partitions:

To be able to use the filesystem created on a partition we need to mount it on a mountpoint :


The mount_point is a directory to which we attach a partition, it provides an entry point to the filesystem that lives on that partition.

Example:

The "/mnt" directory has to exist on the system.

To list all the physical and virtual filesystems on a system
, we use: 


Displaying partitions and their used space:

We can use the below command to check all the partitions and its used space:


Persisting between reboots (mounted partitions):

To persist between reboots, we add the partition we need to mount in the "/etc/fstab" file.


Mount optionsin the "/etc/fstab" file:
  • auto: the partition will be mounted automatically
  • noauto:the partition will not be mounted automatically
  • user: permits any user to mount the filesystem
  • noexec: prevents the execution of programs on the filesystem
Pass: 

0: the kernel doesn't check the partition.
1: the partition is checked first by the kernel. 
2: partition is checked after the one partition"tagged" with "1" i               checked. 

Dump:

0 : the file system is not backed up by the dump utility
1 : file system is backed up by the dump utility.

Listing of the disks UUIDs:

A UUID is an identifier Linux uses to "tag" disk partitions. We can use the below command to display all the UUIDs on a system:


Partition labels:

To add a label to a partition (like the with "opt" tag in the "fstab" file above), we use for example:


"/dev/sda1" is the device and "opt" is its label.

Unmounting a mounted device:

To unmount a device, we use:


We could also use the below command:



Remark:

If a user or a process is using a file on that partition, we will not be able to unmount it, and we will receive "device busy" message.

Creating a swap partition:

A swap partition is a regular disk partition that the system will use as a substitute for  the "RAM" when the "RAM" on the system is full.
We can create a swap partition using the partition "sdb2" for example, using the below command:


To enable the swap partition, we use:


To check the swap partition we use:


Comments

Leave as a comment:

Archive