Automount extroot partition on plug in?

Hello,
I apologize if this question has already been asked, but i couldn't find the specifics..

I am running openwrt 19.07.7 from usb drive, it has two partitions, ext4 (mounted on /overlay) and ntfs(mounted on /mnt/sda1). It's all running well and mounting automatically on boot.

But, if i remove the usb drive and plug it back in, it won't auto mount and the device remains inaccessible until i toggle the power.

Is there a way to auto mount both partitions if they are plugged back in while the device is still running without having to reboot?

This is my fstab file.

config global
	option anon_swap '0'
	option anon_mount '0'
	option auto_swap '1'
	option auto_mount '1'
	option delay_root '5'
	option check_fs '0'

config mount
	option enabled '1'
	option uuid '8137ba5f-a073-d701-8037-ba5fa07'
	option target '/overlay'

config mount
	option enabled '1'
	option label 'STORAGE'
	option target '/mnt/sda1'

Regards!

install blockd package and set the "autofs" option for that folder to 1 in the interface or configs. That's what is responsible for automounting when you plug in so it should work.

Note that blockd is only responsible of automounting, not syncing the configs, so if you made changes to configs while the USB drive was disconnected, you will have to do them again when you re-connect it.

1 Like

Thanks for your reply,

So i just need to add it like this after installing blockd?


config global
	option anon_swap '0'
	option anon_mount '0'
	option auto_swap '1'
	option auto_mount '1'
	option delay_root '5'
	option check_fs '0'

config mount
	option enabled '1'
	option uuid '8137ba5f-a073-d701-8037-ba5fa07'
	option target '/overlay'
	option autofs '1'

config mount
	option enabled '1'
	option label 'STORAGE'
	option target '/mnt/sda1'
	option autofs '1'

yes, that should be it.

Well, I just tested it and getting the same error. It won't remount.

Sat-24-Jul-2021 1:00 PM,Warning,,[  387.500565] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Critical,,[  392.817127] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81624: comm kworker/0:1: reading directory lblock 0
Sat-24-Jul-2021 1:00 PM,Warning,,[  392.806832] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Critical,,[  392.781231] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81624: comm kworker/0:1: reading directory lblock 0
Sat-24-Jul-2021 1:00 PM,Warning,,[  392.770943] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Critical,,[  392.743191] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81624: comm kworker/0:1: reading directory lblock 0
Sat-24-Jul-2021 1:00 PM,Warning,,[  392.732869] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Critical,,[  392.708399] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81624: comm kworker/0:0: reading directory lblock 0
Sat-24-Jul-2021 1:00 PM,Warning,,[  392.698097] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Warning,,[  387.500565] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Warning,,[  387.479658] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Warning,,[  387.457652] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Warning,,[  387.435564] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 1:00 PM,Warning,,[  387.425210] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Critical,,[  339.410508] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #83503: comm luci: reading directory lblock 0
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.400216] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.313956] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.303621] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.229372] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.188465] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:59 PM,Warning,,[  339.178129] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.814555] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.804241] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.787285] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.733851] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.723534] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.706512] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.652883] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.642569] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.625639] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.569953] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.559639] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Notice,,[  289.548339] sd 1:0:0:0: [sdb] Attached SCSI disk
Sat-24-Jul-2021 12:58 PM,Info,,[  289.536338]  sdb: sdb1 sdb2
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.512602] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.502290] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Error,,[  289.483075] sd 1:0:0:0: [sdb] Assuming drive cache: write through
Sat-24-Jul-2021 12:58 PM,Error,,[  289.472275] sd 1:0:0:0: [sdb] No Caching mode page found
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.448913] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.438600] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Debug,,[  289.425284] sd 1:0:0:0: [sdb] Mode Sense: 28 00 00 00
Sat-24-Jul-2021 12:58 PM,Notice,,[  289.415508] sd 1:0:0:0: [sdb] Write Protect is off
Sat-24-Jul-2021 12:58 PM,Notice,,[  289.397295] sd 1:0:0:0: [sdb] 156301488 512-byte logical blocks: (80.0 GB/74.5 GiB)
Sat-24-Jul-2021 12:58 PM,Critical,,[  289.371101] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  289.360813] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Notice,,[  289.341369] scsi 1:0:0:0: Direct-Access     ST380215 A                     PQ: 0 ANSI: 2 CCS
Sat-24-Jul-2021 12:58 PM,Critical,,[  288.407720] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  288.397405] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  288.351823] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  288.341522] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Info,,[  288.331081] scsi host1: usb-storage 1-1:1.0
Sat-24-Jul-2021 12:58 PM,Info,,[  288.295743] usb-storage 1-1:1.0: USB Mass Storage device detected
Sat-24-Jul-2021 12:58 PM,Info,,[  288.030525] usb 1-1: new high-speed USB device number 3 using dwc2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.315741] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.305429] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.288381] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.232583] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.222271] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.199073] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.188779] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.159065] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.148750] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.137870] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.086444] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.076152] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.049536] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.039215] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  276.016053] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81483: comm ls: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  276.005738] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  275.976078] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  275.965750] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Warning,,[  275.954422] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Critical,,[  275.904035] EXT4-fs error (device sda2): ext4_find_entry:1455: inode #81482: comm procd: reading directory lblock 0
Sat-24-Jul-2021 12:58 PM,Warning,,[  275.893749] blk_partition_remap: fail for partition 2
Sat-24-Jul-2021 12:58 PM,Info,,[  275.862743] usb 1-1: USB disconnect, device number 2

Extroot requires reboot as it needs to be mounted at the preinit stage.

1 Like

Well you didn't mention errors in the OP.

These errors seem more like filesystem errors. Try running a filesystem check on that partition, or add
option check_fs '1'
to the overlay config block, to ask for an automatic filesystem check on mount.

Don't do that for the other partition because ntfs filesystem check does not work on linux systems like OpenWrt

Sorry, i didn't thought it was necessary as these errors generated once i remove the drive(no errors while it's functioning normally), it's a normal hard disk to be exact.

ah so it's because it thinks it is still mounted and tries to access a drive that is not there.

what is the result of command
mount

Well i had this feeling since extroot is like external usb acting as internal storage, if it's removed suddenly, the system won't know what to do, since the instructions were in the removed drive. If that's correct.

yes this configuration must be done with the USB drive disconnected too, so that both configurations in internal storage and in usb drive are the same.

This is the output of "mount" when the device is running normally

/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/sda2 on /overlay type ext4 (rw,relatime,data=ordered)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
/dev/sda1 on /mnt/sda1 type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)


And this after drive removed

mount
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/sda2 on /overlay type ext4 (rw,relatime,data=ordered)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
/dev/sda1 on /mnt/sda1 type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

The system things drive is still connected, it's not unmounting the drive. Is this normal?

Reboot the device without the USB drive, make the same fstab configuration and install blockd (so that config and blockd are also in internal storage and the extroot overlay mount is done by blockd).

Then it should work, after a bit of wait the blockd will detect a timeout and unmount /dev/sda2 .

If it still does not work, you have to write an hotplug script that will unmount the /dev/sda2 when the USB device is removed (using OpenWrt Hotplug infrastructure should be easy enough as these events are already detected) https://openwrt.org/docs/guide-user/base-system/hotplug and save it in both internal storage and USB

1 Like

Well, thanks, but the first option didn't work. It just won't mount.
I guess it will only work with script. I don't know much about scripting, don't know if i can make one myself.