How to update fstab file with UUID?

16,150
UUID="14314872-abd5-24e7-a850-db36fab2c6a1" /lpo/sda ext4 defaults,noatime 0 0
UUID="6d439357-3d20-48de-9973-3afb2a325eee" /lpo/sdb ext4 defaults,noatime 0 0

The format of entries in fstab are as follows:

<file system>   <dir>   <type>  <options>   <dump>  <pass>

Where <file system> is the device you want to mount (such as /dev/sdb and <dir> is the path to where the device should be mounted (/lpo/sda in your case).

There are multiple ways you can specify <file system>, the simplest being the path to the file system device in question /dev/sdb in your case (although typically they point to a partition on a drive rather than the drive, such as /dev/sdb1 but it appears that your drives lack a partition table and simply have the filesystem on the main device). But you can also use the device UUID or PARTUUID by specifying it as a key/value pair UUID="14314872-abd5-24e7-a850-db36fab2c6a1" inplace of /dev/sdb.

The main reason to use UUID or PARTUUID instead of device paths is that they are more consistent when changing the physical disks. The devices are numbered according to how they are presented to the OS by the bios (which is normally ordered by the socket they are plugged into). This means that if you add in a new device or physically rearrange existing devices they will be renumbered and what was /dev/sdb before might not be now. As you can imagine this will result in the wrong disk being mounted to the wrong location. UUID and PARTUUID are ids that are written as part of formatting the filesystem for UUID or at the time of creating the partition in the case of PARTUUID. These numbers are written to the disk and will always remain the same so can be used to mount the correct disk even when the underlying device file gets renumbered.

Side note: Your devices are a bit confusing - you have /dev/sdb mounted to /lpo/sda - while that works it can be confusing and lead to errors when you maintain/configuring your system, you may want to make these more consistent.

Share:
16,150

Related videos on Youtube

yael
Author by

yael

Updated on September 18, 2022

Comments

  • yael
    yael over 1 year

    The following lines are defined in my /etc/fstab file.

    My current fstab:

    /dev/sdb /lpo/sda ext4 defaults,noatime 0 0
    /dev/sdc /lpo/sdb ext4 defaults,noatime 0 0
    

    From blkid we get:

    /dev/sdb: UUID="14314872-abd5-24e7-a850-db36fab2c6a1" TYPE="ext4"
    /dev/sdc: UUID="6d439357-3d20-48de-9973-3afb2a325eee" TYPE="ext4"
    

    How to update my current fstab (the two lines) to use the UUID?

    For example, if I create the following line (according to the man page) for /dev/sdb, is it correct?

    UUID="14314872-abd5-24e7-a850-db36fab2c6a1"  /dev/sdb ext4 defaults,noatime 0 0
    
  • yael
    yael over 6 years
    ok so when need to use the UUID instead the default conf ?
  • Michael Daffin
    Michael Daffin over 6 years
    @yael Basically for consistency when the you add or remove disks - I have updated my answer with more details.