You are not logged in.

#1 2008-04-11 13:05:16

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Best way to do 'volume management'

Sure, you can edit /etc/fstab and mkdir a lot of empty dirs just in case some day a device /dev/sdr7 with jfs/zfs/... is attached through USB.

Sure, you can always fire up the CLI to mount a volume using the right parameters.

Sure you can install GNOME / KDE / thunar-volman to have these things done for you.

I am now at a stage where I want to abandon the GUI and try if I can cut it using openbox, a panel (bmpanel or fbpanel), a filemanager (pcmanfm) and some other lightweight apps. Mostly this works very well and VERY fast, but if I connect a dev via USB, an icon shows on the desktop but I cannot click it unless I mount it manually...

So I looked through the wiki, and autofs is given as a possible solution, but shouldn't HAL and udev be able to do these things on their own? Are there good manuals to set them up correctly so that I can have an automatic volume management with the least possible clutter?

Are there even more basic ways to do this without HAL and udev, because these daemons make the bootprocess rather slow... Step by step I'm trying to get to the core of linux so that one day I'm able to have the same knowledge of it as I have now about windows...

THX!

Zl.

Offline

#2 2008-04-11 13:27:45

11010010110
Member
Registered: 2008-01-14
Posts: 284

Re: Best way to do 'volume management'

I have 2 entries in fstab (sda and sda1) with permission to user to mount and rw there

mount /media/key

filesystem is vfat cause thats the only type of keys ever plugged in my box but imo auto will work too

In the really rare cases when i need something more I su and mount it manually




You may make scripts like this

/bin/k+

#!/bin/bash
mount /media/key

/bin/k-

#!/bin/bash
umount /media/key

to shorten the commands

You may add them in the panel too

Offline

#3 2008-04-12 20:21:31

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

I'm doing automounting with pure udev and standard mount command (no fstab entries needed). My rules look like this (/etc/udev/rules.d/010.udev.rules - it's important that it runs as the first rule set):

KERNEL=="sd[b-z]", NAME:="%k", SYMLINK+="usbhd-%k", GROUP:="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usbhd-%k", GROUP:="users", NAME:="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /media/usbhd-%k /mnt/usbhd-%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,async,dirsync,noexec,nodev,noatime /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /media/usbhd-%k", OPTIONS="last_rule"

The most important thing is to properly set sd[X-z] in all rules where X is the first nonfixed hard disk. In my laptop where I'm using these rules I have one hd (/dev/sda) so /dev/sdb is the "lowest" available device name for an usb device.

Also these rules can be further reduced because I'm mounting an usb device in /media and symlink it to /mnt for my convenience only. All media/mnt subdirectories are created dynamically and are deleted on unpluging event.

The first mount rule is designed specifically for vfat (fat32) devices only. It uses flush sync method which gives best performance with maximum data security. Unplugging a device without umounting it first is in this case quite safe (just wait until the led stops blinking and simply unpulg it). Umounting is done later (lazy umount to not confuse applications that might have some files/directories still opened). The second mount rule is for all other filesystems (only general options which should be supported by all of them). It's easy to add more rules for your favourite fs types with special options.

Other parameters can be changed too but don't change %k to other udev parameter because it will most probably not work (it's possible to make it work but it needs more scripting and saving device names in some external file and I wanted only pure udev rules). Also, it's possible to add more scripts (like autobackup) - just search the forums for examples.

I don't know it that's exactly what you're looking for but that's just one way of doing it and it's very "bulletproof" IMHO.

Last edited by lanrat (2008-04-12 20:28:53)

Offline

#4 2008-04-12 20:46:31

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: Best way to do 'volume management'

I use just hal. No automounting, but clicking in thunar cleanly mounts and unmounts usb sticks/external hd to /media. From command line 'pmount /dev/sdb1' (or similar, in package pmount) mounts to /media through hal.

I must admit I like lanrat's solution. But since I have hal running anyway...

Offline

#5 2008-04-12 22:26:20

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: Best way to do 'volume management'

I vote that lanrat adds that to the wiki.

Offline

#6 2008-04-13 08:54:28

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Best way to do 'volume management'

tam1138 wrote:

I vote that lanrat adds that to the wiki.

+1 !


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#7 2008-04-13 09:54:13

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: Best way to do 'volume management'

I think it's already there.

I use thunar-volman. It's a light weight solution that just works *shrug*.

It's convenient having a thunar window pop up when I plug a flash drive in, as i'm normally using a flash drive to transfer files. Then it's just drag drop.

Offline

#8 2008-04-13 13:52:18

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Best way to do 'volume management'

iphitus wrote:

I use thunar-volman. It's a light weight solution that just works *shrug*.

It's convenient having a thunar window pop up when I plug a flash drive in, as i'm normally using a flash drive to transfer files. Then it's just drag drop.

The same thing but I don't have anything pop up automatically (I have thunar bound to Win-x so I can start it easily when I need it -- it mounts things automatically though).  I also use xfce4-volstatus-icon from AUR which gives me an icon in tray when a removable volume is mounted so I can unmount it easily without starting thunar.  I also use notification-daemon-xfce for notifications about whether it is safe to remove stuff (in case something is still needs to be written to a usb stick, for example).

Offline

#9 2008-04-14 05:45:10

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

Yes, it's already in the wiki (on the bottom of the page).

My idea was to have automounting simplified as much as possible and make it "bulletproof" (especially against "bad" updates that can break other automounting solutions from time to time). It's also easy to copy it to other computers (you can simply copy rules file,  change sdX if needed and restart udev/box and it works without any other settings).
Since it doesn't need anything else to run it's a good solution for servers without running X/dbus/hal too.
There is a modification described somewhere in the forums that is using similar rules to make automatic backup copies once certain usb device is plugged in - an interesting idea.

Offline

#10 2008-04-14 05:51:52

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

fwojciec wrote:

I also use notification-daemon-xfce for notifications about whether it is safe to remove stuff (in case something is still needs to be written to a usb stick, for example).

If you're using vfat on an usb stick then (if possible) you should try changing "async"to "flush" (in fstab or other config) and it'll always be safe to unplug the device (nothing is then stored in the cache but the rw performance is still similar to the async method).

Last edited by lanrat (2008-04-14 05:52:20)

Offline

#11 2008-04-14 19:31:33

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Re: Best way to do 'volume management'

lanrat wrote:

I'm doing automounting with pure udev and standard mount command

That's what I was looking for! No need for X - all auto-mounted volumes available in init 3!

Very clean solution and again some memory saved because one less program to keep monitoring in the background...

Thx!

Zl.
PS: it is indeed in the wiki - don't know how I missed it!

Offline

#12 2008-04-14 20:26:16

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Best way to do 'volume management'

zenlord wrote:

Very clean solution and again some memory saved because one less program to keep monitoring in the background...

That sounds a bit paranoid tongue
Does it really make *that* much difference? can you feel it? If so, I'm gonna try that out big_smile


Have you Syued today?
Free music for free people! | Earthlings

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery

Offline

#13 2008-04-16 08:56:10

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Re: Best way to do 'volume management'

finferflu wrote:
zenlord wrote:

Very clean solution and again some memory saved because one less program to keep monitoring in the background...

That sounds a bit paranoid tongue
Does it really make *that* much difference? can you feel it? If so, I'm gonna try that out big_smile

Well, I would like to 'get the hang of linux' and to get it I feel I need to understand the base processes, including udev.

It is so much easier installing thunar-volman and pretend to know how it all works, but if it fails once, you'll see it will be the one time you *really* need the data on that USB-stick and people around you are looking at you, going 'so that is linux, huh? roll' )

If in that case it is just between you and udev, you firmly type 'killall udev' (or whatever) in console and people stand in awe for your greatness.

Nah, just rambling: I want to learn more about it and let me control my pc...

Zl.

Offline

#14 2008-04-16 09:03:45

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Best way to do 'volume management'

zenlord wrote:

Well, I would like to 'get the hang of linux' and to get it I feel I need to understand the base processes, including udev.

It is so much easier installing thunar-volman and pretend to know how it all works, but if it fails once, you'll see it will be the one time you *really* need the data on that USB-stick and people around you are looking at you, going 'so that is linux, huh? roll' )

If in that case it is just between you and udev, you firmly type 'killall udev' (or whatever) in console and people stand in awe for your greatness.

Nah, just rambling: I want to learn more about it and let me control my pc...

Zl.

How about HAL? you can do "/etc/rc.d/hal restart", and your friends will stand in awe too big_smile


Have you Syued today?
Free music for free people! | Earthlings

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery

Offline

#15 2008-04-16 18:01:34

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: Best way to do 'volume management'

