1. Identify the Target Disk
Use the lsblk or fdisk utility to list available block devices and identify the correct drive identifier.
lsblk
# or
sudo fdisk -l
2. Create a Filesystem
If the disk is unformatted, create a new filesystem. The following example formats the partition /dev/sdc1 using the ext4 filesystem.
sudo mkfs.ext4 /dev/sdc1
3. Create a Mount Point
Create a directory to serve as the mount point for the new filesystem.
sudo mkdir -p /mnt/backup_drive
4. Retrieve the Partition UUID
Use the blkid command to find the Universally Unique Identifier (UUID) for the target partition. The UUID is preferred over device names for stability across reboots.
sudo blkid
Sample output:
/dev/sdc1: UUID="e8c7b2a4-1234-5678-90ab-cdef12345678" TYPE="ext4"
5. Configure Automatic Mounting
Edit the /etc/fstab file to define the persistent mount configuration.
sudo vim /etc/fstab
Add an entry using the retrieved UUID and the created mount point. The format is: <file system> <mount point> <type> <options> <dump> <pass>.
UUID=e8c7b2a4-1234-5678-90ab-cdef12345678 /mnt/backup_drive ext4 defaults 0 2
Field definitions:
- file system: The device identifier, typically the UUID.
- mount point: The directory where the device is attached.
- type: The filesystem type (e.g., ext4, xfs, ntfs).
- options: Mount options such as
defaults, which includes settings likerw,suid, andexec. - dump: Determines if the filesystem needs to be backed up by the dump command; usually set to 0.
- pass: Controls the order of filesystem checks (fsck) at boot. The root filesystem should be 1, while other partitions are typically 2. Use 0 to disable checking.
6. Verify the Configuration
Before rebooting, verify the syntax of the fstab file to ensure the system will boot correctly.
sudo mount -a
If this command completes without errors, the drives are mounted successfully. If you encounter errors related to filesystem helpers (such as for NFS or CIFS), install the necessary utilities:
sudo apt-get install nfs-common