Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved]how to change sda/sdb label to UUID in grub.cfg ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
double_crane
Tux's lil' helper
Tux's lil' helper


Joined: 11 Dec 2011
Posts: 119
Location: JiangSu,China

PostPosted: Thu Apr 30, 2015 4:49 pm    Post subject: [Solved]how to change sda/sdb label to UUID in grub.cfg ? Reply with quote

my laptop has 5 SATA interface in BIOS ,
1 & 2. SATA3 ( inside HDD )
3 SATA2 ( inside ODD )
4 SATA3 ( inside msata )
5 SATA3 ( external esata )

I used to install Gentoo and grub2 in the first SATA interface HDD . So it's (hd0,0) or sda1 in grub.conf file .

recently I got a M550 msata SSD and installed gentoo to it , but its order is the 4th in BIOS , after my harddisk which is at the first SATA interface .
So it should be sdb1. But what's worse , I found if I insert a U disk or even connect my cellphone to a USB3 interface , the msata SSD change to sdc ..sdd... so the laptop can't boot up , the init process can't find the valid root filesystem ( cos sdb1 changed )
everytime I want to boot or reboot the gentoo , I have to disconnect the USB devices . but I find if I boot or reboot the windows system ( use grub2 ) , I won't have to do this .

So I want to know , how to change the grub file , use UUID number ( cos it won't change ) instead of sda/sdb name , to boot the system , and I don't have to disconnect the USB devices ?

I use grub2-mkconfig command to generate the grub.cfg file .

Now my grub.cfg file

Code:

menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-f04bba03-1764-429b-a080-0a495190dc46' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd1,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos1 --hint-efi=hd1,msdos1 --hint-baremetal=ahci1,msdos1 --hint='hd1,msdos1'  f04bba03-1764-429b-a080-0a495190dc46
        else
          search --no-floppy --fs-uuid --set=root f04bba03-1764-429b-a080-0a495190dc46
        fi
        echo    'boot Linux 3.18.9 ...'
        linux   /boot/vmlinuz-3.18.9 root=/dev/sdb1 ro init=/usr/lib/systemd/systemd
}


it use " hd1,msdos1 " statement , if the msata changed from sdb to sdc , hd1 should be hd2 ,right ?

how to solve this?


Last edited by double_crane on Fri May 01, 2015 4:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43192
Location: 56N 3W

PostPosted: Thu Apr 30, 2015 6:18 pm    Post subject: Reply with quote

double_crane,

First understand that partitions containing filesystems have two different UUIDs
One for the partition and another different one for the filesystem.

The kernel understands the partition UUID but not the filesystem UUID. That needs the userspace mount command in a initrd.
It has to be in a initrd as you need it to mount root. /sbin/blkid will tell you what you need to know.

Code:
$ /sbin/blkid
/dev/sda1: UUID="9392926d-6408-6e7a-8663-82834138a597" TYPE="linux_raid_member" PARTUUID="0553caf4-01"

You can write root=PARTUUID=0553caf4-01 or root=UUID=9392926d-6408-6e7a-8663-82834138a597

On an MSDOS disklable disk, the -xy is the partition number, so its not as robust as the filesystem UUID but it works without an initrd.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
double_crane
Tux's lil' helper
Tux's lil' helper


Joined: 11 Dec 2011
Posts: 119
Location: JiangSu,China

PostPosted: Fri May 01, 2015 2:02 am    Post subject: Reply with quote

NeddySeagoon wrote:


Code:
$ /sbin/blkid
/dev/sda1: UUID="9392926d-6408-6e7a-8663-82834138a597" TYPE="linux_raid_member" PARTUUID="0553caf4-01"

You can write root=PARTUUID=0553caf4-01 or root=UUID=9392926d-6408-6e7a-8663-82834138a597


I knew , use root=UUID=f04bba03-1764-429b-a080-0a495190dc46 to replace root=/dev/sdb1

but use what to replace " hd1,msdos1 " ? I've used "UUID=f04bba03-1764-429b-a080-0a495190dc46 " , but it seems wrong .

Code:

dc@Gentoo ~ $ blkid
/dev/sda1: LABEL="EXT4" UUID="dd019339-29a7-4131-92de-3969543f5d3a" TYPE="ext4" PARTUUID="91ca102c-01"
/dev/sda2: LABEL="NTFS" UUID="7621FC61524ECAD1" TYPE="ntfs" PARTUUID="91ca102c-02"
/dev/sdb1: LABEL="Gentoo_M550" UUID="f04bba03-1764-429b-a080-0a495190dc46" TYPE="ext4" PARTUUID="cf82a35b-01"
/dev/sdb2: LABEL="WIN7_M550" UUID="18E09636E09619D8" TYPE="ntfs" PARTUUID="cf82a35b-02"


you mean use PARTUUID= cf82a35b-01 to replace hd1,msdos1 ?


by the same time , is there any configure options in /etc/default/grub or other grub configuration files , to make the grub.cfg generated by " grub2-mkconfig " command , use root=UUID=XXXX and not contain any sda sdb or hd1 msdos1 sentence ?

thank you
Back to top
View user's profile Send private message
double_crane
Tux's lil' helper
Tux's lil' helper


Joined: 11 Dec 2011
Posts: 119
Location: JiangSu,China

PostPosted: Fri May 01, 2015 12:59 pm    Post subject: Reply with quote

I found that ,
If the root file system is at /dev/sda1 , then if I connect a USB disk , the laptop can boot correctly, no error.

but if the root file system is not at sda1 , assuming it's in sdb1 , then if I connect a USB disk , the USB disk will become /dev/sda ,and the former sda will be sdb ,, and so on.

and then it can't boot correctly, because no valid root file system.
Back to top
View user's profile Send private message
double_crane
Tux's lil' helper
Tux's lil' helper


Joined: 11 Dec 2011
Posts: 119
Location: JiangSu,China

PostPosted: Fri May 01, 2015 4:07 pm    Post subject: Reply with quote

thank you

I tried to use PARTUUID="cf82a35b-01" to replace /dev/sdb1 , and it works . the system boot correctly no matter how USB connection state is .

So, I want to know is there any configurations , to replace /dev/sdb to PARTUUID automaticly when I do "grub2-mkconfig" command ? Or do I have to change it by hand everytime ?

thank you
Back to top
View user's profile Send private message
double_crane
Tux's lil' helper
Tux's lil' helper


Joined: 11 Dec 2011
Posts: 119
Location: JiangSu,China

PostPosted: Fri May 01, 2015 4:21 pm    Post subject: Reply with quote

I tried set
Code:

GRUB_CMDLINE_LINUX_DEFAULT="root=PARTUUID="cf82a35b-01" init=/usr/lib/systemd/systemd"

in /etc/default/grub.

then after grub2-mkconfig command , the grub.cfg file will be like this:
Code:
linux   /boot/vmlinuz-3.18.11 root=/dev/sdb1 ro  root=PARTUUID=cf82a35b-01 init=/usr/lib/systemd/systemd


though there are two " root=XXXX " in the sentence , but it works .
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum