LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Tricky automount of USB HDU - udev is tough! (https://www.linuxquestions.org/questions/linux-hardware-18/tricky-automount-of-usb-hdu-udev-is-tough-388487/)

laan97ac 12-01-2005 10:10 PM

Tricky automount of USB HDU - udev is tough!
 
Here is a tricky example of automounting an External USB HDU.

The USB HDU used to be NTSF but via mandriva diskdrake I changed it to ext3 (one partition 80 GB) in order to get read/write access. During format, diskdrake asks where to mount and I gave /mnt/sda1 as folder. But I am not sure it plays well with udev, read on:

During boot up, the system gives me the following when mounting partitions:
Mounting special device /mnt/sda1 failed, device not present (if not plugged in) But it should not mount at all if not plugged in. Is that not the whole point of udev?

The mount line /dev/sda1 is still present in media:/ and /etc/fstab even when unplugged

When plugged in, only root can write to it and that was not what I wanted – all users should write to it.

I must have somehow mounted it as a fixed harddrive and not a “portable” one for hotplugging.

While in diskdrake, I could not choose to mount as Supermount – only “No supermount.” System would accept setting it to supermount but when going out of the menu and back in, “No Supermount” would show up again.

Mount command (when unmounted)

[root@localhost laan97ac]# mount
/dev/hda5 on / type ext3 (rw,noatime)
none on /proc type proc (rw)
none on /proc/bus/usb type usbfs (rw)
none on /sys type sysfs (rw)
/dev/hda7 on /home type ext3 (rw,noatime)
/dev/hda1 on /mnt/windows type ntfs (ro,umask=0022,nls=iso8859-1)

fstab regardles of whether disk is plugged or unplugged:
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/hda5 / ext3 noatime 1 1
/dev/hda7 /home ext3 noatime 1 2
/dev/hdb /mnt/cdrom auto umask=0022,user,iocharset=iso8859-1,codepage=850,noauto,ro,exec,users 0 0
/dev/sda1 /mnt/sda1 ext3 noatime 0 0
/dev/hda1 /mnt/windows ntfs umask=0022,nls=iso8859-1,ro 0 0
none /proc proc defaults 0 0
/dev/hda6 swap swap defaults 0 0

I am running Mandriva 2006 on a new HP laptop. Mandriva 2006 runs udev and fstab-sync. I know that udev is supposed to create /mnt/sda1 on the fly as it is plugged in. I formatted the drive USB drive via diskdrake and as part of the formatting process it asks for where to mount. Now how can I format the drive via diskdrake and have it work via udev and fstab/sync?

Bottomline, how can I make this /dev/sda1 ex3 a drive that is automounted and setup via udev on the fly?

Electro 12-01-2005 11:19 PM

Instead of
/dev/sda1 /mnt/sda1 ext3 noatime 0 0

use
/dev/sda1 /mnt/sda1 ext3 noatime,rw,users,noauto 0 0

All you need to do is type mount /mnt/sda1 after you connect the USB device. I recommend you do not add line for USB storage devices in /etc/fstab because USB devices will use certain nodes if sd is not unloaded when you remove the USB device. It is best to setup sudo for certain users and have them mount it manually.

laan97ac 12-02-2005 05:40 AM

thanx,
Due to fstab-sync I cannot manually make changes to /etc/fstab.

How would I then disable fstab-sync?

bigrigdriver 12-02-2005 07:17 AM

You have to decide which you want: mount to the device and mount point specified in /etc/fstab, or let udev create the mount point when the device is plugged in. If there is a mount point specified, and other files have not been edited/created to tell udev to use that mount point, you will get an error message during boot-up.

To use fstab to specify the mount point, you must edit /etc/sysconfig/hotplug to add this line: HOTPLUG_MOUNT_TYPE="fstab". You should also have these lines in that file: HOTPLUG_DO_MOUNT="yes" and HOTPLUG_MOUNT_SYNC="synchronous". That last one will slow things down a bit because writes to disk take place immediately. You could also use asynchronous, which is faster. But, if you shut down the device improperly, you risk loosing anything not written to disk at the time of disconnect.

If you want udev to automount the device and create the mount point, you don't need anything in fstab. When the device is mounted, it will show up in /etc/mtab.

For that to happen, you need to edit/create /etc/udev/rules.d/10-local.rules to add a line like this: BUS="scsi" ID="1:0:0:0" DRIVER="sd" SYSFS(vendor)="Maxtor" SYSFS(model)="OneTouch II" NAME(all_partitions)="usbdisk%n"
That's my entry for my Maxtor external drive connected to the usb port. To find out what you need to put in that line, from the command line, run 'udevinfo -a -p /sys/block/sdb | tee udevinfo.txt' (where sdb is the device used on my system. change it to sda if that's where your device is connected). Then read the txt file; section BUS=scsi. Note: you cannot mix parameters from different sections of that file. All the entries in that line must come from the same section.

Now, with that file done, next edit /etc/sysconfig/hotplug: HOTPLUG_MOUNT_TYPE="subfs" to tell udev to create the mount point on the fly (instead of using fstab).

Then edit /etc/sysconfig/kernel and change this line: MODULES_LOADED_ON_BOOT="". Add the kernel modules you need between the quotes, separated by whitespace.

bigrigdriver 12-02-2005 07:19 AM

You have to decide which you want: mount to the device and mount point specified in /etc/fstab, or let udev create the mount point when the device is plugged in. If there is a mount point specified, and other files have not been edited/created to tell udev to use that mount point, you will get an error message during boot-up.

To use fstab to specify the mount point, you must edit /etc/sysconfig/hotplug to add this line: HOTPLUG_MOUNT_TYPE="fstab". You should also have these lines in that file: HOTPLUG_DO_MOUNT="yes" and HOTPLUG_MOUNT_SYNC="synchronous". That last one will slow things down a bit because writes to disk take place immediately. You could also use asynchronous, which is faster. But, if you shut down the device improperly, you risk loosing anything not written to disk at the time of disconnect.

If you want udev to automount the device and create the mount point, you don't need anything in fstab. When the device is mounted, it will show up in /etc/mtab.

For that to happen, you need to edit/create /etc/udev/rules.d/10-local.rules to add a line like this: BUS="scsi" ID="1:0:0:0" DRIVER="sd" SYSFS(vendor)="Maxtor" SYSFS(model)="OneTouch II" NAME(all_partitions)="usbdisk%n"
That's my entry for my Maxtor external drive connected to the usb port. To find out what you need to put in that line, from the command line, run 'udevinfo -a -p /sys/block/sdb | tee udevinfo.txt' (where sdb is the device used on my system. change it to sda if that's where your device is connected). Then read the txt file; section BUS=scsi. Note: you cannot mix parameters from different sections of that file. All the entries in that line must come from the same section.

Now, with that file done, next edit /etc/sysconfig/hotplug: HOTPLUG_MOUNT_TYPE="subfs" to tell udev to create the mount point on the fly (instead of using fstab).

Then edit /etc/sysconfig/kernel and change this line: MODULES_LOADED_ON_BOOT="". Add the kernel modules you need between the quotes, separated by whitespace.

One last thing. When done, reboot to see if it works. Check /var/log/boot.msg and /var/log/messages to see what's going on during boot, device detection, and module loading.

laan97ac 12-02-2005 08:00 AM

bigrigdriver,

thanx, I will try as soon as I get in front of the box.

YES, my goal is to let udev take care of mounting and setting up the device - again, with read/write access for all users

Only thing I am still unclear about is how I take the /dev/sda1 line away from my current /etc/fstab since it is now controlled by fstab-sync. I think I should remove that line so that udev can create it from now on whenever the device is plugged in?
I would like to keep fstab-sync, but now that I need to remove the line in order to let udev take care of (following your instructions) how do I delete /dev/sda1 from fstab?

bigrigdriver 12-02-2005 09:29 AM

Check the man page for fstab-sync. There is an option: fstab-sync --remove=UDI, where UDI is a HAL unigue device identifier. I don't know what that is, but supposedly you can use that command to edit /etc/fstab.


All times are GMT -5. The time now is 06:47 PM.