You are not logged in.

#1 2013-07-04 09:54:04

roginovicci
Member
Registered: 2010-11-06
Posts: 43

[SOLVED] Grub2 load kernel with root pointed by UUID

I have two hard drives installed? let's say disk1 and disk2. My root partition with linux installed is disk1 first partition /dev/sda1, disk2 is for lvm volume purpose. Some times I boot quite well this is the case when disk1 is /dev/sda and disk2 is /dev/sdb. But some times (after reboot mostly) i have my disk2 as /dev/sda and this is bad, system fail to load. So I was trying to boot using UUID of my partitions, unfortunately with no success. Grub fails to find kernel. (error is /vmlinuz-linux not found; you need to load kernel first)

Here is instructions I use, and below is my grub.cfg
https://wiki.archlinux.org/index.php/GR … _scripting

 set timeout=5
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi
set color_normal='light-blue/black'; set color_highlight='light-cyan/blue'

menuentry 'Arch Linux' {
  set root='(hd0,1)'; set legacy_hdbias='0'
  legacy_kernel   '/boot/vmlinuz-linux' '/boot/vmlinuz-linux' 'root=/dev/sda1' 'ro'
  legacy_initrd '/boot/initramfs-linux.img' '/boot/initramfs-linux.img'

}

menuentry 'Arch Linux UUID' {
# Set the UUIDs for your boot and root partition respectively
  set the_boot_uuid=90aba20e-805b-422b-872e-1e32c0902be8
  set the_root_uuid=90aba20e-805b-422b-872e-1e32c0902be8
# (Note: This may be the same as your boot partition)

# Get the boot/root devices and set them in the root and grub_boot variables
  search --fs-uuid --set=root $the_root_uuid
  search --fs-uuid --set=grub_boot $the_boot_uuid

# Check to see if boot and root are equal.
# If they are, then append /boot to $grub_boot (Since $grub_boot is actually the root partition)
  if [ $the_boot_uuid == $the_root_uuid] ; then
    set grub_boot=$grub_boot/boot
  fi

# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd
  linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro
  initrd ($grub_boot)/initramfs-linux.img

}

this is the part of my fstab file:

tmpfs           /tmp    tmpfs   nodev,nosuid    0       0
UUID=90aba20e-805b-422b-872e-1e32c0902be8 / ext4 defaults 0 1
UUID=fe9e652d-5778-4206-a051-229253e8a5c3 swap swap defaults 0 0

My system is up to date
Should I use some HOOKS or whatever?

Last edited by roginovicci (2013-07-04 13:21:02)

Offline

#2 2013-07-04 12:18:15

roginovicci
Member
Registered: 2010-11-06
Posts: 43

Re: [SOLVED] Grub2 load kernel with root pointed by UUID

Digging around i found the code in wiki is incorrect. The one which working is below. Should it be reported as BUG?

menuentry 'Arch Linux UUID' {
# Set the UUIDs for your boot and root partition respectively
  set the_boot_uuid=90aba20e-805b-422b-872e-1e32c0902be8
  set the_root_uuid=90aba20e-805b-422b-872e-1e32c0902be8
# (Note: This may be the same as your boot partition)

# Get the boot/root devices and set them in the root and grub_boot variables
  search --fs-uuid $the_root_uuid --set=root
  search --fs-uuid $the_boot_uuid --set=grub_boot
# Check to see if boot and root are equal.
# If they are, then append /boot to $grub_boot (Since $grub_boot is actually the root partition)
  if [ $the_boot_uuid == $the_root_uuid ] ; then
    set grub_boot=($grub_boot)/boot
  else
    set grub_boot=($grub_boot)
  fi

# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd
  linux $grub_boot/vmlinuz-linux root=/dev/disk/by-uuid/$the_root_uuid ro
  initrd $grub_boot/initramfs-linux.img

  # (1) Arch Linux
}
 

Offline

#3 2013-07-04 12:31:34

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

Re: [SOLVED] Grub2 load kernel with root pointed by UUID

Just edit the page.  It's a wiki after all.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2013-07-04 13:20:49

roginovicci
Member
Registered: 2010-11-06
Posts: 43

Re: [SOLVED] Grub2 load kernel with root pointed by UUID

fixed.

Offline

#5 2013-07-05 20:37:22

jones
Member
Registered: 2013-03-14
Posts: 247

Re: [SOLVED] Grub2 load kernel with root pointed by UUID

I'm intrigued, I have some similar setup. Thanks for providing the solution . But I don't get how your code would work as you gave the same UUID for the root partition and boot partition.

edit: Nevermind. The wiki entry contains different UUIDs, it's just your post above that's "wrong".

Last edited by jones (2013-07-05 20:40:10)

Offline

Board footer

Powered by FluxBB