How to auto remount external HDD after power loss to laptop server?
from Lenna@piefed.ca to selfhosted@lemmy.world on 19 May 21:36
https://piefed.ca/c/selfhosted/p/733454/how-to-auto-remount-external-hdd-after-power-loss-to-laptop-server
from Lenna@piefed.ca to selfhosted@lemmy.world on 19 May 21:36
https://piefed.ca/c/selfhosted/p/733454/how-to-auto-remount-external-hdd-after-power-loss-to-laptop-server
I’m running a Ubuntu server on my old laptop with an external HDD connected to it. The external HDD is powered independently from the laptop, as it is plugged into the wall.
During a power outage, my laptop remains operational due to its battery, but the HDD shuts down. When power is restored, my laptop does not automatically remount the HDD, and I have to reboot the system manually to access it.
Does anyone know how I can resolve this issue?
#selfhosted
threaded - newest
Cheap and dirty solution would be a battery backup for the drive, but there are some big concerns about the setup. Drives don’t like to go dark like that.
I had a laptop lying around and computer parts are too expensive now to build my own server, so that’s what I went with. Is the concern you have involving loss of data?
One concern, yes. Others such as parking heads. Don’t want platters spinning down with drive heads hovering. Power spikes won’t do the circuit boards any good.
Doesn’t hurt to show servers some kindness even if it’s a laptop in a closet.
Autofs might do what you’re looking for. How often do you have power outages that it’s a major concern?
I was going to mention that, but also that while I’m sure that it’d handle power loss while it’s unmounted the filesystem I don’t know what happens if the backing storage goes away while it’s in use.
It doesn’t happen often, but when it does happen I temporarily lose access to my media. But based on what others are saying here, it looks like it’s possible to manually remount my drive instead of rebooting. So I’ll give that a try.
I can infer that you want suggestions for cost efficient backup power. Depending on the laptop model, it could power the HDD and in case of an outage it could draw power from the laptop’s battery. It would decrease battery charge duration but it would be enough for a graceful shutdown to prevent data loss.
Alternatively, you could maybe use a battery pack.
That risks breaking the drive eventually. They don’t handle loss of power well. And if its being written to at the time, data loss and corruption is inevitable.
That said, no need to reboot to mount the drive.
I shall give this a try the next time it loses power. Thank you.
I had one back in the day like that. My notes on that event are old so maybe someone can modify or clarify.
First you’ll have to find the UUID of the external drive. (
lsblk -f) Then create a mount file like:sudo nano /etc/systemd/system/mnt-data.mount. In themnt-data.mountfile, insert something like:Enable and reload:
Verify status:
systemctl status mnt-data.mountShould say ‘active’. Reboot and test. Let me know if that works. Like I said, that was a while ago. If it works, it’s just another reason why you should doccument your server setups. If it doesn’t, well shucks I tried. LOL
This but put the entries in /etc/fstab instead.
I’ll make an addenda to my notes. Thanks.
My /etc/fstab file currently has the following:
UUID=412ea77a-96e1-427c-9f75-2aae2fe0dca1 /mnt/wd ext4 defaults 0 2If I were to use the
mnt-data.mountyou’ve suggested, does that mean I need to delete what I already have in /etc/fstab and replace it with what you suggested?I recommend a UPS, even a small one is fine for this. Spinning disks don’t like frequent starts and stops, especially not unplanned powerless ones.
At least you should be running a journaling file system or something similar which tolerates power loss decently (you’ll still see data corruption, but the file system won’t die). If you run software that doesn’t tolerate power loss well, then you absolutely need an UPS
Find a used one for sale. Bonus points if it has any kind of management. Replace the battery. If at all possible, have it unmount the drive at a certain percentage.
I don’t know why you’d need a reboot to remount the thing. Are you just not familiar with how to add something to /etc/fstab and mount it manually and are relying on some kind of auto-mounting system that only happens to run at boot, or is it giving some kind of error?
If an error, what happens when you do:
?
This is correct. I made my drive auto mount using /etc/fstab, and I believe that is only checked once during boot.
Nah, that’s good. What I mean is, if it’s in /etc/fstab, it should be possible to manually mount it without a reboot. Have you tried manually remounting it after power comes back?
Nope, I haven’t tried that. But I will give it a try when the next power outage occurs. I actually didn’t know I could manually remount until today. I’m still pretty new to selfhosting.
Gotcha. Yeah, the stuff in fstab is just a convenience; it’s equivalent to running a bunch of mount commands at boot. You might be able to just run “mount” again without the '-o remount" option. I was just listing that in case you were seeing some kind of errors in trying to manually mount it.
You can run mount -a to mount all fstab entries. You could put that in a cronjob I guess