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. 

       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.

Sunday, November 29, 2020

How to configure WiFi for Ubuntu Server 20.10 on Raspberry Pi 3

First, examine network interfaces. On Raspberry Pi 3 Model B, it should have three.  

$ ls /sys/class/net

eth0  lo  wlan0

The interface eth0 is for Ethernet connection, and wlan0 is for WiFi.

The configuration of WiFi access points is in /etc/netplan/50-cloud-init.yaml. The default configuration is as below.

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
            dhcp4: true
                driver: bcmgenet smsc95xx lan78xx
            optional: true
            set-name: eth0
    version: 2

Append the following configurations to the file.

            optional: true
                    password: "MY_WIFI_PASSWORD"
            dhcp4: true

Where you need to replace MY_AP_NAME and MY_WIFI_PASSWORD. After modifying the configurations, use the command to apply the changes.

sudo netplan apply

Be careful about letter case of the access point name. To check if Raspberry Pi successfully connects to the WiFi, use the command line to list IP address for each network interface.

ip a
You should see wlan0 has an IP address assigned.

How to set up Ubuntu Server 20.10 on Raspberry Pi 3

There are many editions of Raspberry Pi and many versions of Ubuntu. This how-to is specifically for setting up Ubuntu 20.10 on Raspberry Pi 3.  

Ready hardware ready

  • Raspberry Pi 3 Model B
  • Micro USB 5V 3A power supply
  • 16GB Micro SD card

A good power supply is needed, otherwise Raspberry Pi will complain about under voltage, keep rebooting, or have no HDMI video output. The micro SD card storage can be more or less than 16GB. The OS will use about 4GB. Choose a size that is required for the purpose of the device.

Download and run the image tool

An OS image is required to boot up the device. Ubuntu has a download site for Raspberry Pi at However, there is an easier way to creating the OS image. 

Go to the web site to download and install Raspberry Pi Imager.

The tool lets you select an OS image available online and a destination SD card connected on your computer.

For this how-to, Ubuntu Server 20.10 (RPi 3/4/400) should be selected.

The tool detects SD cards connected on the local computer. It's better to remove other SDs if there is any. Since the card will be wiped out, be careful about your selection. After OS and card are selected, click WRITE button. The selected OS image will be downloaded and written to you SD card.

Boot up Raspberry Pi

After the OS image is ready, plug the SD card into Raspberry Pi and power on the device. It will take a few minutes to boot up. Once the startup is done, the screen will prompt you to log in. The default username is ubuntu and the password is ubuntu, too. You will need to reset the password at the first login. 

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...