Mount Filesystem Partitions in Arch Linux

Mount Filesystem Partitions in Arch Linux

On Arch Linux non-system partitions are not mounted automatically. Partitions have to be mounted in fstab or systemd mount scripts. Mounting in fstab is the more traditional method and is still used because of it’s simplicity and convenience. Mounts in fstab are converted to native systemd mounts so there is no major benefit to mount with systemd at this time. After the system partitions have been mounted you can install MHDDFS or another virtual pool volume.

 

Create Mount Points

Create a directory that will be used as a mount point for the physical storage device.

sudo mkdir /mnt/diskx

 

Set the mount point ownership to root user and group.

sudo chown root:root /mnt/diskx

 

Set the permissions on the mount points to allow root access only.

sudo chmod 700 /mnt/{disk1,disk2,disk3,disk4,disk5,disk6,disk7,disk8,disk9,disk10}

 

Set immutable flag on the mount point to prevent accidental changes to ownership or permissions.

sudo chattr +i /mnt/{disk1,disk2,disk3,disk4,disk5,disk6,disk7,disk8,disk9,disk10}

When set immutable flag will prevent changing permissions or ownership by anyone including root. The flag can be removed with -i option the same way it is added with +i option.

 

Check if immutable flag is set.

sudo lsattr /mnt

 

While setting the owner to root and setting immutable flag is optional it is recommended to prevent files being written to the underlying mount point instead of the mounted volume. This can cause confusion and data loss as well as issues other issues when for example the system drive fills up with data because the volume failed to mount.

 

Mount Partitions Manually

Mount a device manually.

sudo mount /dev/sd?1 /mnt/diskx

Mount command accepts a minimum of two options – the device followed by  the mount point. Device option can be omitted if it is mentioned in fstab or mtab. Partition can be mounted in read-only mode with -r option.

 

Unmount a device manually.

sudo umount /mnt/disk?

The only required option is the mount point that the device is mounted on. Multiple mount points can be specified with a space in between. To unmount only when disk operation are completed -l option can be used. To unmount forcibly regardless of any operations use -f option. All mounts in mtab can be unmounted with -a option.

 

Mount Partitions with fstab

Open the file systems table file.

sudo nano /etc/fstab

 

Add the mount commands at the end of file replacing mount options as needed and save.

/dev/sdb1 /mnt/disk1 ext4 async,auto,exec,rw,nouser 0 2
UUID=3e6be9de-8139-11d1-9106-a43f08d823a6 /mnt/disk2 ext3 defaults,acl,nobootwait 0 2
LABEL=portable /mnt/portable ntfs-3g defaults,noauto,nofail 0 2

 

Mount everything listed in fstab.

sudo mount -a

 

Unmount everything listed in fstab.

sudo umount -a

 

Mount Partitions with Systemd

Create the mount.

sudo nano /etc/systemd/system/mnt-disk1.mount

 

Copy the script and save.

[Unit]
Description = Disk 1 mount

[Mount]
What = /dev/disk/by-label/diskx
Where = /mnt/diskx
Type = ext4
Options = defaults,nofail 0 2

[Install]
WantedBy = multi-user.target

 

Start the mount.

sudo systemctl start mnt-disk1.mount

 

Enable the mount to run on boot.

sudo systemctl enable mnt-disk1.mount

 

Mount Options

The mount command in fstab is a little different than the mount command entered in command line. In fstab a total of six parameters are specified in this order: [file_system] [mount_point] [type] [options] [dump] [pass]. Some are optional but it is good practice to provide default values for clarity if nothing else.

 

File System

File system argument can be specified in one of three methods. The most common way is to specify the name of the block special device like /dev/sda1. This method is however unreliable because there is no guarantee that the same physical device will be attached to the same block special device each time.

If you need to mount a specific physical device to a specific mount point you will need to use either UUID or Label. Mounting by UUID uses a practically unique partition identifier that can be used to identify the physical device, for instance UUID=3e6be9de-8139-11d1-9106-a43f08d823a6.

The only downside of UUID is it’s poor human readability. To solve this a Label can be used to identify the device in much the same way as with UUID but with an optional user-defined identifier, for example LABEL=disk1.

 

Mount Point

Mount point argument is simply the path of the directory where the device partition is to be mounted e.g. /mnt/disk1. It is also where the contents of that partition will be accessible by the user.

 

Type

Type argument is one of many supported file system types of the partition. ext4 file system is common in Linux environment.

 

Options

There are a lot of options that can be modified but most are rarely used or file system specific. They can also be omitted to use the default values. A few more common options are never the less worth being aware of. File system can be mounted in read-only mode with ro option or read-write mode with rw option. Set-user-identifier and set-group-identifier bits are allowed by suid option or disallowed by nosuid option. To permit access to device nodes use dev option and nodev to deny access. Use exec option to enable direct execution of binaries on the mounted filesystem and noexec to disable it. With auto option the device can be mounted at boot time or only explicitly after boot with noauto option. The user option permits non root users to mount the device and nouser denies it.

For quick setup default option can be used instead of passing all options individually. Default options are rw, suid, dev, exec, auto, nouser, async, relatime.

In addition to the default options there are a few other useful options. One of them is nobootwait option which prevents the system from failing to boot because one or more of the devices fail to mount due to any reason including being missing. Errors due to missing devices can be suppressed with nofail option which is useful for portable devices. Partitions can be ignored when mounting altogether with noauto option. For Advance Control List or acl is enabled by default for ext4 file systems on Ubuntu 14.04 or above. You may need to specify it explicitly for other file systems or older versions of Ubuntu or specify noacl to disable explicitly.

 

Dump

The fifth argument should be left at it’s default value of 0 in practically every case.

 

Pass

The sixth argument sets the priority with which the storage devices will be checked by fsck. The root file system should have a value of 1 while the rest of the devices should be set to 2. The default value of 0 is not recommended because it disables fsck scanning completely.

 

View Mount Points

List all mounts.

mount

 

List all mounts with disk space usage.

df -h

Display human readable units with -h option.

dom