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

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.

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}
network:
    ethernets:
        eth0:
            dhcp4: true
            match:
                driver: bcmgenet smsc95xx lan78xx
            optional: true
            set-name: eth0
    version: 2

Append the following configurations to the file.

    wifis:
        wlan0:
            optional: true
            access-points:
                "MY_AP_NAME":
                    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 https://ubuntu.com/download/raspberry-pi. However, there is an easier way to creating the OS image. 

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

https://www.raspberrypi.org/blog/raspberry-pi-imager-imaging-utility/

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. 
















































Saturday, August 8, 2020

How to turn on dark mode in Windows 10

Dark mode is the latest UI design trend. Windows 10 also jumps on the bandwagon. It keeps light mode as the default. To enable dark mode, open Windows Settings. In the search box, type in "dark mode". Select "Turn on dark mode for apps".


In fact, there are 2 dark modes in Windows. One is for Windows Explorer, and the other for apps. 


Adjust them for your preference. One light one dark or both dark.


You may or may not see dark mode in apps or web sites. It depends on if they support it, 

 

Monday, July 20, 2020

How to use text reader in macOS

Sometimes you are tired of reading a long email or article, or maybe want to hear the message while doing something else. On macOS, you can configure accessibility features to do that. 

First, open System Preferences.
In System Preferences, select Speech, and then check "Speak selected text when the key is pressed". The default shortcut keys are Option+Esc. There are some voice options. Siri Female is probably the best.

Now remember the shortcut keys. Whenever you want the computer to read text for you, select the text and hit the shortcut keys.

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