lanrat wrote:

If you're using vfat on an usb stick then (if possible) you should try changing "async"to "flush" (in fstab or other config) and it'll always be safe to unplug the device (nothing is then stored in the cache but the rw performance is still similar to the async method).

What about wear and tear on the flash drive's lifespan, though?

Offline

#16 2008-04-17 02:03:49

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

It shouldn't be different from the normal usage at least if you're simply copying files on the stick. Flush works like async with manual sync command run at the end of copying process. If you're using async you still have to sync before umount so IMHO it's the same.
Perhaps when you are writing and changing many files on the stick before you want to umount it could be some difference. But it's just easier with flush IMHO. After all it was designed for mobile devices.

Offline

#17 2008-05-22 16:58:45

Laertes
Member
From: Munich
Registered: 2007-04-08
Posts: 66

Re: Best way to do 'volume management'

Hi lanrat, I'm trying to use your method but no fs gets mounted, only the symlinks in /dev and directories in /mnt are created. No error message whatsoever in the logs. What can be the problem?

Offline

#18 2008-05-22 17:01:13

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Re: Best way to do 'volume management'

You do have the necessary fs-packages installed?

Offline

#19 2008-05-22 17:03:16

Laertes
Member
From: Munich
Registered: 2007-04-08
Posts: 66

Re: Best way to do 'volume management'

I think so, I can mount it manually.

Offline

#20 2008-05-23 18:54:18

Laertes
Member
From: Munich
Registered: 2007-04-08
Posts: 66

Re: Best way to do 'volume management'

I've just solved it. As usual, a pretty stupid error. I used nano for writing the rules and it seems that it introduced an end line character in the middle of the long lines (the ones actually doing the mounting) so udev read these lines as two different lines.

Now it works, and it is a really simple way of automounting. Thanks lanrat! smile

Offline

#21 2008-05-25 03:14:42

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

Cool :-)
BTW line wrapping is sometimes a PITA but nano -w solves it.

Offline

#22 2008-05-25 08:05:55

Laertes
Member
From: Munich
Registered: 2007-04-08
Posts: 66

Re: Best way to do 'volume management'

I have two more questions:

- Can the CDs/DVDs mounted in a similar way? I don't think so because AFAIK no new device nodes are created when a CD is inserted.

- Is there any way to tell conky that a new fs has been mounted so it can be shown? I know that there is variable called if_mounted that checks if a given mountpoint is mounted, but if you use it on a non-existing mountpoint (in this case the mountpoint is created by udev only when a new device is plugged-in) it gives an error message. It can be done creating statically the necessary mountpoints, but then the /mnt directory will be full of empty mountpoints.

Thanks again.

Offline

#23 2008-05-25 23:53:01

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Best way to do 'volume management'

Unless something has changed since I last checked it a CD/DVD can't be mounted this way. Device nodes are created on the module load not when a cd is inserted. Also it would rather work with "ACTION" attribute I guess (something like ACTION==insert/eject).

Some time ago I was using this tiny utility to automount cdroms. IIRC I had to change "umount" to "eject" in the sources and it worked but it's quite old and not developed anymore.

The second question is interesting but I have no idea how to do that :-) I was using conky a long time ago and I don't know if there is a way to do something similar with the newest version. I guess you could try changing conky config file and reloading it from udev (as another udev rule). But this would require some assumptions (like which user/display to use) and/or more coding. However in theory at least it could be done, I think.

edit: Also if conky can run scripts inside configuration you could try to generate if_mounted commands for the whole collection of /dev/usbhd* or something like this.

Last edited by lanrat (2008-05-26 00:00:55)

Offline

#24 2008-05-26 15:26:03

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Re: Best way to do 'volume management'

For cd's / dvd's I use an 'auto-fs-line' in fstab. It does the job without any clutter and without the need for extra programs.

Sometimes I have to umount before I can eject though - I think I need to do it with movie DVD's, not with CDROM's.

Zl.

Offline

#25 2008-05-30 18:01:25

Laertes
Member
From: Munich
Registered: 2007-04-08
Posts: 66

Re: Best way to do 'volume management'

Well, finally I've switched to the Dark Side, i.e. the easy way. I'm using hal, thunar and thunar-volman. But thanks anyway lanrat, I've learned a bit about udev rules trying your way. smile

Offline

Board footer

Powered by FluxBB