Header Ads

Breaking News

File systems and UUIDs on Linux


The /etc/fstab file is a very important file on Linux systems. It contains information that allows the system to connect to disk partitions and determine where they should be mounted in the file system. While this file has played an important role over the years, its format has changed with the introduction of UUIDs and, on some systems, a more reliable file-system type.

Here’s an example of an /etc/fstab file on a Fedora system:

$ cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar 12 12:26:55 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=a9e33237-9114-44ae-afd5-8ddb231d301f /             btrfs   subvol=root     0 0
UUID=15f42905-5897-4804-9c51-e6d5e169e6c2 /boot         ext4    defaults        1 2
#UUID=a9e33237-9114-44ae-afd5-8ddb231d301f /home        btrfs   subvol=home     0 0
UUID=d867ced1-8d81-47c6-b299-3365ba8a02de /home         ext4    defaults

Each line in the file (other than the comments) represents a file system and has six fields.

  1. describes the disk partition (more on the UUIDs below)
  2. identifies the mount point
  3. shows the file system type (could be ext4, xfs, btrfs, f2fs, vfat, ntfs, hfsplus, tmpfs, sysfs, proc, iso9660, udf, squashfs, nfs, cifs or something else)
  4. provides mount options
  5. determines if the file system might be dumped (0 = not) using the dump command (not often used)
  6. determines if file-system checking should be done at boot time (0 = not)

The btrfs file system is a modern copy-on-write (CoW) filesystem for Linux that provides advanced features while also focusing on fault tolerance, repair and easy administration.

The /etc/fstab file shown above is unusual in that a new OS was just recently installed on /dev/sda and the /home folder from the system before the upgrade (on a separate disk) was then remounted after the first reference to /home was commented out.

What are UUIDs?

Those lengthy device identifiers that you see in /etc/fstab that are labeled UUID (universally unique identifier) are 128 bit (32 hex characters) long and arranged in an 8-4-4-4-12 character sequence. One way to view how the UUIDs connect with the device names (e.g., /dev/sda1) is to use the blkid command.

$ sudo blkid
/dev/sda1: UUID="15f42905-5897-4804-9c51-e6d5e169e6c2" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="01a5b4ea-01"
/dev/sda2: LABEL="fedora_localhost-live" UUID="a9e33237-9114-44ae-afd5-8ddb231d301f" UUID_SUB="25ba7101-46bd-4eb8-87d4-91b404f93a4c" BLOCK_SIZE="4096" TYPE="btrfs" PARTUUID="01a5b4ea-02"
/dev/sdb1: UUID="d867ced1-8d81-47c6-b299-3365ba8a02de" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="drive2" PARTUUID="5cf63888-8b4a-4d13-8453-4eb3a87c3e09"
/dev/zram0: UUID="3b156a62-8b04-4725-b5ea-f0d817ff4109" TYPE="swap"
/dev/sdc1: UUID="76E8-CACF" BLOCK_SIZE="512" TYPE="exfat" PARTUUID="fa2cb833-01"

You can also check out the by-uuid file to view the relationships:

$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root 10 Mar 12 13:46 15f42905-5897-4804-9c51-e6d5e169e6c2 -> ../../sda1
lrwxrwxrwx. 1 root root 10 Mar 14 11:52 76E8-CACF -> ../../sdc1
lrwxrwxrwx. 1 root root 10 Mar 12 13:46 a9e33237-9114-44ae-afd5-8ddb231d301f -> ../../sda2
lrwxrwxrwx. 1 root root 10 Mar 12 13:46 d867ced1-8d81-47c6-b299-3365ba8a02de -> ../../sdb1

The 76E8-CACF device mounted as /dev/sdc1 is a USB drive that is temporarily in use.

You can get a feel for how Linux generates UUIDs by running uuidgen yourself. Check if it’s on your system by typing “which uuidgen”. These identifiers are for all practical purposes unique. When you enter the uuidgen command, you will get any of more than 3.40 × 1038 possible responses.

$ uuidgen
8e487c4e-6ec6-4c27-95c4-11ed8c3a9bbf
$ uuidgen
57f5c0e1-fb6c-43cb-a909-89fcd682939c

Using lsblk

Another convenient way to view file systems is with the lsblk command that provides a clear view of how file systems are related along with mount points, device sizes and major/minor device numbers. This command makes the partitions on each drive easy to visualize.

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 111.8G  0 disk
├─sda1   8:1    0     1G  0 part /boot
└─sda2   8:2    0 110.8G  0 part /
sdb      8:16   0 465.8G  0 disk
└─sdb1   8:17   0   434G  0 part /home
sdc      8:32   1   1.9T  0 disk
└─sdc1   8:33   1   1.9T  0 part /run/media/shs/76E8-CACF
sr0     11:0    1  1024M  0 rom
zram0  252:0    0   2.9G  0 disk [SWAP]

Wrap-Up

Linux systems provide a number of ways to view file systems. A few commands can help you understand the /etc/fstab file and the connections between disk partitions, file systems and UUIDs.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2021 IDG Communications, Inc.

Source Link

No comments