Ubuntu 24.04 SDCard Auto mounting

Seems like the SD card is not auto mounting in 24.04 I want a way to persist some configs between firmware re-installs.

The tachyon sees the sd card just fine and I can manually mount it.

image

However the docs are saying it should mount on boot/insert and that is not happening.

my use case is to use the particle managed contianers to deploy a bunch of homelab stuff in a way that I don’t have to think as hard about it. Design it locally on my machine (or remote on the particle) make a blueprint and push. Its really slick! However with the 24.04 build (which has been mostly great!) having regular updates I want a way to re-install/persist my configs in a sane fashion. Todo this I wanted to mount the sdcard where applicable to the containers. Hence wanting this up on boot.

Hey @Geekbozu are you using a headless or desktop variant of Ubuntu?

If headless, you might have to let systemd mount it at boot via /etc/fstab

Hey @ericpietrowicz !

This is the headless variant of 24 I thought it was headless but that seems to not be an option. I believe when I was testing the headless variant of 20 the SD card auto mounts. however 20.XX does not have the wireguard modules setup so its not fit for my use case.

Sadly for the use case I'm interested in I would need to either update the overlay for the fstab or have another solution since my goal is to be able to update the firmware and have the SD card get mounted again afterwards with no intervention.

Id personally rather not have to build an image every release, much easier as a beta adopter to just run the setup and enjoy the freshly cooked goodness y'all are working on!

All that said part of why I'm being it up is the docs imply that it would automount. Which seems to not be the case on 24.04 yet and might be worth adding to the list of discrepancies.

The solution I have that's working for now is I cobbled together a docker container that abuses a privileged mode and nsenter to get access to the host and mount/modify fstab on boot, my deployed apps already need a check to make sure the sdcard is mounted so it naturally extends that process. I have this deployed with particle container/blueprints which means it just gets provisioned and finalizes the bootstrap process for me.

services:
  sdcard-mount:
    image: alpine:latest
    container_name: sdcard-mount
    privileged: true
    network_mode: host
    pid: host
    volumes:
      - /dev:/dev
      - /etc:/host_etc
      - /mnt:/mnt:shared
      - /proc:/host_proc
    command: >
      sh -c '
      echo "=== SD Card Auto-Mount Service ===";
      DEVICE="/dev/mmcblk1p1";
      MOUNT_POINT="/mnt/sdcard";
      
      ls -la $$DEVICE || exit 1;
      mkdir -p $$MOUNT_POINT;
      
      if mount | grep -q "$$DEVICE on $$MOUNT_POINT"; then
        echo "SD card already mounted at $$MOUNT_POINT";
      else
        echo "Mounting $$DEVICE to $$MOUNT_POINT...";
        mount $$DEVICE $$MOUNT_POINT && echo "Successfully mounted SD card" || exit 1;
      fi;
      
      if ! grep -q "$$DEVICE" /host_etc/fstab 2>/dev/null; then
        FSTYPE=$$(blkid -s TYPE -o value "$$DEVICE" 2>/dev/null || echo "auto");
        echo "$$DEVICE $$MOUNT_POINT $$FSTYPE defaults,nofail 0 2" >> /host_etc/fstab;
        echo "Added to fstab";
      fi;
      
      echo "SD card ready at $$MOUNT_POINT";
      
      while true; do
        if ! mount | grep -q "$$DEVICE on $$MOUNT_POINT"; then
          echo "WARNING: Mount lost, remounting...";
          mount $$DEVICE $$MOUNT_POINT && echo "Remounted successfully" || echo "Remount failed";
        fi;
        sleep 300;
      done
      '
    restart: unless-stopped

Its on my list to go see if the headless 20.XX version just has it in the default fstab overlay. Simple enough PR to add if it does just also unable to find anything clear about the older version (understandably)

Hey Geekbozu!

I took a look - indeed it's different from 20.04! I asked AI to make a summary if the findings below:

SD Card Auto-Mount Behavior Change: Ubuntu 20.04 vs 24.04

What Changed

On Ubuntu 20.04, SD cards would automatically mount at a predictable location
like /mnt/sdcard regardless of desktop session state.

On Ubuntu 24.04, SD card mounting is handled by udisks2 + GNOME gvfs, which:

  • Mounts to /media/<username>/<UUID-or-label> (e.g., /media/particle/4A21-0000)
  • Only auto-mounts when the desktop session is active (screen unlocked)
  • Does NOT auto-mount when screen is locked/idle (security feature)

Why This Happens

Ubuntu 24.04 uses a more "desktop-centric" approach to removable media:

  1. udisks2 detects the SD card and exposes it via D-Bus
  2. gvfs-udisks2-volume-monitor (running in user session) watches for new volumes
  3. GNOME Shell triggers the actual mount when should_automount=1
  4. BUT: GNOME checks IdleHint - if session is idle, it skips automount for security

This breaks headless/embedded use cases where you want the SD card mounted
regardless of whether someone is logged in or the screen is locked.

Solution: Systemd Service

Create a systemd service that mounts the SD card at boot, independent of the
desktop session. This restores the predictable 20.04 behavior.


/etc/systemd/system/sdcard-mount.service

[Unit]
Description=Mount SD Card at /mnt/sdcard
After=local-fs.target
Wants=local-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/bin/mkdir -p /mnt/sdcard
ExecStart=/bin/bash -c 'for i in 1 2 3 4 5; do [ -b /dev/mmcblk1p1 ] && break; sleep 1; done; mount -o uid=1000,gid=1000,dmask=0022,fmask=0022 /dev/mmcblk1p1 /mnt/sdcard || true'
ExecStop=/bin/umount /mnt/sdcard

[Install]
WantedBy=multi-user.target

Install the service

  sudo cp sdcard-mount.service /etc/systemd/system/
  sudo systemctl daemon-reload
  sudo systemctl enable sdcard-mount.service

Disable GNOME automount to prevent conflicts

  gsettings set org.gnome.desktop.media-handling automount false
  gsettings set org.gnome.desktop.media-handling automount-open false

Start immediately (or reboot)

  sudo systemctl start sdcard-mount.service

Verify

  mount | grep sdcard
  # /dev/mmcblk1p1 on /mnt/sdcard type exfat (rw,uid=1000,gid=1000,...)

What the Service Does

  • Waits up to 5 seconds for /dev/mmcblk1p1 to appear (handles slow card detection)
  • Creates /mnt/sdcard if it doesn't exist
  • Mounts with uid/gid 1000 (particle user) so apps can read/write without root
  • Runs at boot before user login, independent of desktop session
  • Gracefully handles missing SD card (won't fail boot if no card inserted)

Hope this answers your question!

I'll update this in the docs - thanks again for writing in!

Nick

1 Like

It matches what I was expecting!
Thanks for getting it on the docs. Figured this is still the best place to throw feedback for the builds in some form!

2 Likes