# USB hard drives randomly switch places (sda5, sdb5) reboot

## rrrssssss

Hello forum,

I installed the automounter software called aufofs to detect all of my drives and partitions and it works beautifully in Gentoo 2007.

But I am having problems with my two USB hard drives swapping places randomly on each reboot according to fdisk-l (sda5 and sdb5). This is causing me to have to frequently edit the auto.auto config file in the autofs automounter in order for the devices to once again match the folder names. I think the order of execution changes for sda5 and sdb5.

Is there a way to stabilize the order of execution of sda5 and sdb5 so they will not randomly swap places during a reboot? 

Thank you in advance,

Roy

----------

## spOOwn

Put a label on your file system ! I had the same problem once. The kernel take the first available device block.

By the way, you can always attach your usb disk in the same order to keep the same block device if you want !!

If you USB disk partition is of reiser fs type , you would type this :

```
# reiserfstune --label my_label /dev/sda5
```

and replace "my_label" with you own label, but not more than 16 character, otherwise it will be truncate.

If you got an ext3/ext2 file system on it :

```
# tune2fs -L my_label /dev/sda5
```

And in your configuration file of autoload, only specify these label, you could also UUID.

----------

## rrrssssss

Thanks sp00wn,

I was only able to create a label for one of the USB drives since only one of them has ext3. The other USB drive has NTFS.

Will this be enough to keep the devices from switching places? And if not, is there a way to create a lable for NTFS so I can have a label for both USB devices?

Thanks much,

Roy

----------

## Akkara

I think there's a way using udev to always give the devices the same names, in case you can't label your ntfs partition.  I don't know udev well so alas I can't help further, except to suggest this as a place to look.

----------

## spOOwn

One device wouldn't switch anymore, if you always use the label ( or UUID ) to mount the partition. But the other one could...

It is also possible to put a label on a device with a NTFS file system.

Let's first check if your ntfs device has perhaps already a label : 

```
 # ntfslabel /dev/sda 
```

if it returns something, this is the label of your ntfs device. Otherwise, you can put your own label with :

```
 # ntfslabel /dev/sda my_own_label
```

----------

## rrrssssss

I used ntfslabel from the ntfsprogs package to create a new label for the ntfs USB hard drive but it will not mount using the new label.  The command I used to create the label is ntfslabel /dev/sdb5 new-label. I then substituted /dev/sdb5 for LABEL=new-label.

I verified the new label worked by the command ntfslabel /dev/sdb6 and it showed the new label correctly.

The only way to get the ntfs USB HD to mount is to revert back to the old way, /dev/sdb5.

Am I forgetting to do something? The new label works fine for the ext3 USB HD but it will not work for the ntfs USB HD.

Thanks in advance,

Roy

----------

## rrrssssss

If I try to mount /dev/sdb5 in the /mnt directory using the label by typing "mount LABEL=my-label /mnt", I get a message saying "mount: special device LABEL=label does not exist".

But when I type "ntfslabel /dev/sdb5", it says the label is "my-label".

So one says it exists and the other says it does not exist.

I'll keep trying.

Roy

----------

## clpalmer

Try mounting by UUID. You can find the UUID of mounted partitions with blkid (or vol_id -u <device>). Mount all your partitions, run blkid to get the UUID's and then replace the /dev/* in your fstab with UUID=<uuid>.

----------

## rrrssssss

The command vol_id was not recognized in my copy of Gentoo but this command was: /bin/ls -lF /dev/disk/by-uuid/ which gives the uuid of /dev/sdb5 as 5600175F00174581  . But I have already tried using that and it didn't work unless I used the wrong format (see below).

Keep in mind that this is for automount (autofs) which does not require any entries in fstab for it to work. Instead, I have to edit the auto.auto file in the /etc/autofs directory. It creates each folder (such as hda-five) on the fly as each drive mounts and the folders disappear when it unmounts.  It looks like this:

hda-five        -fstype=ext3            :/dev/hda5

hda-six         -fstype=ext3            :/dev/hda6

hda-seven       -fstype=ext3            :/dev/hda7

hda-eight       -fstype=ext3            :/dev/hda8

hda-nine        -fstype=ext3            :/dev/hda9

hda-ten         -fstype=ext3            :/dev/hda10

hda-eleven      -fstype=ext3            :/dev/hda11

hda-twelve      -fstype=ext3            :/dev/hda12

secondHD        -fstype=ntfs,ro,sync,umask=0022            :/dev/hdb5

secondHD2         -fstype=auto,sync         :/dev/hdb6

usb-ext3       -fstype=auto,sync           :LABEL=roylabel

usb-ntfs        -fstype=ntfs,ro,sync,umask=0022         :LABEL=roy-label

card-reader        -fstype=auto,sync          :/dev/sdc1

Every drive works perfectly except the usb-ntfs line which is /dev/sdb5.

Maybe I typed the uuid incorrectly in the next to the last line for :LABEL. I tried :UUID= 5600175F00174581  which didn't work. I also tried :LABEL=UUID= 5600175F00174581 which didn't work either. 

The funny thing about this is that I can boot into another Linux disribution such as Linux Mint (I have a multi-boot configuration) and the problem drive, sdb5 shows up on the desktop as "roy-label" And it works!. So I think the lable scheme must be working for it to show up there.

But I'll keep trying. 

If you can think of any tid bits of information to interject, please do.

Roy

----------

## jcat

If you're having trouble with labels, why not use a udev rule to persistently name the devices as you prefer.

Take a look at these guides.

http://www.reactivated.net/writing_udev_rules.html

and

http://webpages.charter.net/decibelshelp/LinuxHelp_UDEVPrimer.html

Cheers,

jcat

----------

## rrrssssss

Hello forum,

I solved my problem.

I simply upgraded to the latest version of hal (and its dependencies) and decided to let hal detect my drives and partitions instead of autofs PLUS hal recognizes my labels too. Autofs still can't see my label for NTFS and I still can't mount the label using the mount command in a terminal window. As long as I let hal do the mounting instead of autofs, my labels are recognized and everything works fine.

Hal will also mount all of the drives and partitions even with the proper permissions to the "root owned" USB NTFS hard drive, which is something the older version of hal could not do (Gentoo 2007 CD).

Since Hal is doing such a fine job automounting everything, I don't have any more use for autofs. The only reason I went to autofs is because the lower version of hal was doing such a poor job doing the mounting itself. It didn't mount my partitions and my USB NTFS hard drive could only be accessed as root.

Somebody is doing some mighty fine work writing code for Linux!

Thank you all for your responses,

Roy

----------

