Automount Partition

Overview

After booting up using an alternate partition I need to be able to access the partition that contains my latest files and information.

Since I don't want to have to mount manually each time I boot up I need to make an entry for the given partition in the "/etc/fstab" file so that it mounts automatically upon boot up.

Make a directory where we will mount the partition.

sudo mkdir /mnt/ubuntu20.04

This is in my /etc/fstab:

#
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>

UUID=f90fb201-6ba5-4bff-aad0-a127d20e1a63 /               ext4    errors=remount-ro 0       1
UUID=e9c9590f-c1f9-49f0-a83f-820c64728433 none            swap    sw                0       0

We want to append a line there for our as yet unmounted partition.

One that looks like this:

UUID=nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn /mnt/ubuntu20.04 ext4 errors=remount-ro 0 1

Find out the information we need.

sudo fdisk -l

output:

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x5f540829

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 156205055 156203008 74.5G 83 Linux
/dev/sda2 156205056 968665087 812460032 387.4G 83 Linux
/dev/sda3 968665088 976771071 8105984 3.9G 82 Linux swap / Solaris

We can see that the partition we want is the one at /dev/sda2. Discover the UUID of the partition we want to mount

sudo blkid

output:

/dev/sda1: UUID="f90fb201-6ba5-4bff-aad0-a127d20e1a63" TYPE="ext4" PARTUUID="5f540829-01"
/dev/sda2: UUID="8219c564-8865-44c8-a691-15faa4d3db4f" TYPE="ext4" PARTUUID="5f540829-02"
/dev/sda3: UUID="e9c9590f-c1f9-49f0-a83f-820c64728433" TYPE="swap" PARTUUID="5f540829-03"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"

So the line we need to append to /etc/fstab is this:

UUID="8219c564-8865-44c8-a691-15faa4d3db4f" /mnt/ubuntu20.04 ext4 errors=remount-ro 0 1

Append a comment line then our automount line to /etc/fstab.

Beware here, we are modifying an important file, don't damage the file and cause a boot up issue. Use your UUID not the one in echo example below.

echo '# Appended Automount partition at /mnt/ubuntu20.04' | sudo tee -a /etc/fstab`
echo 'UUID=8219c564-8865-44c8-a691-15faa4d3db4f /mnt/ubuntu20.04 ext4 errors=remount-ro 0 1' | sudo tee -a /etc/fstab

Double check:

cat /etc/fstab

# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
# / was on /dev/sdb1 during installation

output:

UUID=f90fb201-6ba5-4bff-aad0-a127d20e1a63 / ext4 errors=remount-ro 0 1
# swap was on /dev/sdb5 during installation
UUID=e9c9590f-c1f9-49f0-a83f-820c64728433 none swap sw 0 0
# Appended Automount partition at /mnt/ubuntu20.04
UUID=8219c564-8865-44c8-a691-15faa4d3db4f /mnt/ubuntu20.04 ext4 errors=remount-ro 0 1

Retrigger mounts.

sudo mount -a

OK Job is done. Make sure your mounts are ok before rebooting.

Published by Pierre Bernatchez in «troubleshoot». Key Words: disk, partition, id, mount, ext4