LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-03-2013, 03:45 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Rep: Reputation: 25
How to unmount a device?


I'm trying to unmount a device as a whole! Take note that a device such as a HDD can have multiple partitions and some of them can be mounted while others are not. Is there an easy way to unmount an entire device i.e. all mounted partitions on a given device like /dev/sdb?

Is there a single shell command (one-liner) for this?
Or do I have to write a script that iterates through /dev/sdb*?

Best regards!
~dis
 
Old 09-03-2013, 04:18 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,399

Rep: Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192Reputation: 4192
You umount whichever partition(s) is/are mounted - easy enough to do as a one-liner.
Should you happen to have a filesystem on an unpartitioned disk, you can simply umount that as a single command.
 
Old 09-03-2013, 04:32 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,374

Rep: Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009
when I press "eject" or "safely remove drive" it will unmount all the partitions belonging to that device. I do not know how it is solved, but definitely works.
 
Old 09-03-2013, 06:38 AM   #4
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
syg00: Okay, so you're saying the easiest way is to use a shell script to iterate through all partitions and unmount those which are mounted?

pan64: I have a headless system, so there's no pressing "eject" or "safely remove". Additionally, those options will also spindown and unlink the device. This is not desired in my situation, as I'm trying to dismount any partitions and then format the hard disk.

EDIT: I found the one-liner I was looking for:
# umount /dev/sdb?*

I have another question. What is the recommended way to handle disk formatting, filesystem creation and un/mounting partitions in python on a linux system? Shall I simply call the shell scripts, or are there any packages for this purpose. I found python-parted bindings package, which seems to handle part of the stuff, but the documnetation is practically nonexistent.

~dis

Last edited by displace; 09-03-2013 at 11:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-unmount device in kde after performing "device action" newbie to linux Linux - Software 1 01-25-2012 06:28 AM
Unmount cd: device is busy jhimes Linux - Hardware 18 04-08-2008 01:51 AM
How Do I Unmount An Unmounted Device? maatghandi Linux - Software 10 02-17-2005 12:28 PM
unmount the usb device prital Linux - Newbie 6 01-24-2005 08:08 PM
unmount usb device pmorimer Linux - Hardware 2 08-25-2004 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:44 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