Skip to content


How to add a new partition to the fstab file

Overview

This article will cover the scenario where we want to add new partitions to be mounted upon system start-up. The /etc/fstab [2] is the file that contains the necessary information for the operating system mount partitions at the system start-up.

The syntax of a fstab entry is described below :

[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]

Where:

  • Device – Device/partition (/dev location or UUID)
  • Mount Point – The directory on your root file system (mount point)
  • File System Type – Type of file system (ext4, ext3, ext2, jfs, reiserfs, vfat, and others)
  • Options – Device/partition ( Mount options for accessing the device/partition (see the man page for mount)
  • Dump – Used by the dump utility to decide when to make a backup. Default is 0
  • Pass – Used by fsck to decide which order filesystems are to be checked. Possible entries are 0, 1 and 2. The root file system should have the highest priority 1 – other file systems you want to have checked must have a 2 and they will be checked sequentially. File systems with a value 0 will not be checked by the fsck utility.

Configuration

By default Ubuntu uses UUID [1] to identify partitions. To list your partitions you must use the blkid command.

$ sudo blkid

You will find all the new disks found by the operation system. An example of the output can be seen below.

/dev/sda1: UUID="2746087f-0e00-4429-a2f6-1ddae8a56cc0" TYPE="ext4"
/dev/sda5: UUID="bf4200b2-b938-48a2-bf77-c5ec1f4d86a8" TYPE="swap"
/dev/sdb1: UUID="bf4200b2-b938-48a2-bf77-c5ec1f4d86b9" TYPE="ext4"

Once you know the UUID for the partition you want to configure in /etc/fstab you can proceed and create a mount point for the new partition. In this example we will be using /data. The mount point is the location where you will mount the new disk and/or partition

$ mkdir /data

Add the new partition to the /etc/fstab file

Before you edit system files, make a backup.

$ sudo cp /etc/fstab /etc/fstab.old

Add the following line to the /etc/fstab file.

# /data on /dev/sdb1
UUID=bf4200b2-b938-48a2-bf77-c5ec1f4d86b9	/data	ext4	errors=remount-ro	0	2

Save the file and then run mount in order to make the changes effective without booting the system.

$ sudo mount -a

To view the current partitions mounted, run:

$ sudo mount -v

fstab entries for other filesystems

NFS

nfs-server:/share /media/nfs-share	nfs4	_netdev,auto	0	0

SSHFS

sshfs#user@server:/share  fuse  user,allow_other  0  0

References

Posted in Knowledge Base.

Tagged with , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.