What's new

Entware How to properly eject/dismount USB attached SSD with EXT2 file system?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Limpi

Occasional Visitor
Hey,
I have an RT-AX86U with Merlin 388.1.
I also have an SSD (Patriot Burst 480GB) formatted to EXT2 and installed entware on it (with amtm).
It works fine.
Except ejecting the storage from Merlin’s web UI!
That fails with “device is busy”.
Disk check also can not properly dismount it.
I tried to dismount it with SSH command line, but that also failed the same way.
How can I properly dismount it?
(I am using EXT2 because the SSD’s purpose is to run qBittorrent. That works well now.
With EXT4 and journaling enabled it worked not really well, I got strange read errors and 100% CPU utilization for a while sometimes.
I just want to dismount the device to run a disk check on it with not only read-only mode.)
 
Last edited:
Hey,
I have an RT-AX86U with Merlin 388.1.
I also have an SSD (Patriot Burst 480GB) formatted to EXT2 and installed entware on it (with amtm).
It works fine.
Except ejecting the storage from Merlin’s web UI!
That fails with “device is busy”.
Disk check also can not properly dismount it.
I tried to dismount it with SSH command line, but that also failed the same way.
How can I properly dismount it?
(I am using EXT2 because the SSD’s purpose is to run qBittorrent. That works well now.
With EXT4 and journaling enabled it worked not really well, I got strange read errors and 100% CPU utilization for a while sometimes.
I just want to dismount the device to run a disk check on it with not only read-only mode.)
You've likely got a swap file still in use. With EXT4 it can be stopped from the GUI dismount process, but maybe with EXT2 it can't. You would need SSH access to stop the swap file, so the disc can be unmounted.
 
I recall using this at one point. It's a script that used to work. I haven't had to use it in years so it may need some help to run.

Code:
#!/bin/sh

SWP="$(find $1/myswap.swp 2> /dev/null)"
if [ "$SWP" ]; then
        swapoff $1/myswap.swp # cleanly close swap
fi

umount /tmp/mnt/EXT2

chmod 700 unmount
 
There is this too.

Code:
#enable swap
swapon /tmp/mnt/(DRIVE NAME)/myswap.swp

#disable swap
swapoff /tmp/mnt/(DRIVE NAME)/myswap.swp
 
Hope some of this helps. :)
 
Hope some of this helps. :)

Thank you!

