You are not logged in.

#1 2006-05-02 15:37:17

barebones
Member
Registered: 2006-04-30
Posts: 235

Is udev all that is needed for automounting?

Hi All,
As soon as my new hard drive shows, I'm planning on installing Arch on it, and I was hoping to clear up some confusion before then. While i'm not necessarily a linux noob, gnome has covered up alot of stuff that I'll need to know for the switch to arch so I am pretty nooby to the stuff that happens deep down in the bowels of my computer. I've been reading around about udev, and it appears that it will handle all device recognition/automounting/ect. If so, do I need hotplug, hal, hwd, ect, ect?

Right now I am running ubuntu with fluxbox, and gnome-volume-manager takes care of automounting. This works allright, but I would much rather not install gnome along with arch. I've found plenty of articles about setting up udev, and would like to use it exclusivly if possable due to it's ease of use (the keys seem simple enough) and reliability. I am, however, a little confused as to what it actually does when something is connected to the system. Will udev actually reconize that say, a pendrive has been inserted, or does some other program take care of recognition while udev takes care of mounting? Also, I'd still like to use fstab for mounting my static HDD's at boot, does the kernel actually use this file, or do I need another program for this functionality?

Offline

#2 2006-05-03 10:48:42

FUBAR
Member
From: Belgium
Registered: 2004-12-08
Posts: 1,029
Website

Re: Is udev all that is needed for automounting?

udev doesn't automatically mount, it automatically creates the /dev nodes when it finds hardware supported by the kernel (or loaded modules).

If you don't configure your /etc/fstab properly, udev will recognize your harddisk and create the correct partition nodes (/dev/hda1, etc) but they will not be mounted at boot time.

I imagine you'll always want your swap and / partition mounted at boot time, which is a simple matter of editing /etc/fstab. For CD's, USB-sticks and similar media to be auto mounted, you can choose one of several tools.

I use AutoFS: when I enter a directory where my USB or DVD will be mounted, AutoFS tries to mount it and if it succeeds I get to see the contents. If I didn't put a DVD in the DVD-Rom, I don't get a dir listing.

I use AutoFS on my DVD's, USB pendrive, USB/FireWire external hard disk and NFS mounts and it works wonderfully well. Here's a Wiki page for instructions on AutoFS.


A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.

Offline

#3 2006-05-04 16:24:04

barebones
Member
Registered: 2006-04-30
Posts: 235

Re: Is udev all that is needed for automounting?

Thanks for your reply FUBAR. After installing arch, running into a bad fstab, and having my new install mount read-only, I've learned a little more about how udev/fstab/ect work and I'm more clear about how everything works. I'll have to check out AutoFS, I didn't read about that one while I was looking up stuff on automounting. As far as udev goes, though, I'm pretty sure it's capable of automounting partitions on its own. Check out this article. Theres no event for cd drives, but the author also mentions a solution for that.

Offline

#4 2006-05-05 07:51:27

FUBAR
Member
From: Belgium
Registered: 2004-12-08
Posts: 1,029
Website

Re: Is udev all that is needed for automounting?

I'll be damned. I had no idea udev could do that! big_smile

I don't know how it can unmount a partition tho. AutoFS automatically unmounts when a timeout is reached. When you access the partition again, it quickly remounts it without the user noticing.
How does udev know when you're about to pull out your USB-stick?


A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.

Offline

#5 2006-05-05 13:14:47

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

Re: Is udev all that is needed for automounting?

My latest udev rules for usb sticks or usb hard disks automounting (/etc/udev/rules.d/010.udev.rules):

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,sync,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,sync,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"

Mr Green reminded me about path change for vol_id which is now /lib/udev/vol_id (was /sbin/vol_id). Tnx. I've changed it in the above rules.

I have SATA hard disk in my notebook (/dev/sda) so I have to use sd[b-z] for removable media. /dev/sda is mounted normally via fstab. If you don't have any fixed sd* devices in your fstab you can use sb[a-z] everywhere.

How does udev know when you're about to pull out your USB-stick?

It doesn't :-) As you can see I'm using mount with several options like sync and dirsync and "lazy umount".
Usinc sync and dirsync sometimes slows down transfer speed but it's safer than async. Basically it saves data to the device instantly so there is little risk of losing data when you unplug usb stick.

When you first plug a device these rules create subdirectory in /media, mount every partition found on it to it's own subdirectory and make symlinks from /mnt to /media for each device/partition - this is not required but it's good to have them accessible from both /mnt and /media.

These rules can detect vfat partition and use different mount options (dmask,fmask) which allows every user to access vfat partition (read and write).
Any other partition type is mounted with general mount options.
I have an usb stick with 2 partitions: one vfat and one reiserfs. They both work well with these rules.

