Would like "quick" unmounting of USB drives - SOLVED

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
crgibson

Would like "quick" unmounting of USB drives - SOLVED

Post by crgibson »

A newbie with 3 USB drives (12 partitions) auto mounting at startup.
I get about 30 sec. startups. Reboots or shutdown take over 2 1/2 min before grub starts up.
When I unmount all partitions before reboot, shutdown takes about 3 sec.

Question: Is there any cmd or "trick" to unmount all partitions with a single click?

Thanks for any help!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Mute Ant

Re: Would like "quick" unmounting of USB drives

Post by Mute Ant »

The ext4 mount has a system variable at /proc/sys/vm/dirty_expire_centisecs which is usually set to a value '3000'. It means the last 30 seconds of drive activity, like closing files and shutting down applications, is still in RAM. Normally that's a good thing; Persistent changes are kept in fast RAM store just-in-case they change again; Hundreds of megabytes that don't get written to the drive until Linux is reasonably sure you want to keep them. Some of your shut-down delay will be everyone trying to write to the hard drive. If you want to shut down faster, you can try...

### Reduce the amount of data allowed to pile up in the cache. 10MB is a similar size to the RAM buffer in a hard drive.
sudo su -c "echo 10000000 > /proc/sys/vm/dirty_bytes"

### Send data in the cache to the drive earlier...ext3 uses 5 seconds.
sudo su -c "echo 500 > /proc/sys/vm/dirty_expire_centisecs"

These are temporary changes...gone next reboot. You can make them permanent with entries in the /etc/sysctl.conf file
vm.dirty_bytes = 10000000
vm.dirty_expire_centisec = 500

A five-second latency has worked fine for ext3 for...fifteen years?. You can make it less, of course, getting closer to a 'sync' mount where changes are written as soon as they happen. On my machine the GUI response starts getting 'gritty' as the drive writes interfere, but my processor is ten years old, maybe 'sync' is just what you want.
Last edited by Mute Ant on Sat Aug 12, 2017 9:29 pm, edited 1 time in total.
syg00

Re: Would like "quick" unmounting of USB drives

Post by syg00 »

Mute Ant wrote:A five-second latency has worked fine for ext3 for...fifteen years?.
For multiple attached USB devices ?.
I'm more comfortable with the dirty_bytes change than dirty_expire. More (slow) activity on the bus may not be beneficial everywhere, all the time. No real harm in testing it though.

Maybe a simple script to umount them all before shutdown - even a systemd service if you're that keen.
crgibson

Re: Would like "quick" unmounting of USB drives

Post by crgibson »

Mute Ant - Thanks for the suggestions . . . .sadly they did nothing and maybe added a few seconds to the shutdown.
Thanks again.

syg00 - Thanks for the reply. It sounds like a script is what I need. Willing to try anything if it will give a fast shutdown. Do you know of one?

Thanks again
syg00

Re: Would like "quick" unmounting of USB drives

Post by syg00 »

Something as simple as this should work

Code: Select all

for i in /media/$USER/* ; do echo $i ; done
Test it, and when happy, change the "echo" to "umount"; should be no need for sudo.
crgibson

Re: Would like "quick" unmounting of USB drives

Post by crgibson »

syg00 - THanks. I ran "for i in /media/$USER/* ; do echo $i ; done" and got a list of the partitions on the desktop. I changed the "echo" to "umount" and got:

chuck@chuck-GA-MA770-UD3 ~ $ for i in /media/$USER/* ; do umount $i ; done
umount: /media/chuck/BACKUPS: No such file or directory
umount: /media/chuck/LINUX: No such file or directory
umount: /media/chuck/NEW: No such file or directory
umount: /media/chuck/OTR: No such file or directory
umount: /media/chuck/Redo: No such file or directory

The first 4 listed are names for partitions
ions on the desktop and are the only ones still showing on the desktop now.

The "No such file or directory" could be because it's not the full name. ex "BACKUPS" should be "BACKUPS & IMAGES", "LINUX" should be "LINUX ONLY", "NEW" should be "NEW DOWNLOADS" and "OTR" should be "OTR BACKUPS".

All the other partitions are single named.

Any help with this info?

Thanks again for help.
syg00

Re: Would like "quick" unmounting of USB drives

Post by syg00 »

Funny, I thought about that at the time and though "nah, nobody uses spaces (and/or special characters) in labels". Try putting doubles-quotes around the $i to stop the word splitting, like so "$i"
crgibson

Re: Would like "quick" unmounting of USB drives

Post by crgibson »

syg00 - After running: "for i in /media/$USER/* ; do echo "$i" ; done" I get the same over 1 1/2 min. shutdown/reboot.

I assume that I'll have to run any script each time before rebooting?

Thanks for help again!
syg00

Re: Would like "quick" unmounting of USB drives

Post by syg00 »

Echo isn't going to do anything - change it to umount like I said. And yes, before every shutdown.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Would like "quick" unmounting of USB drives

Post by catweazel »

crgibson wrote:I assume that I'll have to run any script each time before rebooting?
You can always create a shutdown script and assign a keystroke to it, etc...

https://community.linuxmint.com/tutorial/view/1113
For example.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
crgibson

Re: Would like "quick" unmounting of USB drives

Post by crgibson »

syg00 - Thank You!!! I just had a brain fart when I looked at what I was doing. I saw 'ECHO' but was thinking "umount". It is working like a charm. Will mark SOLVED.

Thanks Again!

catweazel - Thanks for suggestion and link. I'll get to it next week when I have more time. Thanks.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Would like "quick" unmounting of USB drives

Post by catweazel »

crgibson wrote:tweazel - Thanks for suggestion and link. I'll get to it next week when I have more time. Thanks.
You're welcome.

Cheers.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Locked

Return to “Storage”