Unfortunately I do not use swap file
(intentionally, because after I created one with 2 GB size, I noticed that nothing is actually using it, but it was stored on the SSD which was in a 2.5" rack that could go automatically to sleep...), so I think something else is holding the SSD busy.

How can I check what is it?

(Sorry for the lame question, I have only very poor Linux skills...)
 
Thank you!

Unfortunately I do not use swap file
(intentionally, because after I created one with 2 GB size, I noticed that nothing is actually using it, but it was stored on the SSD which was in a 2.5" rack that could go automatically to sleep...), so I think something else is holding the SSD busy.

How can I check what is it?

(Sorry for the lame question, I have only very poor Linux skills...)
Using SSH you could look at the "top" command, check it out. That may narrow things down, the other thing to consider is the torrent client.
 
If you find a process that may be doing it, use "kill (PID)" PID being the process number you found. TOP will give you a table of results that is dynamic so it changes in real time.
 
If you find a process that may be doing it, use "kill (PID)" PID being the process number you found. TOP will give you a table of results that is dynamic so it changes in real time.

That's cool, thanks!

And can I somehow see which processes are accessing /dev/sdb1 a lot?

(I manually stopped the qBittorrent through it's Web UI, but it's possible that is is not properly shutting down when using EXT2 file system. Or something else is doing it. (The service stop_nasapps command is also not enough.) With EXT4+journaling I had no problems with eject/unmount.)
 
Last edited:
If you fill this out right it should tell you.

lsof | grep '/dev/name of drive'

It will give you results like this as an example.

vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1

In this case it's vi that is running so you would kill 4453

Then use this to unmount.

umount /dev/name of drive


Found all this HERE.
 
lsof available on the router?

You want to umount the filesystem merely to check the filesystem? Really?

Probably will have to walk the /proc/[0-9]* directories to see where there's an open file on the "drive."
 
Last edited:
lsof available on the router?

AFAIK, it's not a built-in utility, but you can install it via Entware:

Bash:
opkg install lsof
 
If you fill this out right it should tell you.

lsof | grep '/dev/name of drive'

It will give you results like this as an example.

vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1

In this case it's vi that is running so you would kill 4453

Then use this to unmount.

umount /dev/name of drive


Found all this HERE.

That's great, thank you very much! :)
 
AFAIK, it's not a built-in utility, but you can install it via Entware:

Bash:
opkg install lsof

Thanks!

That I can do:
Limpi@RT-AX86U:/tmp/home/root# opkg install lsof
Installing lsof (4.94.0-1) to root...
Downloading https://bin.entware.net/aarch64-k3.10/lsof_4.94.0-1_aarch64-3.10.ipk
Installing libtirpc (1.3.2-1a) to root...
Downloading https://bin.entware.net/aarch64-k3.10/libtirpc_1.3.2-1a_aarch64-3.10.ipk
Configuring libtirpc.
Configuring lsof.

I think it's done. :)
 
Last edited:
lsof available on the router?

You want to umount the filesystem merely to check the filesystem? Really?

Probably will have to walk the /proc/[0-9]* directories to see where there's an open file on the "drive."

Why do you ask, is it an unusual case to unmount the filesystem to check it?

Whit read-only check mode I get this:
"
Limpi@RT-AX86U:/tmp/home/root# e2fsck -vfn /dev/sdb1
e2fsck 1.45.6 (20-Mar-2020)
Warning! /dev/sdb1 is mounted.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (94571872, counted=92260880).
Fix? no


Free inodes count wrong (26377764, counted=26377747).
Fix? no


476 inodes used (0.00%, out of 26378240)
39 non-contiguous files (8.2%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 41/8/1
10920950 blocks used (10.35%, out of 105492822)
0 bad blocks
4 large files

364 regular files
65 directories
0 character device files
0 block device files
0 fifos
0 links
54 symbolic links (54 fast symbolic links)
1 socket
------------
484 files
Limpi@RT-AX86U:/tmp/home/root#

"
I guess those are not really a big problem. But I still want to fix them.
Or should I leave those errors alone? :)
By the way how can the filesystem miscalculate such values?
I think I used it as intended, there was no unexpected events.
(Except the few unsuccessful attempts to eject the drive through Asuswrt-Merlin's web admin UI...)
 
If you fill this out right it should tell you.

lsof | grep '/dev/name of drive'

It will give you results like this as an example.

vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1

In this case it's vi that is running so you would kill 4453

Then use this to unmount.

umount /dev/name of drive


Found all this HERE.

Wow, LOL, it's entware itself :):

Limpi@RT-AX86U:/tmp/home/root# lsof | grep '/tmp/mnt/ASUS-480GB'
lsof 29729 Limpi txt REG 8,17 164016 14008780 /tmp/mnt/ASUS-480GB/entware/bin/lsof
lsof 29729 Limpi mem REG 8,17 2931760 14008736 /tmp/mnt/ASUS-480GB/entware/usr/lib/locale/locale-archive
lsof 29729 Limpi mem REG 8,17 105168 14008394 /tmp/mnt/ASUS-480GB/entware/lib/libpthread-2.27.so
lsof 29729 Limpi mem REG 8,17 1431816 14008360 /tmp/mnt/ASUS-480GB/entware/lib/libc-2.27.so
lsof 29729 Limpi mem REG 8,17 83960 14008349 /tmp/mnt/ASUS-480GB/entware/lib/libgcc_s.so.1
lsof 29729 Limpi mem REG 8,17 165984 14008772 /tmp/mnt/ASUS-480GB/entware/lib/libtirpc.so.3.0.0
lsof 29729 Limpi mem REG 8,17 136952 14008356 /tmp/mnt/ASUS-480GB/entware/lib/ld-2.27.so
grep 29730 Limpi txt REG 8,17 228696 14008655 /tmp/mnt/ASUS-480GB/entware/libexec/grep-gnu
grep 29730 Limpi mem REG 8,17 2931760 14008736 /tmp/mnt/ASUS-480GB/entware/usr/lib/locale/locale-archive
grep 29730 Limpi mem REG 8,17 1431816 14008360 /tmp/mnt/ASUS-480GB/entware/lib/libc-2.27.so
grep 29730 Limpi mem REG 8,17 83960 14008349 /tmp/mnt/ASUS-480GB/entware/lib/libgcc_s.so.1
grep 29730 Limpi mem REG 8,17 526592 14008643 /tmp/mnt/ASUS-480GB/entware/lib/libpcre2-8.so.0.10.2
grep 29730 Limpi mem REG 8,17 136952 14008356 /tmp/mnt/ASUS-480GB/entware/lib/ld-2.27.so
lsof 29731 Limpi txt REG 8,17 164016 14008780 /tmp/mnt/ASUS-480GB/entware/bin/lsof
lsof 29731 Limpi mem REG 8,17 2931760 14008736 /tmp/mnt/ASUS-480GB/entware/usr/lib/locale/locale-archive
lsof 29731 Limpi mem REG 8,17 105168 14008394 /tmp/mnt/ASUS-480GB/entware/lib/libpthread-2.27.so
lsof 29731 Limpi mem REG 8,17 1431816 14008360 /tmp/mnt/ASUS-480GB/entware/lib/libc-2.27.so
lsof 29731 Limpi mem REG 8,17 83960 14008349 /tmp/mnt/ASUS-480GB/entware/lib/libgcc_s.so.1
lsof 29731 Limpi mem REG 8,17 165984 14008772 /tmp/mnt/ASUS-480GB/entware/lib/libtirpc.so.3.0.0
lsof 29731 Limpi mem REG 8,17 136952 14008356 /tmp/mnt/ASUS-480GB/entware/lib/ld-2.27.so
Limpi@RT-AX86U:/tmp/home/root#


How can I fully stop entware on the drive before ejecting the device?
(I think Asuswer-Merlin's admin web UI should do this, but it fails to properly do it...)

Or I really just should kill the 29729, 29730 and 29731 processes?
Will that cause no trouble?

I also have this (configured automatically by amtm):
Limpi@RT-AX86U:/jffs/scripts# cat services-stop
#!/bin/sh
/opt/etc/init.d/rc.unslung stop # Added by amtm
 
Wow, LOL, it's entware itself :):

Limpi@RT-AX86U:/tmp/home/root# lsof | grep '/tmp/mnt/ASUS-480GB'
Use the device file (e.g. /dev/sdb1) that the mount point (e.g. /tmp/mnt/ASUS-480GB) is associated with:

EXAMPLE:
Bash:
lsof | grep '/dev/sdb1'
 
Use the device file (e.g. /dev/sdb1) that the mount point (e.g. /tmp/mnt/ASUS-480GB) is associated with:

EXAMPLE:
Bash:
lsof | grep '/dev/sdb1'

Thanks!

I could properly stop entware with this command:
Limpi@RT-AX86U:/jffs/scripts# /opt/etc/init.d/rc.unslung stop
Checking qbittorrent-nox... alive.
Shutting down qbittorrent-nox... done.


By the way the disk check found no problems, LOL:

Limpi@RT-AX86U:/tmp/home/root# e2fsck -vfn /dev/sdb1
e2fsck 1.45.6 (20-Mar-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

500 inodes used (0.00%, out of 26378240)
41 non-contiguous files (8.2%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 43/8/1
13232031 blocks used (12.54%, out of 105492822)
0 bad blocks
4 large files

370 regular files
65 directories
0 character device files
0 block device files
0 fifos
0 links
56 symbolic links (56 fast symbolic links)
0 sockets
------------
491 files
Limpi@RT-AX86U:/tmp/home/root#


So I don't see why did it found these two errors in read-only mode before:
Free blocks count wrong (94571872, counted=92260880).
Free inodes count wrong (26377764, counted=26377747).

But I think I am leaving this problem alone then. :)
Because it is not really a problem, just a strange behavior (for me).
 
I also have an SSD (Patriot Burst 480GB) formatted to EXT2 and installed entware on it (with amtm).
It works fine.
Except ejecting the storage from Merlin’s web UI!
That fails with “device is busy”.
I could properly stop entware with this command:
Limpi@RT-AX86U:/jffs/scripts# /opt/etc/init.d/rc.unslung stop
Checking qbittorrent-nox... alive.
Shutting down qbittorrent-nox... done.

In your case, based on what you described above, it seems that what you might need to do, to avoid similar problems in the future, is to stop the Entware services from the "/jffs/scripts/unmount" script as well.

For example:
Bash:
#!/bin/sh
# FILE: unmount #
...
...
RC_UNSLUNG="${1}/entware/etc/init.d/rc.unslung"
[ -x "$RC_UNSLUNG" ] && $RC_UNSLUNG stop
...
 
I put this together the other day. Give it a shot. I call it lsofalt.


Bash:
[bash]
#!/bin/sh

cd /proc
this=`basename $0`
ran=y
for i in `ls -d [0-9]* 2>/dev/null | sort -g`; do
   opfi=`ls -lF ${i}/fd/ 2>/dev/null | sed -n '/\//{ /\/dev\//d
                                                    /\/proc\//d
                                                    /(deleted)/d
                                                    /'$this'/d
                                                    s/.*->/  /p }'`
   case $1 in
      +l* ) # to include .lock files as well
    ;;
      * ) [ "$ran" = "y" ] && { ran=n
            echo "#   pass \"+l[ocks]\" to not exclude any /var/lock/ files"; }
        opfi=`echo "$opfi" | sed '/\/var\/lock\//d'`
    ;;
   esac
   [ "$opfi" ] && { /bin/echo -en "\n$i\t"
      cat ${i}/cmdline | tr '\0' ' '
      echo
      echo "$opfi"
   }
done
[/bash]
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top