Monday, November 30, 2020

How to automount an external drive in Ubuntu Server 20.10

The following steps have been tested on Raspberry Pi 3.

After plugging in an external hard drive, use the following command to check the status of drive

sudo lshw -C disk

It show vendor, product name and other information. 

  *-disk                    
       description: SCSI Disk
       product: GoFlex Desk
       vendor: Seagate
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       version: 0D19
       serial: XXXXXXXX
       size: 2794GiB (3TB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 logicalsectorsize=4096 sectorsize=4096 signature=4540ecae

Where /dev/sda is the logical name of the drive. To see the partitions of the drive, use the follow command.

sudo fdisk -l

 It shows all partitions in the current system. We are only interested in Disk /dev/sda.

Disk /dev/sda: 2.73 TiB, 3000592977920 bytes, 732566645 sectors
Disk model: GoFlex Desk     
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xXXXXXXXX

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1        2048 732565503 732563456  2.7T  7 HPFS/NTFS/exFAT

The output shows there is only one partition /dev/sda1 in the drive. Say if the partition is to be mounted at /media/hd3tb, The directory should be created first. 

sudo mkdir /media/hd3tb

Then it can be mounted with the following command. Ubuntu 20.10 has Linux 5.7 which has native support of exFAT file system. If the partition is formatted as exFAT, the command should work fine. 

sudo mount /dev/sda1 /media/hd3tb

After the mount the files in the drive should be accessible. However, it is temporary. If the system reboots, it has to be mounted again. The file /etc/fstab can be configured to mount a partition automatically at startup. The configuration required the partition's UUID, which can be found with the following command.

sudo blkid

The output lists partitions' UUID.

/dev/mmcblk0p1: LABEL_FATBOOT="system-boot" LABEL="system-boot" UUID="2EC5-A982" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="254a9658-01"
/dev/mmcblk0p2: LABEL="writable" UUID="c21fdada-1423-4a06-be66-0b9c02860d1d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="254a9658-02"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/sda1: LABEL="FreeAgent3G" UUID="000D-E638" BLOCK_SIZE="4096" TYPE="exfat"

Using the UUID to create a new entry in /etc/fstab, and then is followed by mount point, file system type, and then read, write and user configurations. To make the drive accessible to everyone, append the line to /etc/fstab. 

UUID=000D-E638  /media/hd3tb  exfat  user,auto,fmask=0111,dmask=0000  0  2

Now every time the system reboots and the external drive will be mounted automatically.

No comments:

Post a Comment

How to make external drives spin down automatically on Ubuntu 20.10

 The following steps have been tested on Raspberry Pi 3. When using Raspberry Pi as a file server, it would save energy and extend an extern...