Auto mount USB drives

Raspbian OS (Raspberry Pi) do not mount USB drives automatically out of the box.

I’m pretty annoyed by the lack of easy to use packages by 2021 and I still have to do it myself with the instructions here: https://github.com/avanc/mopidy-vintage/wiki/Automount-USB-sticks

These are cookbook instructions, but I’ll add some insights to what each component means so it’s easier to remember the steps.

At top level, to auto-detect and mount USB drives, we need the following components

  • udev: analogous to what happens behind device manager, it keeps track of and updates devices as they are connected and disconnected immediately. Need to register USB sticks by adding a event handler, which triggers a systemd service (see below)
  • systemd: analogous to Windows’ services. Need to register the service by stating what commands it will call on start (mostly mounting) and cleanup (mostly unmounting)
  • automount script: it’s a user defined script that abstracts most of the hard work detecting the partitions on the USB stick, assign the mount point names, and mount them
# Register udev event handler (rules)
# /etc/udev/rules.d/usbstick.rules

ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"

# It triggers a systemd call to "usbstick-handler@" service registered under /etc/systemd/system/
# Register systemd service
# /etc/systemd/system/usbstick-handler@.service
# (Note: instructions used /lib instead of /etc. It's better to add it as /etc as this is manually registered as user-defined service rather than from a package)

[Unit]
Description=Mount USB sticks
BindsTo=dev-%i.device
After=dev-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/automount %I
ExecStop=/usr/bin/pumount /dev/%I

# %I is the USB stick's device name under /dev, usually sda
# Abstracted the logic of determining the mount point name and mounting to 'automount' (see below)

Create the file /usr/local/bin/automount and give it execution permission: chmod +x /usr/local/bin/automount

#!/bin/bash

# $1 (first argument) is usually "sda" (supposedly USB stick device name) seen from %I in the systemd service commands
PART=$1

# Within the "sda" (USB stick device of interest), extract the partition labels (if applicable) from lsblk command. The first column (name) is dropped
FS_LABEL=`lsblk -o name,label | grep ${PART} | awk '{print $2}'`

# Decide the mount point name {partition label}_{partition name}
# e.g. MS-DOS_sda1
tokens=($FS_LABEL)
tokens+=($PART)
MOUNT_LABEL=$(IFS='_'; echo "${tokens[*]}")
# Using string array makes it easier to drop the prefix if there's no {partition label}
# Bash use IFS to specify separators for listing all elements of the array

# Suggestion: drop --sync for faster USB access (if you can umount properly)
/usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${MOUNT_LABEL}

This automount script is adapted from https://raspberrypi.stackexchange.com/questions/66169/auto-mount-usb-stick-on-plug-in-without-uuid with my improvements.

Loading

Get myself comfortable with Raspberry Pi

I2C is disabled by default. Use raspi-config to enable it. Editing config file /boot/config.txt directly might not work

Locale & Keyboard (105 keys) defaults to UK out of the box. Shift+3 “#” (hash) sign became “£” pound sign. Use raspi-config to change the keyboard.

It reads random garbage partitions for MFT assigned to FAT16 drives. Just use FAT32

USB drives does not automount by default. usbmount is messy as it creates dummy /media/usb[0-7] folders. Do this instead.

Loading

InfiniiMax AutoProbe 1 Caveats

For most mortal souls probing up to 12Ghz, Agilent’s integrated active probe system is called the the AutoProbe 1, which looks like this:

Regular full blown Windows-based Infiniium oscilloscopes takes any AutoProbe 1 probes (as long as the shape fits), but I noticed my DSO6104A (InfiniiVision 6000A series) do not take my 1152A (2.5Ghz) probes nor my fancy 1168A (10Ghz) and 1169A (12Ghz) probes.

Turns out the more compact, embedded (VxWorks) Agilent scopes that boots almost immediately. It’s called the InfiniiVision Series, which covers 1000 X-, 2000 X-, 3000A/T X-, 4000 X-, 6000 X-, 5000, 6000, and 7000 Series.

I’m not rich enough to get my hands on the X series, but I know from the architecture that 5000, 6000 and 7000 series are basically the same scope. 5000 and 6000 series looks almost identical while the 7000 series adds a giant screen and a slightly different keypad layout (the BNC ports do not align with the channel buttons and dials).

Turns out the datasheets shows two caveats:

  • 100Mhz model uses different hardware. They don’t take Autoprobe interface as there’s absolutely no reason why you need an active probe to get 100Mhz single ended. Agilent skipped the hardware for it (thus the autoprobe pins) altogether although they kept the recessed space reserved for Autoprobe so they don’t have to mold a different front bezel just for the 100Mhz models.
  • They basically take only Generation I AutoProbe I, namely the 1130 series
  • Gen 0 (not an official name) AutoProbe 1 does not work: 1152A (2.5Ghz single ended) for 54845A. These differential probes: 1153A, 1154A, 1155A, 1159A are also considered too old. They were intended to work with old Infiniiums such as 54845A
  • Gen 2 AutoProbe 1 (only 10Ghz 1168A/B and 12Ghz 1169A/B models) does not work. These embedded scopes usually max out at 1.5Ghz, with the exception that 6000X goes up to 6Ghz, which is still way below 10Ghz
  • N2800 series are Autoprobe I, but it’s Gen III (has a bigger butt extending away from the AutoProbe I hole), so it doesn’t work
  • The rest are Autoprobe II and III that’s beyond our mortal souls (and way out of the league of InfiniiVision scopes)
https://www.keysight.com/us/en/assets/7018-06782/data-sheets/5968-7141.pdf

Loading