automatically mount USB drive on boot/power loss

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
mouseater
Posts: 8
Joined: Sat Oct 31, 2020 7:50 pm

automatically mount USB drive on boot/power loss

Post by mouseater »

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.
User avatar
Joulinar
Posts: 4170
Joined: Sat Nov 16, 2019 12:49 am

Re: automatically mount USB drive on boot/power loss

Post by Joulinar »

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.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
mouseater
Posts: 8
Joined: Sat Oct 31, 2020 7:50 pm

Re: automatically mount USB drive on boot/power loss

Post by mouseater »

Joulinar wrote: Wed Dec 23, 2020 11:59 am 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.
User avatar
Joulinar
Posts: 4170
Joined: Sat Nov 16, 2019 12:49 am

Re: automatically mount USB drive on boot/power loss

Post by Joulinar »

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

Code: Select all

cat /etc/fstab
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
mouseater
Posts: 8
Joined: Sat Oct 31, 2020 7:50 pm

Re: automatically mount USB drive on boot/power loss

Post by mouseater »

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
User avatar
Joulinar
Posts: 4170
Joined: Sat Nov 16, 2019 12:49 am

Re: automatically mount USB drive on boot/power loss

Post by Joulinar »

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?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
mouseater
Posts: 8
Joined: Sat Oct 31, 2020 7:50 pm

Re: automatically mount USB drive on boot/power loss

Post by mouseater »

Joulinar wrote: Sat Dec 26, 2020 11:52 am 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.
User avatar
Joulinar
Posts: 4170
Joined: Sat Nov 16, 2019 12:49 am

Re: automatically mount USB drive on boot/power loss

Post by Joulinar »

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
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply