Saturday, December 5, 2020

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 external drive's life if it spins down on idle. 

For example, if the drive is /dev/sda, use the command to see its hard drive configuration

sudo hdparm -I /dev/sda

Where advanced power management is default to 254. It means to no speed and no spinning down. Now do an experiment with the following commands. They set the advanced power management and spin down time.

sudo hdparm -B 60 /dev/sda
sudo hdparm -S 60 /dev/sda

Check if the external drive spins down after idling a while. Most of popular external hard drives should works with these commands. However, this is temporary. If the computer reboots, the settings are gone. They should be set in the configuration file /etc/hdparm.conf. Append the following lines to the file.

/dev/sda {
  apm = 60
  spindown_time = 60
}

Be careful if more drives are plugged in or USB ports are switched, The drive names sda, sdb or sdc could be switched also.

How to set up Samba on Ubuntu Server 20.10

 The following steps have been tested on Raspberry Pi 3.

Samba should be installed first. 

sudo apt update
sudo apt install samba

After the installation, run the command to check the status

sudo systemctl status smbd 

The status should be active (running). To manage Samba users, it's easier to create a user group. For example, use the group name smbgroup.

sudo addgroup smbgroup 

Next, create one or more users and add to the group. For example, the user name is smbuser. 

sudo adduser smbuser 

Add the user to the group

sudo usermod -aG smbgroup smbuser 

Samba manages a different set of passwords. To set the password to the user

sudo smbpasswd -a smbuser 

Now the user can be enabled to access Samba.

sudo smbpasswd -e smbuser 

The next step is to set up a shared directory. The Samba configuration file is /etc/samba/smb.conf. Open the file and append a section as below.

[HomeShare]
  path = /media/external_hd
  valid users = @smbgroup
  guest ok = no
  writable = yes
  browsable = yes

Where the share name is "HomeShare" and the shared directory is /media/external_hd. After the change is saved, run the following command to restart Samba service.

sudo service smbd restart 

The network share should be working. Find another computer in the network and try to access the network share "HomeShare".

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