I always thought that to safely remove a device that had been mounted was to use the umount
command and until recently when I switched to Ubuntu 12.04 LTS, I noticed that there was the ability to safely remove the device which struck my curiosity.
I dug around a number of posts and found that umount
apparently doesn't mean I can safely remove the device because it doesn't power down the device. I know there is the option to eject
. Now this is my understanding after scouring the Internet. References include:
- The “Unmount”, “Eject” and “Safely Remove Drive” dilemma
-
"eject" / "unmount" / "safely remove drive" – which is better?
- umount only unmounts a single partition on the device
- safely remove unmounts all partitions on the device and powers down the device
- eject is used to media such as CDs, DVD, etc
I then came across an article but found the process convoluted and I think I finally hit pay dirt when I came across the command udisks
e.g. udisks --unmount /dev/sdb1 && udisks --detach /dev/sdb
What confuses me is (aside from whether umount
actually means it is safe to remove the device without data loss and whether I need to use the command sync
prior to it as well as that the device has powered down which safely remove seems to achieve) is why do I have to use /dev/sdb
followed by --detach
as opposed to /dev/sdb1
Best Answer
/dev/sdb
is the whole device./dev/sdb1
is one partition on that device.While you could use a disk without partitioning it, that's rather unusual (outside of RAID setups, but then you make the filesystems on the raid device nodes, not the physical device nodes).
It doesn't really make sense to try to detach (physically remove) a single partition – you want to remove the whole device (that can contain multiple partitions), not just one partition of that device.
Unmounting a partition will synchronize the filesystem, so calling
sync
beforeunmount
is not necessary.Calling
udisks --detach
on the device checks that you have no filesystems mounted on that device (you should make sure that that call does indeed succeed), and will perform an "orderly shutdown", which is always preferable to a "pull the plug" approach, regardless of whether that particular device does anything special.