A
A
Alexander Alexandrov2021-10-11 04:06:33
Debian
Alexander Alexandrov, 2021-10-11 04:06:33

How to remount a drive on a sudden shutdown?

I use an external usb disk with two partitions on the raspberry pi4. One for nextcloud cloud storage, the second for your needs. I mount partitions in fstab like this:

proc            /proc           proc    defaults          0       0
PARTUUID=560a887e-01  /boot           vfat    defaults          0       2
PARTUUID=560a887e-02  /               ext4    defaults,noatime  0       1
UUID=2EFC775BFC771C71 /mnt/usbstorage ntfs nofail,uid=www-data,gid=www-data,dmask=0007 0 0
UUID=48840E20840E10DC /mnt/transcend ntfs nofail,uid=pi,gid=pi 0 0
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30M 0 0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

Periodically, the disk falls off. Tried
sudo umount -a
sudo mount -a

Does not help.
This also doesn't work:
#!/bin/bash
if ! mountpoint -q /mnt/usbstorage
then 
mount -U 2EFC775BFC771C71 /mnt/usbstorage 
fi 
if ! mountpoint -q /mnt/transcend
then 
mount -U 48840E20840E10DC /mnt/transcend
fi

The commands
mount -U 48840E20840E10DC /mnt/transcend
mount -U 2EFC775BFC771C71 /mnt/usbstorage
work individually in the terminal without errors, but when you go to the transcend and usbstorage folders, there is nothing there.
How should you organize the connection of the disk in this case, so that you can control the moment when it falls off and remount?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Oleg Volkov, 2021-10-11
@voleg4u

Try using autofs. It mounts on demand, unmounted the rest of the time.
The second option is to set up udev rules. As the disk falls off, do "umount -l", as it appears - "mount".
Many years ago I did something similar here at the end of the article . Surely the syntax has changed, but you can get the idea.

C
ctyjiuh, 2021-10-11
@ctyjiuh

2 discs is a big deal. In any case, for previous generations, even one disk did not always pull out.
There are complaints about the lack of power in the logs?

D
Dmitry, 2021-10-11
@Demonische

The Raspberry Pi 4B has a 1.2A limit on all ports. Look at the consumption of an external hard drive and other peripherals. Had a similar problem recently.

A
Alexander Alexandrov, 2021-10-11
@Armany

The disk is clearly losing power, but is it really interesting to write a more script to reconnect?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question