You are not logged in.

#1 2011-11-21 15:01:38

jjacky
Member
Registered: 2011-11-09
Posts: 321
Website

pmount & safe removal of USB device

I am new to Linux (still discovering Arch inside a VM for now) and lately I've been looking into working with USB devices. I found out about pmount, great tool, but I wanted a little more. So also as part of me trying to learn C as well, I decided to make some changes.

First of all, as the title indicates, I added something to safely remove devices. After searching, it seemed that a lot of people simply unmount whatever file system they have mounted before unplugging their USB devices. That just didn't seem like completely enough to me, and I eventually found this post where it seems that there are, indeed, a few more steps to do before one can safely unplug an USB device.

So I did put those into a new option (-D) of pumount, which will try also try to unmount all partitions of a given device before. Similarly, the same option can be used with pmount to mount all partitions of a device at once.

Additionally, I also added support for a configuration file (/etc/pmount.conf) where one can predefined, for some devices, a few options. Some are new, others will overwrite any command-line options:
- fs to define the file system (overwrites option -t)
- charset to define the I/O character set (overwrites option -c)
- passphrase to define the file to read passphrase from (overwrites options -p/--passphrase)
- mntpt to define the mount point. Overwrites the usual way (e.g. specified label), can be anywhere (not restricted to /media/)
- options to defines the mounting options. That is, this allows you to overwrite the defaut options, as defined in fs.c No checks are done here, so make sure not to include non-existing options, as well as not to include any options auto-added by pmount (that is, things based on command-line options, such as atime/noatime, exec/noexec, etc)

In the end, with a simple call to pmount I can now have my LUKS encrypted partitions mounted automatically; and when I’m done one call to pumount will have them all unmounted, and the device be prepared for safe removal. I think I now have everything I was looking for.

The modified source code is available on this BitBucket repository. You can also find a PKGBUILD in the AUR, which uses the official source code and a patch to get there, simply because I figured it would allow people to check the changes more easily.

I've also made a blog post where I described changes I made a little more, if anyone's interested.

Maybe that might be useful to others; And any bug reports, suggestions or any other form of constructive criticism is very much welcome.
-jacky

Offline

#2 2012-03-23 18:05:13

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: pmount & safe removal of USB device

I've just found this and it looks interesting. Have you tried to push (some of) your changes upstream? Especially the safe removal bits (might be good to split to two patches for that)?
I'm still trying to work out how to sort out my working but unsatisfactory removable drives situation, and it may well involve this or main pmount.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#3 2012-03-23 19:48:25

jjacky
Member
Registered: 2011-11-09
Posts: 321
Website

Re: pmount & safe removal of USB device

I haven't submitted anything upstream, no. I might try and do that at some point, but as you said it would require splitting it in a few patches, and while I use this version of pmount I haven't looked at this code in a while...

Offline

#4 2012-03-24 20:35:00

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: pmount & safe removal of USB device

Fair enough, thanks for the response. Going to be a week or so before I get round to this, but I might install this version and see how it goes.
Thanks for writing it. smile


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#5 2012-05-25 07:47:04

donniezazen
Member
From: Salt Lake City
Registered: 2011-06-24
Posts: 671
Website

Re: pmount & safe removal of USB device

[donnie@arch ~]$ sudo sdparm --command=sync /dev/sdb1
    /dev/sdb1: WD        15EADS External   1.75
[donnie@arch ~]$ sudo sdparm --command=stop /dev/sdb1
    /dev/sdb1: WD        15EADS External   1.75
[donnie@arch ~]$ sudo umount /dev/sdb1
umount: /run/media/donnie/wd: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
I tried to pumount an ext4 external usb western digital 1.5TB drive. It is umounted/safely removed without error but it keeps spinning indefinitely. I am not sure if the drive is being 'safely removed'.

Thanks you so much for your work.

UPDATE-1 pumount won't work because default location is now set to /run/media/$HOME/$LABEL by udisks2

Error: mount point /run/media/donnie/wd is not below /media/
Failed to umount device /dev/sdb1 : error 4

I am trying to remove the drive safely using following method without luck.

[donnie@arch ~]$ sudo sdparm --command=sync /dev/sdb1
    /dev/sdb1: WD        15EADS External   1.75
[donnie@arch ~]$ sudo sdparm --command=stop /dev/sdb1
    /dev/sdb1: WD        15EADS External   1.75
[donnie@arch ~]$ sudo umount /dev/sdb1
umount: /run/media/donnie/wd: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

Last edited by donniezazen (2012-05-25 09:55:20)

Offline

Board footer

Powered by FluxBB