automatically mount USB drive on boot/power loss

I have been using my Dietpi box to host a samba shared drive so that I can easily access files from around the house, the only problem is that if I lose power when the pi and USB drive power back up they are no longer mounted which means I have to log into the dietpi box and manually mount them again using drive manager.

Is there a way to set the USB drive to automatically be assigned to a mount point? I’ve read some people use fstab to do this on linux, but when I run fstab in dietpi I get command not found error.

Hi,

fstab isn’t a command that can be xecuted. It’s a file containing mount information about drives to be mounted. It located at /etc/fstab

many thanks for your message. How do yoou mount your USB drive? do you use DietPi drive manager? Usually drive manager will set an option to mount the external drive as soon as someone is trying to access it.

Yes I am using drive manager each time I mount it, and then I have the mount point for it shared with Samba. I don’t see any options to set it to auto-mount after a power or connection loss.

can you share your /etc/fstab. Usually drive manager will set automatic mount automatically

cat /etc/fstab

So the shares show up just fine in fstab, but when I lose power they are gone. I want to try and set it up so that they are always there.

Please use “dietpi-drive_manager” to setup mounts

#----------------------------------------------------------------

NETWORK

#----------------------------------------------------------------


#----------------------------------------------------------------

TMPFS

#----------------------------------------------------------------
tmpfs /tmp tmpfs size=1938M,noatime,lazytime,nodev,nosuid,mode=1777
tmpfs /var/log tmpfs size=50M,noatime,lazytime,nodev,nosuid,mode=1777

#----------------------------------------------------------------

MISC: ecryptfs, vboxsf (VirtualBox shared folder), gluster, bind mounts

#----------------------------------------------------------------


#----------------------------------------------------------------

SWAPFILE

#----------------------------------------------------------------


#----------------------------------------------------------------

PHYSICAL DRIVES

#----------------------------------------------------------------
PARTUUID=907af7d0-02 / ext4 noatime,lazytime,rw 0 1
PARTUUID=907af7d0-01 /boot vfat noatime,lazytime,rw 0 2
UUID=406CED016CECF298 /mnt/samba/backup ntfs noatime,lazytime,rw,permissions,big writes,nofail,noauto,x-systemd.automount
UUID=825AE4125AE4052F /mnt/samba/share ntfs noatime,lazytime,rw,permissions,big
writes,nofail,noauto,x-systemd.automount

both devices are set with x-systemd.automount flag. Means, on a reboot these devices are mounted automatically as soon as someone is trying to access them. Could be you don’t see them after a reboot. They will be mounted just in case you or an application is going inside the folder. Usually there is no need to mount them manually after a reboot.

Btw: what do you mean with power loss? Is that a reboot on your DietPi device or on the external HDD?

Power loss meaning my kid or dog hit’s the power strip and turns off my HDD and my diet pi. When that happens, or I have a normal power outage, when everything boots back up I have to remount the USB hard drive in the drive-manager again.

for testing purposes, do a reboot and connect on command line afterwards. Now go inside your data directories /mnt/samba/backup as well as /mnt/samba/share and check if your data are visible.

If drives did not get mounted have a look to dmesg and journalctl for error messages. Information about the mount should be at the end of the list

Hey, @Joulinar , I’m adding a reply here instead of starting a new thread. I’m having an issue with automounting my external USB to mnt/media at reboot, and I wonder if this entry under NETWORK in fstab may be to blame?

# You can use "dietpi-drive_manager" to setup mounts.
# NB: It overwrites and re-creates physical drive mount entries on use.
#----------------------------------------------------------------
# NETWORK
#----------------------------------------------------------------
192.168.50.242:/mnt/media   /mnt/media   nfs    rw  0  0

#----------------------------------------------------------------
# TMPFS
#----------------------------------------------------------------
tmpfs /tmp tmpfs size=1024M,noatime,lazytime,nodev,nosuid,mode=1777
tmpfs /var/log tmpfs size=50M,noatime,lazytime,nodev,nosuid,mode=1777

#----------------------------------------------------------------
# MISC: ecryptfs, vboxsf, glusterfs, mergerfs, bind, Btrfs subvolume
#----------------------------------------------------------------


#----------------------------------------------------------------
# SWAP SPACE
#----------------------------------------------------------------
/var/swap none swap sw

#----------------------------------------------------------------
# PHYSICAL DRIVES
#----------------------------------------------------------------
PARTUUID=c26b8af2-02 / ext4 noatime,lazytime,rw 0 1
PARTUUID=c26b8af2-01 /boot vfat noatime,lazytime,rw 0 2
UUID=f02d7604-01a9-4326-8758-532d31affa4d /mnt/media ext4 noatime,lazytime,rw,nofail,noauto,x-systemd.automount

Thoughts? Can I safely remove the NETWORK entry? Thanks!

for testing you simply could comment out (using a #) the line within network section and reboot your system.

1 Like

Well, I rebooted after my latest failed attempt to update Dietpi to 8.12 today, and the drive did NOT automount with this line UNcommented. Used drive manager to remount the drive and restarted sonarr and sab, and all’s back to normal. I’m not sure why the update failed…gave me that “dpkg: cannot write to log file ‘/var/log/dpkg.log’: No space left on device” error again, but df -h looks like this:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        30G  3.5G   25G  13% /
devtmpfs        446M     0  446M   0% /dev
tmpfs           480M  4.0K  480M   1% /dev/shm
tmpfs           192M  5.3M  187M   3% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.0G     0  1.0G   0% /tmp
tmpfs            50M  412K   50M   1% /var/log
/dev/mmcblk0p1  127M   35M   92M  28% /boot
/dev/sda1       1.8T  779G  1.1T  43% /mnt/media

You log directory was full and it got cleaned due to reboot. I guess one of your apps (like Sonarr) is writing quite some logs filling up the directory.

1 Like

OK. I don’t get it. Last time I had this issue I cleared all the logs and set all my *arr aps to Info log level. Guess I’ll just have to keep a better eye on it and make sure I’m deleting log files prior to doing any updates.

Better to avoid doing all this unwanted logs. Just check which app generation them.