503 Service Unavailable

2009-02-18

New project was born: halrv

Filed under: Software — rg3 @ 20:30

Some days ago I started a new small project called halrv. It is a very simple Python script that allows you to manage removable volumes from the command line using HAL. This would be a command line equivalent of the typical GUI programs that let you do the same thing. In modern desktops, when you plug a USB memory stick in your computer, you get a dialog asking you if you want to open its contents on an explorer window, and they also put an icon in your desktop for similar purposes. You can see which devices are connected to your computer by looking at your desktop. If you click on the icon, an explorer window opens showing its contents, and maybe the device was mounted in the way. When you’re done, you close the window and right-click on the device icon, and then you select the option to “safely remove” the device.

However, if you don’t run X or if you run a minimalistic desktop environment or window manager like fluxbox chances are, as a user, you don’t have any program running to do the same trick. Many times these users run their systems with a few static entries on the /etc/fstab file to perform this operation. Now you can do the same from the command line using HAL, hence only needing to be part of the “plugdev” group. No need for static entries in /etc/fstab. Some of you may be thinking “didn’t this type of program exist already?”. Maybe it did, but I didn’t find any other than pmount-hal, and it wasn’t working when I downloaded a copy (I wasn’t able to mount my memory stick and the error message appeared in several Google search results that didn’t give me a solution). You can still use plain pmount instead of pmount-hal, but then you are not using HAL and lose the advantages of it. You have to create a pmount config file where you whitelist devices that users can mount with it. In practice this works well, like static /etc/fstab entries. However, HAL is more flexible and, if you can use it, why not use it? Why not use the same service many desktop environments are using?

So here we go with halrv. In a mere 300 lines script, with short functions and commented code, you can have the following functionality, similar to a GUI and following the same steps:

$ # I am part of the plugdev group
$ groups
users lp audio video cdrom plugdev power
$
$ # Let's see which removable volumes are present
$ halrv
Device      Label       UUID                                  Mount point
$ 
$ # None, the table is empty
$ # I plug my SanDisk memory stick, labeled "SANDISK", and wait a few seconds
$ # ...
$ # Let's check again
$ halrv
Device      Label       UUID                                  Mount point
/dev/sdb1   SANDISK     4026-23C0
$ # There we go! So let's mount it
$ 
$ halrv mount /dev/sdb1
/dev/sdb1 mounted on /media/SANDISK
$ 
$ # Great! Let's see the contents
$ ls /media/SANDISK
sz3fen.pdf*
$ 
$ # And let's see how HAL mounted the device
$ mount
/dev/sda3 on / type ext4 (rw,relatime,barrier=1,data=ordered)
/proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
none on /proc/bus/usb type usbfs (rw)
/dev/sda4 on /boot type ext2 (rw)
none on /dev/shm type tmpfs (rw,noexec,nosuid,nodev)
/dev/sdb1 on /media/SANDISK type vfat (rw,nosuid,nodev,uhelper=hal,uid=1000)
$ # You can see the last entry above
$ 
$ # Now let's unmount it and eject the device (safely remove)
$ halrv eject /dev/sdb1
$ # No error messages, which is a success
$ # Let's confirm it
$ 
$ mount
/dev/sda3 on / type ext4 (rw,relatime,barrier=1,data=ordered)
/proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
none on /proc/bus/usb type usbfs (rw)
/dev/sda4 on /boot type ext2 (rw)
none on /dev/shm type tmpfs (rw,noexec,nosuid,nodev)
$ halrv
Device      Label       UUID                                  Mount point
$ 
$ # The device has been unmounted and ejected!

Apart from the basics above, the program also uses a personal config file (per user) where you can put specific mount options for some filesystems or even per-volume identified by its UUID. I’d say it’s quite flexible and useful. I hope you think the same. Don’t forget to try it and report back any problems or bugs you find!

Advertisements

2 Comments »

  1. For the same purpose I discovered month ago this little program:
    http://sourceforge.net/projects/hmount/
    It works fine with all usb-storage devices, but lacks support for CD/DVDs. How is halrv acting on these kind of removable devices?
    Mounting optical discs is one of the two reason to start up konqueror under fluxbox (the other reason is because konqueror is nice for “scping”, but that is another story ;-).

    Comment by goj — 2010-04-14 @ 22:29 | Reply

    • I suppose that depends on how you set up HAL or if HAL supports that. All operations in halrv are performed through HAL, and there’s no intention to change that.

      On the other hand, while a CD or DVD drive can contain removable media like a disc, the drive itself is always present unless you have a removable CD or DVD drive, so it’s absolutely no trouble to set up an fstab entry for it, just like you set up fstab entries for your disk partitions. The “auto” filesystem type provides flexibility regarding the file system in the disc itself, which is usually “iso9660” anyway.

      Comment by rg03 — 2010-04-17 @ 18:29 | Reply


RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: