Automatically mount a drive using /etc/fstab

From PCLinuxOS Knowledgebase
Jump to navigation Jump to search

automatically mount a drive using `/etc/fstab`

To automatically mount a drive using `/etc/fstab`, you need to add an entry for it in the `/etc/fstab` file with the correct parameters. Here's how you can do it as the root user:

NOTE: All Commands are executed as the root user in a konsole window.


Step 1: Find the UUID or device path

1. Run the following command in a terminal window to get the UUID of the drive:

  blkid

  Look for the UUID of the partition you want to mount (e.g., `/dev/sda1`).


Step 2: Create a mount point

Decide where you want to mount the drive (e.g., `/mnt/mydrive`) and create that directory if it doesn't already exist:

  mkdir -p /mnt/mydrive


Step 3: Edit `/etc/fstab`

1. Open the `/etc/fstab` file in a text editor with root privileges:

  nano /etc/fstab

2. Add a new line with the following format:

  UUID=<your-drive-uuid> /mnt/mydrive <filesystem-type> <options> 0 0

  - Replace <your-drive-uuid> with the UUID you found.
  - Replace <filesystem-type> with the file system type (e.g., ext4, ntfs, vfat).
  - <options> can be something like defaults or noatime. For NTFS, you might want ntfs-3g instead.

  Example:

  UUID=123e4567-e89b-12d3-a456-426614174000 /mnt/mydrive ext4 defaults 0 0

Step 4: Test the `/etc/fstab` Entry

You can test if the entry is correct by running:

  mount -a

If there are no errors, the drive should be mounted automatically at the specified mount point on the next reboot.