When you unplug the device remove event is generated, /dev/sdX is removed by udev and then the rules umount all partitions with lazy umount (which prevents the panic of applications that still have any file or directory opened from any of umounted partitions).
Next all directories in /media and symlinks in /mnt are removed.

This way all you need for automounting is udev rules (no need for fstab items etc.) and you don't need to know in advance how many partitions and what type of filesystems are used.

I'm using this for most of my linux computers and so far it works quite well. Of course it has some drawbacks (like slower speed) but for me this is clean and simple and I don't have to worry about every ivman/whatever update ;-)

Offline

#6 2006-05-05 14:28:58

FUBAR
Member
From: Belgium
Registered: 2004-12-08
Posts: 1,029
Website

Re: Is udev all that is needed for automounting?

Read this thread and get rid of sync on USB devices: it degrades performance and the life span of your USB devices.


A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.

Offline

#7 2006-05-06 16:12:06

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

Re: Is udev all that is needed for automounting?

FUBAR wrote:

Read this thread and get rid of sync on USB devices: it degrades performance and the life span of your USB devices.

But if you leave async then you can't really unplug usbstick without manual umount or sync. And if it really degrades the life span of my usbstick then it'll be a good reason to buy a new (better) one when the current fails :-)
Seriously, it all depends how you use your usbstick and how much it degrades its life span. For me it works well and my usbstick is still alive. I'm using these rules for my hard disk with usb - ide connector too.

BTW I think you can also simulate autofs periodic sync for ext3 partitions with mount commit=number_of_seconds parameter though it only works for ext3. I don't know what is the default sync time for reiserfs and other filesystems (if there is any). If there is then you can change sync to async and just wait a few seconds before unplugging the device like you do  with autofs or you can run a manual sync or something.

EDIT: If someone is using these rules please update vol_id path - details in my previous post

Offline

#8 2006-05-06 17:56:59

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Is udev all that is needed for automounting?

strange, today it worked with the old path though I have newest udev...

Offline

#9 2006-05-06 19:15:18

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

Re: Is udev all that is needed for automounting?

It's possible because vol_id is used only for vfat partitions and even if it was vfat it could still be mounted by the second general mount rule.

Offline

#10 2006-05-06 22:28:32

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

Re: Is udev all that is needed for automounting?

well, if you take a look at how other operating systems do it..
under windows it's reccomended you safely remove usb storage before removing - safely removing is so that windows can sync the disk if it needs it and unmount it.

i always thought it were simpler to pacman -S ivman and use that then mess with udev rules...

James

Offline

#11 2006-05-07 11:11:59

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Is udev all that is needed for automounting?

Sorry, I didn't get that from ivman's man: Does ivman unmount your device after some time of inactivity? If not, what's the benefit in comparison to "the udev rule"?

Offline

#12 2006-05-07 11:37:30

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

Re: Is udev all that is needed for automounting?

hellwoofa wrote:

Sorry, I didn't get that from ivman's man: Does ivman unmount your device after some time of inactivity? If not, what's the benefit in comparison to "the udev rule"?

no idea, it just works.

Offline

#13 2006-05-07 11:47:05

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Is udev all that is needed for automounting?

Well, then I would rather choose the autofs-way which unmounts the device after some time of inactivity which should be comparable to a "safe remove" in Windows...

Offline

#14 2006-05-07 11:53:22

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

Re: Is udev all that is needed for automounting?

hellwoofa wrote:

Well, then I would rather choose the autofs-way which unmounts the device after some time of inactivity which should be comparable to a "safe remove" in Windows...

wouldnt matter if a device isnt unmounted after a period of inactivity, as typically the kernel would have synced the data by then.

James

Offline

#15 2006-05-07 14:45:32

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Is udev all that is needed for automounting?

Ah ok then I missed that point. I thought it should generally be desirable to umount the dev before it gets unplugged.

How long does it usually take until the data are synced on an ordinary usb-pendrive?

I mean if I copy some files on it and see via ls that the data are completely written on it, may I already unplug it or should I wait another 10 seconds?

Offline

#16 2006-05-07 15:36:41

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

Re: Is udev all that is needed for automounting?

iphitus wrote:

i always thought it were simpler to pacman -S ivman and use that then mess with udev rules...

James

Maybe but it's nofun :-)

Offline

#17 2006-05-08 03:30:13

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: Is udev all that is needed for automounting?

hellwoofa wrote:

Ah ok then I missed that point. I thought it should generally be desirable to umount the dev before it gets unplugged.

How long does it usually take until the data are synced on an ordinary usb-pendrive?

I mean if I copy some files on it and see via ls that the data are completely written on it, may I already unplug it or should I wait another 10 seconds?

It could take longer than 10 seconds to sync, so I'd always unmount or use sync from the cli prior to pulling it out. Obviously, ls doesn't tell you if it's already been sync'ed or not.

Offline

Board footer

Powered by FluxBB