Connect the External HDD: Ensure that your external HDD is connected to your Debian system.
Identify the Device: Use the lsblk
or fdisk -l
command to identify the device name of your external HDD. It will typically be something like /dev/sdX
, where X is a letter assigned to the drive.
lsblk
Partition the Drive with MBR: Use the fdisk
command to create an MBR partition on the external HDD.
sudo fdisk /dev/sdX
Once inside the fdisk program do the following:
Type o
and press Enter to create a new empty DOS partition table (MBR).
Type n
and press Enter to create a new partition.
Choose the default values for the start and end sectors to use the entire disk.
Type t
and press Enter to set the partition type. Choose 83
for Linux.
Type w
and press Enter to write the changes and exit.
Create the ext4 Filesystem: After creating the partition, use the mkfs.ext4
command to create an ext4 filesystem.
mkfs.ext4 /dev/sdX1
Replace /dev/sdX1
with the actual partition identifier you created in the previous step.
Label the Filesystem (Optional): You can optionally label the ext4 filesystem for easier identification. Replace NEW_LABEL
with the desired label for your filesystem. That can for example be the model of the hard disk or it’s purpose.
e2label /dev/sdX1 NEW_LABEL
Mount the Filesystem: Create a directory where you want to mount the hard disk and mount the filesystem.
It would be a good idea to create the folder using the same name as the label of the hard disk’s partition.
sudo mkdir /media/LABEL sudo mount /dev/sdX1 /media/LABEL
Adjust the mount point (/media/LABEL
) according to your preference.
Now, your external HDD should be formatted with MBR and have an ext4 filesystem. If you want the drive to be automatically mounted on boot, you may need to add an entry to the /etc/fstab
file which is show below.
Automounting disk with fstab
Identify the UUID of the Partition: Use the blkid
command to identify the UUID of the partition on your external HDD. The UUID uniquely identifies the partition, and using it in /etc/fstab
helps avoid issues if the disk order changes.
Replace /dev/sdX1
with the actual partition identifier.
sudo blkid /dev/sdX1
Take note of the PTUUID number without quotes. It should look something like this: “c381c2aa-044b-415a-b901-2a6a374b2591“.
Edit the /etc/fstab
file: Open the /etc/fstab
file in a text editor using a command like sudo nano
or sudo vim
. Add a new line with the following information:
UUID=your_partition_uuid /media/LABEL ext4 defaults 0 2
Replace your_partition_uuid
with the UUID you obtained in the first step, and adjust the mount point (/media/LABEL
) if needed.Example using nano
:
sudo nano /etc/fstab
Add the line to automount the disk with default values:
UUID=c381c2aa-044b-415a-b901-2a6a374b2591 /media/LABEL ext4 defaults 0 2
Or with more specific options:
UUID=c381c2aa-044b-415a-b901-2a6a374b2591 /media/LABEL ext4 rw,relatime,nofail,errors=remount-ro 0 2
rw
:- Stands for “read-write.”
- This option allows both read and write operations on the filesystem. It specifies that the filesystem should be mounted with read and write permissions.
relatime
:- This option stands for “relative atime.”
- With
relatime
, the access time of files is updated only if the current access time is earlier than the modification time or the inode creation time. It’s an optimization over the traditionalatime
update mechanism, helping to reduce write operations to the filesystem.
nofail
:- This option indicates that if the filesystem cannot be mounted, the failure should not be considered fatal to the system boot process. If the device is not present or there are issues with the filesystem, the system will continue booting without the specified filesystem being mounted.
errors=remount-ro
:- Specifies the action to be taken in case of errors on the filesystem.
- If errors are encountered, the filesystem will be remounted in read-only mode (
ro
). This is a safety measure to prevent further potential damage and data loss in case of filesystem errors.
0 2
:- These are the dump and pass fields, respectively.
- The
dump
field (0) indicates whether the filesystem should be backed up using thedump
command. A value of0
means no automatic backup. - The
pass
field (2) is used by thefsck
command to determine the order in which filesystems are checked at boot time. A value of2
typically means the filesystem will be checked after the root filesystem.
- The
- These are the dump and pass fields, respectively.
In summary, the options in your /etc/fstab
entry specify that the filesystem should be mounted with read-write permissions, use relative atime for optimization, not be considered critical for system boot (nofail
), remount in read-only mode in case of errors, and be checked after the root filesystem during the boot process.
Press Ctrl + X
to save, press Y
to confirm changes, and press Enter
to exit.
Create the Mount Point (if not already created): If you haven’t created the mount point earlier, create it using:
sudo mkdir /media/LABEL
Remember to create the folder with the name of the label of your hard drive for easy identification.
Mount All Filesystems in /etc/fstab
: To mount all filesystems listed in /etc/fstab
, you can use the following command:
sudo mount -a
To auto mount as a non root user
To automount a disk with specific user permissions using /etc/fstab
, you can utilize the user
and noauto
options along with the uid
, gid
, and umask
options.
- Determine the UID and GID of the user you want to mount the disk as. You can find this information by running the following commands:
id -u username
id -g username
- Determine the UUID of the disk you want to mount. You can find this information using the
blkid
command:
sudo blkid
- Edit the
/etc/fstab
file using a text editor:
UUID=your_disk_uuid /mnt/mount_point filesystem defaults,user,noauto,uid=your_user_id,gid=your_group_id,umask=022 0 0