Linux File System setup

Linux fstab setup

Published: Sunday, 1 July 2012

Mounting partitions

If you have unmounted partitions you can mount them by creating a directory as a mount point, then mounting the partition.

To mount /dev/sdb1 so it is accessible on /mnt/backup run

root@turtle:~# mkdir /mnt/backup
root@turtle:~# mount /dev/sdb1 /mnt/backup

This will not survive a restart.

fstab

The /etc/fstab file contains information about file systems that should be automatically mounted.

Each file system (think of these as partitions) are mounted in a directory. Any file that is created in that directory will be saved onto that file system.

e.g. if the contents of fstab is

/dev/sda1     /
/dev/sda2     /home

then files written to /home and any subdirectories will be created on /dev/sda2. All other files will be written to /dev/sda1.

When planning your mount points think about the size requirements of each directory.

UUID with blkid

With newer versions of fstab you can refer to disk drive partitions with a UUID instead of device name. blkid will list all the UUIDs. This is better than the /dev/sdaX device reference which can change when drives are added or removed, or internal cables are moved.

To update fstab:

1. Identify the partition UUID

root@turtle:~# blkid
/dev/sda1: UUID="746c7a5a-4960-4bf1-9403-b6875006d981" TYPE="ext2"
/dev/sda5: UUID="Kao8Us-6YUs-OFsA-BBH4-ION9-Nz6I-eY7LTI" TYPE="LVM2_member"
/dev/sdb1: UUID="049ba9c1-0ca0-48a2-9ef2-325ca1370623" TYPE="ext4"
/dev/sdb2: UUID="b01f3205-982d-4bc3-9f6b-86bba6e900d0" TYPE="swap"
/dev/sdb3: UUID="7f58fea9-8065-4a18-99cd-fc0396ad83cd" TYPE="ext4"
/dev/sdb4: UUID="5003da93-0229-4da0-b48e-52770b98c3ca" TYPE="ext4"
/dev/mapper/turtle-root: UUID="80b8e195-5990-4a85-8e7e-214b885b2a1d" TYPE="ext4"
/dev/mapper/turtle-swap_1: UUID="b2f330fb-e457-472f-afa0-ff80c698ad75" TYPE="swap"

Assuming we are after /dev/sdb1, then the UUID will be 049ba9c1-0ca0-48a2-9ef2-325ca1370623

2. Add it to fstab

Edit /etc/fstab and add a line with the UUID and mount point.

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=049ba9c1-0ca0-48a2-9ef2-325ca1370623 /mnt/backup1 ext4 defaults 0 0