Persistent USB Drive mounting

Hi All.

This issue has been bugging me for weeks, and although I think I know what I need to do to solve it, the scripted solution has me beat!

I have openSUSE 11.1 (i586), Linux 2.6.27.23-0.1-pae i686, 4.1.3 (KDE 4.1.3) “release 4.10.4”.

I have 2 internal IDE drives, and an external USB Disk (IDE) which is partitioned as seen below.

One of the partitions (shown below as sdh5) contains my music.

I only switch this drive on (power supply) when I’m planning on listening to music or working, as pretty much everything else I use is located on the internal drives.

The problem I’'m having is that if I decide to switch this on before boot it’s all ok, but if I switch on after boot it won’t mount. The device Path/ID is changing with boot/mount sequence, which is messing me up. It changes from sdg5 to sdh5 whether it’s powered pre or post boot.

What I want is it automounted at boot if it’s switched on, but if not, I want it to mount automatically when it’s switched on or ‘hotplugged’ after boot.
I want it to automount as Amarok’s library has to rescan if it tries to access it whilst unmounted, and then it takes about 30 minutes to rescan all my music!

I’ve been reading for a few days, and tried allsorts of stuff with fstab entries, and tried symlinking the device uuid with a udev rule, but with no success, which is probably down to my syntax!
I’ve also been trying to find a script called ‘Devlabel’, but have struggled with dependencies for SuSE 11.1.

If anyone could halp me with help, settings or a script to manage what I’m trying to achieve, it’d be very much appreciated.

My uuid list is:

Beth@dhcppc0:~> ls -l /dev/disk/by-uuid/
total 0                                 
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 3a9941f4-a58b-4de2-bfef-bcf20ba3fe60 -> ../../sda7
lrwxrwxrwx 1 root root 10 2009-06-22 19:19 40A7D9FB2FCF437F -> ../../sdh5                    
lrwxrwxrwx 1 root root 10 2009-06-22 19:19 43CA39AF550207FD -> ../../sdh8                    
lrwxrwxrwx 1 root root 10 2009-06-22 19:19 65ED15A038107692 -> ../../sdh6                    
lrwxrwxrwx 1 root root 10 2009-06-22 19:19 72a861f9-86c8-49e9-b0e9-08df13fb367a -> ../../sdh1
lrwxrwxrwx 1 root root 10 2009-06-22 19:19 72BE30B6BE307527 -> ../../sdh7                    
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 96f83de1-43dd-46ee-b2a8-ebb60febe2f2 -> ../../sdb1
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 c6afda7e-e1a0-483a-85e9-4b529b12cc24 -> ../../sda5
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 CAE07794E077858B -> ../../sdb2                    
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 CC6C41256C410BA0 -> ../../sda1                    
lrwxrwxrwx 1 root root 10 2009-06-22 20:17 d6fd03f3-9efe-4a39-94b8-8706714e0dda -> ../../sda6
Beth@dhcppc0:~>

my device list is:

dhcppc0:/home # fdisk -l      

Disk /dev/sda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa73e3802

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        2422    19454683+   7  HPFS/NTFS
/dev/sda2   *        2423        4865    19623397+   f  W95 Ext'd (LBA)
/dev/sda5            2423        2684     2104483+  82  Linux swap / Solaris
/dev/sda6            2685        3612     7454128+  83  Linux
/dev/sda7            3613        4865    10064691   83  Linux

Disk /dev/sdb: 122.9 GB, 122942324736 bytes
255 heads, 63 sectors/track, 14946 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xdc04a2d2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        4493    36089991   83  Linux
/dev/sdb2            4494       14947    83966976    7  HPFS/NTFS
Partition 2 does not end on cylinder boundary.

Disk /dev/sdh: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a3557

   Device Boot      Start         End      Blocks   Id  System
/dev/sdh1               1       12859   103289886   83  Linux
/dev/sdh2           12860      121601   873470115    5  Extended
/dev/sdh5           12860       38483   205824748+   7  HPFS/NTFS
/dev/sdh6           38484       95978   461828556    7  HPFS/NTFS
/dev/sdh7           95979      106304    82943563+   7  HPFS/NTFS
/dev/sdh8          106305      121601   122873121    7  HPFS/NTFS
dhcppc0:/home #

Look at the post boot situation: suppose it mounts at this location if you power it on after it boots: /path_to/directoryxyz.

OK, here’s how to make it mount to that directory if it’s powered on pre-boot. Make an executable shell script called “fixmount.sh” containing these lines:

#!/bin/sh
umount /dev/sdg5
mount /dev/sdg5 /path_to/directoryxyz

or if it’s an NTFS partition, you’d use this:

#!/bin/sh
umount /dev/sdg5
ntfs-3g /dev/sdg5 /path_to/directoryxyz

Then make a root crontab entry with this entry:
@reboot /path_to/fixmount.sh

Here’s a tutorial on crontab/cron: HowTo Use Cron Tables (Crontab) in Suse / openSUSE
remember, make the crontab entry for root.

I did not read all your details, but persistant mounting is much easier by using any of the /dev/disk/by-… device special files rather then the /dev/sd… ones. Both in your /etc/fstab and elsewhere.

Bethybabes wrote:

> What I want is it automounted at boot if it’s switched on, but if not,
> I want it to mount automatically when it’s switched on or ‘hotplugged’
> after boot.

I agree with hcvv’s advice.

Just give the device a “label” or mount it “by-id” or “by-uuid” and define a
mount point in /etc/fstab.

That should do the trick.

Greetings,


Camaleón

Thankyou for your replies, It dawned on me last night that I may be thinking in the wrong area for a solution to this, to add to my information, if I delete all entries in fstab relating to this partition, it manually mounts fine, but DOESN’T automount at boot.

Can I add a script to the hotplug system to automount this on detection rather than achieving this through fstab? How would that relate to a fixed mount point?

In answer to your replies.

Thanks HCW & Camaleón.

I did try that in fstab, but got the same symptom, must I select a universal setting for fstab, and mount ALL drive/Partitions like this, as I simply changed the ‘Mount by ID’ of that one partition when I was experimenting.
Also, how does that work with ‘automounting on detection’? This is something I really wanted to achieve for this one partition.

**HCW: **

Both in your /etc/fstab and elsewhere.

This might be the issue, is there anywhere else that a USB device gets parameters for mounting etc? I have only been changing fstab parameters in my attempts to fix this.
Should I be changing some other script somewhere?

I have posted my current fstab below, this fstab works ok for when I switch on the drive pre-boot, but when I switch on post-boot I get errors.

If I delete the entry for

/dev/disk/by-id/usb-ST310003_33AS_9E1DAFFFFFFF-0:0-part5 /media/Music         ntfs-3g    user,users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

then it mounts perfectly pre or post boot, BUT doesn’t auto mount at boot, I have to manually mount it.

Swerdna I’m going to try your suggestions later when I get home from work, thankyou.

/dev/disk/by-id/ata-ST340823A_5EF05VE9-part5 swap                 swap       defaults              0 0
/dev/disk/by-id/ata-ST340823A_5EF05VE9-part6 /                    ext3       acl,user_xattr        1 1
/dev/disk/by-id/ata-ST340823A_5EF05VE9-part7 /windows/D           ext3       acl,user_xattr        1 2

/dev/disk/by-id/ata-ST340823A_5EF05VE9-part1 /windows/C           ntfs-3g    users,gid=users,fmask=133,dmask=002,locale=en_US.UTF-8 0 0
/dev/disk/by-id/ata-Maxtor_6Y120L0_Y40XAPNE-part1 /home           ext3       acl,user_xattr        1 2                                         0 0
/dev/disk/by-id/ata-Maxtor_6Y120L0_Y40XAPNE-part2 /windows/E           ntfs-3g    users,gid=users,fmask=133,dmask=002,locale=en_US.UTF-8 0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
/dev/disk/by-id/usb-ST310003_33AS_9E1DAFFFFFFF-0:0-part5 /media/Music         ntfs-3g    user,users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

First allow me to refer to: SDB:Basics of partitions, filesystems, mount points - openSUSE.

During the conception of this page we found out that the automounting using HAL has some weak points, some of them you are aware of now.

I think I personaly would try to use udev rules to solve your problem and avoid HAL.

Alternative:
IIRC, Hal will not (auto)mount when there is an fstab entry for the device. So having the fstab entry will mount it correctly on boot (when available). It will then not mount on plugin, but a crontab entry running every one (or five) minutes (along swerdna’s lines) would help here. Even a simple:

*/1 * * * *   mount -a >/dev/null 2>&1

sounds primitive, but would work.

Bethybabes wrote:

> I did try that in fstab, but got the same symptom,

This is strange as all partitions defined in /etc/fstab must be mounted at
boot, unless “noauto” option is specified.

Review you “/var/log/boot.msg” file or just “dmesg” to find any errors
related to this.

Maybe you are facing a permission problem :-?

BTW, better do not use a mount point under /media as that is mainly used for
non-static hotplugged mounted devices. Just create a mount point under your
user’s home directory, for instance “/home/your_username/Music”.

and adjust “/etc/fstab” file accordingly, i.e.:


/dev/disk/by-id/usb-ST310003_33AS_9E1DAFFFFFFF-0:0-part5 /home/your_username/Music
ntfs-3g user,users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

Greetings,


Camaleón