LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2024, 03:46 PM   #1
disk_bearing
Member
 
Registered: Mar 2022
Posts: 36
Blog Entries: 1

Rep: Reputation: 2
Safely disconnect a USB drive via command line


The eject button in Fedora's file manager works great but I want to get better at the command line.
Code:
$ umount /dev/sdx
usually does nothing.
Code:
$ udisksctl umount -b /dev/sdx
$ udisksctl power-off -b /dev/sdx
sometimes works, other times it ties up the drive making me afraid to remove it. Also its really verbose.

Any tips about the nuance of safely removing drives?
 
Old 02-09-2024, 03:53 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by disk_bearing View Post
The eject button in Fedora's file manager works great but I want to get better at the command line.
Code:
$ umount /dev/sdx
usually does nothing.
Code:
$ udisksctl umount -b /dev/sdx
$ udisksctl power-off -b /dev/sdx
sometimes works, other times it ties up the drive making me afraid to remove it. Also its really verbose. Any tips about the nuance of safely removing drives?
Reading the man page on the umount command would be a good tip. You don't unmount the device, but the mount-point, and unless you're in the right groups you need to be root or use sudo to run it. If you have /dev/sdx mounted on /home/user/path you'd type in:
Code:
umount /home/user/path
 
1 members found this post helpful.
Old 02-09-2024, 07:55 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,987

Rep: Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627
Usb's could be in some cache state. Some process still using it?

Eject and unmount a filesystem different.

https://unix.stackexchange.com/quest...-eject-command
 
Old 02-09-2024, 09:07 PM   #4
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,127
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
You should be able to unmount with either the device path or the mount path. So if your USB device is /dev/sdb1 mounted on /mnt/myusb, using umount /dev/sdb1 or umount /mnt/myusb should work. If you get a message like device or resource is busy, you can use lsof to see what's keeping your device busy. Ex. lsof /mnt/myusb.
 
Old 02-10-2024, 12:01 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,583
Blog Entries: 19

Rep: Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454Reputation: 4454
Quote:
Originally Posted by disk_bearing View Post
The eject button in Fedora's file manager works great but I want to get better at the command line.
Code:
$ umount /dev/sdx
usually does nothing.
I've never known umount to "do nothing". Either it works silently and a subsequent run of mount shows the device gone, or it fails and gives you an error message (usually "device busy"). Did you run mount immediately afterwards to check if anything had happened?

Remember that Linux commands don't usually give you any feedback when they work. They give you an error message when they don't work. It's the Napoleon principle: only wake me if there's bad news.

Last edited by hazel; 02-10-2024 at 12:03 AM.
 
Old 02-10-2024, 12:03 AM   #6
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068
A simple df will remind you what's mounted where, so you can verify the correct filesystem to umount. It probably isn't /dev/sdx that needs umounting, but /dev/sdxy, or its mount point.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Proper way to disconnect from internet via command line and wpa_supplicant TheEzekielProject Linux - Networking 1 07-02-2017 09:15 PM
How can I Disconnect an Established connection via command line? hack3rcon Linux - Networking 8 12-03-2015 06:55 PM
Unable to mount USB - USB disconnect with Lexar thumb drive stoicbaby Linux - Hardware 9 04-29-2015 05:31 PM
can you apply 2.6.x kernel config to 2.4.x safely/somewhat safely? silex_88 Linux - Software 3 12-09-2005 11:38 PM
How do I safely disconnect USB camera operating in PTP mode? TakeAwayDave Linux - Hardware 4 07-22-2004 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration