# (SOLVED)How do I use a fixed address in fstab for harddrives

## Kasumi_Ninja

Lately Linux habit of randomly renaming the various /dev/sd* is driveing me nuts. Currently I even have problems booting because the name of my root partition is constantly switching between sdc2 and sdg2   :Confused: 

I remember fro my opensuse days that it is possible use a fixed address for your fstab entries. I wonder if this is also possible in Gentoo and if so how can I apply this?

----------

## NeddySeagoon

Aniruddha,

You can use LABEL= or UUID= but the patch to make that work needs an initrd.

I don't think you can use udev to rename root because it would need to run before root was mounted, which is tricky without an inirrd

You can use udev to rename things after root is mounted but if root moves around, its a little late then

----------

## Kasumi_Ninja

 *NeddySeagoon wrote:*   

> Aniruddha,
> 
> You can use LABEL= or UUID= but the patch to make that work needs an initrd.
> 
> I don't think you can use udev to rename root because it would need to run before root was mounted, which is tricky without an inirrd
> ...

 

I have a initrd (though genkernel) so that shouldn't be problem, where can I find more info about using this feature?. In the meantime I have a serious problem; I can't boot   :Shocked: .

I couldn't boot because root changed from sdc2 to sdb2, I changed fstab accordingly and rebooted. It failed to boot since the root partition was now on sdc2   :Shocked:   :Shocked:   :Shocked: 

----------

## gerard27

If you have a livecd the solution is simple.

Mount your /boot hd-partition to a directory

then open /grub/grub.conf and change it to the new hd.

Gerard.

----------

## NeddySeagoon

Aniruddha,

I know of the method and that you can find your uuids in /dev/disk/by-uuid

How you use that information in grub.conf and /etc/fstab, I'm not sure.

Other distros do it, have a peek at their sites.

The genkernel initrd supports labels and uuids, thats a snippit I picked up here in the last few days.

My raid sets don't seem to have uuids :(

----------

## Kasumi_Ninja

 *Gerard van Vuuren wrote:*   

> If you have a livecd the solution is simple.
> 
> Mount your /boot hd-partition to a directory
> 
> then open /grub/grub.conf and change it to the new hd.
> ...

 

That's what I did but the device name kept changing (from sdc to sdg to sdb)...

----------

## gsoe

I'm quite annoyed at the UUID using distros because I keep about ten partitions to try out other distros when they come up with new editions, so I have changing UUID's everytime I install a new distro. That's making a lot of the other distros unbootable....

Anyway the problem here is the opposite, here's a snippet from mandriva's fstab:

```
# Entry for /dev/sda10 :

LABEL=Mandriva / ext3 noatime 1 1

...

...

# Entry for /dev/sda6 :

UUID=0a4bc37e-8aa4-40c0-81d8-bf7778c15a23 /media/hd4 reiserfs noauto 1 2

...
```

and this is from grub.conf:

```
title linux

kernel (hd0,9)/boot/vmlinuz BOOT_IMAGE=linux root=LABEL=Mandriva resume=/dev/sda3

initrd (hd0,9)/boot/initrd.img

```

The UUID's are there automagically, as mentioned you find them in /dev/disk/by-uuid. I don't know about labels, you might have to set them yourself. Hope this is a help, good luck.

Anyway, how come your devicenames are changing? Unless you change hardware that shouldn't happen I think...  Do you have both the old and new SATA drivers enabled in the kernel?

----------

## Kasumi_Ninja

 *gsoe wrote:*   

> I'm quite annoyed at the UUID using distros because I keep about ten partitions to try out other distros when they come up with new editions, so I have changing UUID's everytime I install a new distro. That's making a lot of distros unbootable....
> 
> Anyway the problem here is the opposite, here's a snippet from mandriva's fstab:
> 
> ```
> ...

 

Thanks for the help! I managed to adjust my fstab using uuid  and my system boots fine  :Smile:   :Smile:   :Smile: . To find the unique volume identifier use the following command (substitute /dev/sda with your drive):

```
# vol_id -u /dev/sda
```

How do UUID's work with removable media like usb stick? Since initrd is used I wonder if you have to plugin the usb stick at boot, or is it hot-plugable?

----------

## NeddySeagoon

Aniruddha,

UUIDs are fixed at file system create time. They are ok with removable devices

----------

## yabbadabbadont

I have my Gentoo system converted to using UUID for everything.  Here are my fstab and grub.conf files in case it helps.

/etc/fstab:

```
UUID=90B5-E9EB                             /mnt/windows  vfat         utf8,umask=007,gid=users,quiet              0 2

UUID=5e7ca13e-5fce-4477-a967-68c2213a8d74  /boot         ext3         noauto,noatime                              0 3

UUID=174c42d0-10cd-436d-aa0d-d94bbe062a3e  /             ext3         noatime                                     0 1

UUID=0c400f84-71f7-4faf-8229-39417ef34b39  /home         ext3         noatime                                     0 4

UUID=53106d93-9666-4fb1-8177-01cb23930d55  /mnt/backup   ext3         noatime                                     0 5

UUID=2eacc7c6-729a-46a8-a6f9-8cd1b148a411  /mnt/music    ext3         noatime                                     0 6

UUID=0b1639fd-e7c6-4a2f-a163-3258ce26dc8b  /mnt/video1   ext3         noatime                                     0 7

UUID=5c4dce4d-83ee-419b-a770-18fea9c83359  /mnt/video2   ext3         noatime                                     0 8

UUID=ef102bc3-f432-48fc-9bfe-c0fe27cb35fc  /mnt/images   ext3         noatime                                     0 9

UUID=4830c333-6657-4a91-b8b2-551cc88d4fe4  none          swap         sw                                          0 0

```

/boot/grub/grub.conf:

```
default 0

timeout 10

color cyan/blue white/blue

title Gentoo 2.6.25-gentoo-r6

root (hd0,1)

kernel /bzImage-2.6.25-gentoo-r6 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=UUID=174c42d0-10cd-436d-aa0d-d94bbe062a3e vga=775 udev quiet

initrd /initramfs-genkernel-x86-2.6.25-gentoo-r6

title Windows

rootnoverify (hd0,0)

makeactive

chainloader +1

title Poweroff

halt

```

----------

## gsoe

 *Quote:*   

> How do UUID's work with removable media like usb stick? Since initrd is used I wonder if you have to plugin the usb stick at boot, or is it hot-plugable?

 Well, I don't know. I suppose that it's hot-pluggable and that hal takes care of things, but I'll reboot into mandriva and try it out. Just a minute...

Is your problem that you get different devicenames when you boot with a plugged usb-stick compared to when you don't?

----------

## Kasumi_Ninja

 *gsoe wrote:*   

>  *Quote:*   How do UUID's work with removable media like usb stick? Since initrd is used I wonder if you have to plugin the usb stick at boot, or is it hot-plugable? Well, I don't know. I suppose that it's hot-pluggable and that hal takes care of things, but I'll reboot into mandriva and try it out. Just a minute...
> 
> Is your problem that you get different devicenames when you boot with a plugged usb-stick compared to when you don't?

 

Coming to think of it, that was another major problem I encountered with my 'regular' fstab. Every I left a usb device plugged during boot it didn't boot (since the usb stick messed up the device numbering). 

Coming to think of it, do I have to adjust my grub.conf (especially the real_root line)? My grub.conf:

```
# cat /boot/grub/grub.conf

# Which listing to boot as default. 0 is the first, 1 the second etc.

default 0

# How many seconds to wait before the default listing is booted.

timeout 5

# Nice, fat splash-image to spice things up :)

# Comment out if you don't have a graphics card installed

#splashimage=(hd0,1)/boot/grub/splash.xpm.gz

title=Gentoo Linux (2.6.25-gentoo-r6)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.25-gentoo-r6 real_root=/dev/sdc2 

initrd /boot/initramfs-genkernel-x86-2.6.25-gentoo-r6
```

----------

## yabbadabbadont

 *Aniruddha wrote:*   

> Coming to think of it, do I have to adjust my grub.conf (especially the real_root line)? My grub.conf:

 

See my previous post for a working example after which you can pattern yours.   :Very Happy: 

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

>  *Aniruddha wrote:*   Coming to think of it, do I have to adjust my grub.conf (especially the real_root line)? My grub.conf: 
> 
> See my previous post for a working example after which you can pattern yours.  

 

Oops, I overlooked that entry,  thanks!

----------

## gsoe

The UUID part seems solved, but I'm quite puzzled by your changing devicenames. I've tried rebooting mandriva (and Gentoo) a couple of times now with and without a plugged usb-stick. It doesn't affect devicenames. I have /dev/sda and /dev/sdb hard drives and the stick allways shows as /dev/sdc. However I did experience once, that by adding a third harddrive, the former /dev/sda and /dev/sdb changed... Does anybody have useful info? 

Mandriva simply doesn't mount the plugged stick at boot, but when it's mounted, it's always /dev/sdb (there's no mounting of my /dev/sdb harddrive in fstab). I get this

```
[gert@localhost ~]$ ls /dev/disk/by-uuid/

0a4bc37e-8aa4-40c0-81d8-bf7778c15a23@  47E0-17A3@

0a4be4e4-6fd6-44a3-b878-f1cebc9d347b@  69cdd8ef-e37a-4d74-9b71-1feabb513a1b@

10F08273F0825F3A@                      89cd7e0f-98eb-4c20-9711-c081aa9a549e@

12affa1b-e0f1-42bd-9c0b-b61ddb69fc7c@  8b4c45e6-de6c-4930-b065-57fd6e087c57@

1552358b-23bd-4a40-9802-595872034f9a@  ba072c66-f0d1-4f11-8dd8-c49e455ca675@

1c04fea6-1780-450b-bbe6-c11c6bdea9ed@  be836e7c-8dd0-4025-ac7f-dae61bad4fc7@

2e7e35fa-2d65-42bb-9fbf-7fa193245b24@  da81878c-da56-421e-8801-e42a024c2cea@

2f00fced-49fe-4beb-a0ce-9dfa18ebd4f5@  EAACF81CACF7E14D@

317f34eb-5450-4402-94b8-581beaf0c4f3@

```

no matter if the stick is present, mounted or not, so it seems that the stick filesystem doesn't have a UUID (at least when it's fat).

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

>  *Aniruddha wrote:*   Coming to think of it, do I have to adjust my grub.conf (especially the real_root line)? My grub.conf: 
> 
> See my previous post for a working example after which you can pattern yours.  

 

Unfortunately I can't boot using UUID in grub. I compiled genkernel with the --disklabel option but aparantly something is still missing?

```
# genkernel --install --bootloader=grub --menuconfig --disklabel all

* Gentoo Linux Genkernel; Version 3.4.10

* Running with options: --install --bootloader=grub --menuconfig --disklabel all
```

```
# cat  /boot/grub/grub.conf

# Which listing to boot as default. 0 is the first, 1 the second etc.

default 1

# How many seconds to wait before the default listing is booted.

timeout 5

# Nice, fat splash-image to spice things up :)

# Comment out if you don't have a graphics card installed

#splashimage=(hd0,1)/boot/grub/splash.xpm.gz

title=Gentoo Linux (2.6.25-gentoo-r6)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.25-gentoo-r6 real_root=/dev/sdc2 

initrd /boot/initramfs-genkernel-x86-2.6.25-gentoo-r6

title=Gentoo Linux (2.6.24-gentoo-r8)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.24-gentoo-r8 real_root=UUID=dd4927a2-e1f4-4955-8aa7-76a11d8c3aca udev

initrd /boot/initramfs-genkernel-x86-2.6.24-gentoo-r8
```

@gsoe

The problems started when I inserted another hard drive (and another one).

----------

## yabbadabbadont

Someone needs to learn to read more closely...   :Wink:   :Very Happy: 

You left out: 

```
root=/dev/ram0 init=/linuxrc ramdisk=8192
```

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> Someone needs to learn to read more closely...   
> 
> You left out: 
> 
> ```
> ...

 

I though these were optional...   :Embarassed: 

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> Someone needs to learn to read more closely...   
> 
> You left out: 
> 
> ```
> ...

 

Unofrtunately I still have problems booting   :Sad: 

```
$ cat /boot/grub/grub.conf

# Which listing to boot as default. 0 is the first, 1 the second etc.

default 1

# How many seconds to wait before the default listing is booted.

timeout 5

# Nice, fat splash-image to spice things up :)

# Comment out if you don't have a graphics card installed

#splashimage=(hd0,1)/boot/grub/splash.xpm.gz

title=Gentoo Linux (2.6.25-gentoo-r6)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.25-gentoo-r6 real_root=/dev/sdc2 

initrd /boot/initramfs-genkernel-x86-2.6.25-gentoo-r6

title=Gentoo Linux (2.6.24-gentoo-r8)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.24-gentoo-r8 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=UUID=dd4927a2-e1f4-4955-8aa7-76a11d8c3aca udev

initrd /boot/initramfs-genkernel-x86-2.6.24-gentoo-r8
```

----------

## yabbadabbadont

What is the error message?  (the first one, not the panic at the end)

Edit: You may want to add "verbose" to the end of your kernel options.

----------

## cyrillic

 *Aniruddha wrote:*   

>  *gsoe wrote:*   Is your problem that you get different devicenames when you boot with a plugged usb-stick compared to when you don't? 
> 
> Coming to think of it, that was another major problem I encountered with my 'regular' fstab. Every I left a usb device plugged during boot it didn't boot (since the usb stick messed up the device numbering). 

 

The simple solution to that particular problem is to configure usb-storage as a module instead of having it compiled-in.

That way, USB drives will always get enumerated after your internal harddrives.

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> What is the error message?  (the first one, not the panic at the end)
> 
> Edit: You may want to add "verbose" to the end of your kernel options.

 

It's the default error message you get when trying to boot from a wrong partition:

```
"/dev/sdc2" could not be found

Superblock could not be read

press Ctrl+D for reboot or enter you password for maintenance 
```

----------

## yabbadabbadont

Are you sure that you took the correct option off of your grub boot menu?

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> Are you sure that you took the correct option off of your grub boot menu?

 

It boots per default the second option, therefor I'm pretty sure I got the correct one  :Wink: 

----------

## danomac

 *gsoe wrote:*   

> The UUID part seems solved, but I'm quite puzzled by your changing devicenames. I've tried rebooting mandriva (and Gentoo) a couple of times now with and without a plugged usb-stick. It doesn't affect devicenames. 

 

I'm not, I've seen the changing device names on my own PC. I've actually had multiple UUIDs even show up for a partition.

I wound up having to alias one controller so this wouldn't happen. It's really frustrating when your /home partition doesn't mount properly.   :Evil or Very Mad: 

It's very easy to reproduce. Get a PCI/PCI-e SATA controller. Then plug in a usb drive or two and reboot. Everything gets remapped! Using UUIDs didn't fix it for me as my box (for some odd reason) would get multiple UUID entries for some devices, completely screwing up any mounting.

I would guess the reason for this is the boot ordering of the BIOS. Mine goes from onboard SATA->onboard IDE->USB->IEEE1394->PCI-e slots.

Inserting either a ieee1394 drive or a usb flash drive would get all sorts of random reordering. (My RocketRaid card would be sde, sgh, and sdi depending on what would be plugged in at the time.)

I used udev to alias my rocketraid controller to /dev/hptX so I didn't have to guess which on it is.

I didn't see anything in my BIOS to disable any of these controllers, although I didn't really look very hard.   :Wink: 

----------

## yabbadabbadont

 *Aniruddha wrote:*   

>  *yabbadabbadont wrote:*   What is the error message?  (the first one, not the panic at the end)
> 
> Edit: You may want to add "verbose" to the end of your kernel options. 
> 
> It's the default error message you get when trying to boot from a wrong partition:
> ...

 

The initrd should have spit out some messages prior to that error.  There should have been a message where it lists the device that it thinks goes with the UUID you specified for real_root.  Did you see that?  If not, something isn't right.  If you did, was the device listed /dev/sdc2, just like in the final error?

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

>  *Aniruddha wrote:*    *yabbadabbadont wrote:*   What is the error message?  (the first one, not the panic at the end)
> 
> Edit: You may want to add "verbose" to the end of your kernel options. 
> 
> It's the default error message you get when trying to boot from a wrong partition:
> ...

 

I just looked but I didn't get any other message, I'll try the verbose option to see if that helps.

----------

## yabbadabbadont

If you aren't getting any messages from the initrd prior to the kernel panic then, perhaps, you don't have the correct initrd installed?

Always make sure that /boot is mounted before running genkernel to create the initrd (with the --disklabel option of course).

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> If you aren't getting any messages from the initrd prior to the kernel panic then, perhaps, you don't have the correct initrd installed?
> 
> Always make sure that /boot is mounted before running genkernel to create the initrd (with the --disklabel option of course).

 

It is not really  a kernel panic, the problem that it can't find the partition   :Rolling Eyes: 

----------

## Kasumi_Ninja

I used uuid for another kernel and this time it actually gave some useful information:

```
init line 421 blkid not found
```

```
$ cat /boot/grub/grub.conf

# Which listing to boot as default. 0 is the first, 1 the second etc.

default 0

# How many seconds to wait before the default listing is booted.

timeout 5

# Nice, fat splash-image to spice things up :)

# Comment out if you don't have a graphics card installed

#splashimage=(hd0,1)/boot/grub/splash.xpm.gz

title=Gentoo Linux (2.6.25-gentoo-r6)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.25-gentoo-r6 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=UUID=dd4927a2-e1f4-4955-8aa7-76a11d8c3aca udev

initrd /boot/initramfs-genkernel-x86-2.6.25-gentoo-r6

title=Gentoo Linux (2.6.24-gentoo-r8)

root (hd0,1)

kernel /boot/kernel-genkernel-x86-2.6.24-gentoo-r8 real_root=/dev/sdc2 udev

initrd /boot/initramfs-genkernel-x86-2.6.24-gentoo-r8
```

----------

## yabbadabbadont

That error indicates that the "--disklabel" option was not included when the initrd you are using was generated with genkernel.  Re-run genkernel with that option and generate a new initrd.

----------

## Kasumi_Ninja

 *yabbadabbadont wrote:*   

> That error indicates that the "--disklabel" option was not included when the initrd you are using was generated with genkernel.  Re-run genkernel with that option and generate a new initrd.

 

Thanks, this worked. Unfortunately even with uuid the partition naming keeps changing, so I opened another thread.

----------

