LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 10-29-2010, 11:04 AM   #1
richardrosa
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Modifying GRUB2 for LABEL= syntax


Greetings all,

After a recent hard drive replacement, I find that I can no longer
boot my Ubuntu partition. It seems that Ubuntu set up GRUB to boot
using the disk id, which is no longer valid.

I've been using the old GRUB for a number of years, and have always
used the LABEL= syntax to assure that the correct partition is booted.

There is a dire warning in the /boot/grub/grub.cfg file NOT to edit
it. With the old grub, it was just a simple matter to change the
menu.lst file.

What file DOES get edited to make the change for the new drive? Is there an easy way to get GRUB2 to use the LABEL= form that I know and love? Or is it easier just to reinstall Ubuntu when a drive gets changed?

Thanx in advance.

Rich
 
Old 10-29-2010, 02:14 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,678

Rep: Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712
Grub2 and LABELd partitions.

Check out these threads:
http://www.linuxquestions.org/questi...b2-how-819474/

Remember, google is your friend!
 
Old 10-29-2010, 02:40 PM   #3
TSquaredF
Member
 
Registered: Dec 2005
Location: "The South Coast of Texas"
Distribution: Slackware64-current
Posts: 564

Rep: Reputation: Disabled
I have just finished jumping through the hoops required to understand grub2. I installed it in one of my Slackware partitions & used it for quite a while by editing /boot/grub/grub.cfg. I know that isn't recommended, but if you realise that it will be overwritten when "update-grub" is run & keep a backup, you can do that.
In order to use it as designed, you can start by editing "/etc/default/grub". There are a number of settings in there that can be changed & it is fairly well annotated. There is even a setting to turn off passing "root=UUID=whatever", but if you do, it passes "root=/dev/sdXY". There is nothing to have it pass "root=LABEL=whatever", unfortunately. The actual menu entries are read from the files in "/etc/grub.d". The files in that directory that are executable are added to /boot/grub/grub.cfg when "update-grub" is run. On my system, I have 00_header, 05_debian_theme, 10_linux & 40_custom executable, so it does not probe for other OSes, via 30_os-prober. I have one ubuntu & two Slackware partitions on this harddrive & full backups on a USB harddrive. If I ran 30_os-prober, it would add all my backups to my grub.cfg; I didn't want that, so I edited 40_custom to add my Slackware partitions like this:
Code:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Slackware-Current Desktop" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=primary ro 4
        initrd /initrd.gz
}
menuentry "Slackware-Current Command Line" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=primary ro
        initrd /initrd.gz
}
menuentry "Slackware-Current Unmodified" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=current ro
        initrd /initrd.gz
}
Once I have files modified as above, I run "update-grub" & get a new grub.cfg, which looks like this:
Code:
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}

function load_video {
  insmod vbe
  insmod vga
}

insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 74205868-6a68-4b7e-afa5-48da485b84b0
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=640x480
  load_video
  insmod gfxterm
fi
terminal_output gfxterm
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 74205868-6a68-4b7e-afa5-48da485b84b0
set locale_dir=($root)/boot/grub/locale
set lang=en
insmod gettext
if [ "${recordfail}" = 1 ]; then
  set timeout=-1
else
  set timeout=4
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.35-22-generic' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos2)'
        search --no-floppy --fs-uuid --set 74205868-6a68-4b7e-afa5-48da485b84b0
        linux   /boot/vmlinuz-2.6.35-22-generic root=/dev/sda2 ro   quiet splash
        initrd  /boot/initrd.img-2.6.35-22-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Slackware-Current Desktop" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=primary ro 4
        initrd /initrd.gz
}
menuentry "Slackware-Current Command Line" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=primary ro
        initrd /initrd.gz
}
menuentry "Slackware-Current Unmodified" {
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        linux /generic root=LABEL=current ro
        initrd /initrd.gz
}
### END /etc/grub.d/40_custom ###
You can unset the executable bit on 10_linux & manually add your ubuntu partition to the 40_custom file. That way you could use "root=LABEL=XXXX" with no hassles.
Regards,
Bill

Edit: Well, I didn't search well enough, did I? I've spent part of my afternoon following the instructions in post #2 & they work perfectly. Follow them & pay very little attention to what I have posted. I still have to use 40_custom for my other partitions, but maybe, with the stuff I read this afternoon, I can modify 30_os-prober to do what I want. Regards again, Bill

Last edited by TSquaredF; 10-29-2010 at 06:16 PM.
 
Old 10-29-2010, 11:42 PM   #4
tommcd
Senior Member
 
Registered: Jun 2006
Location: Philadelphia PA USA
Distribution: Lubuntu, Slackware
Posts: 2,230

Rep: Reputation: 293Reputation: 293Reputation: 293
Quote:
Originally Posted by richardrosa View Post
After a recent hard drive replacement, I find that I can no longer
boot my Ubuntu partition. It seems that Ubuntu set up GRUB to boot
using the disk id, which is no longer valid.
So is grub2 still installed to the MBR of the hard drive you are booting from? If so, then you should be able to update /boot/grub/grub.cfg just by running:
Code:
sudo update-grub
This should then point grub2 to the proper partition to boot Ubuntu.
To find the UUIDs of all your partitions, simply run:
Code:
sudo blkid
This will list your partitions and their respective UUIDs.
Here is a good tutorial on grub2:
https://help.ubuntu.com/community/Grub2
Quote:
Originally Posted by richardrosa View Post
What file DOES get edited to make the change for the new drive? Is there an easy way to get GRUB2 to use the LABEL= form that I know and love? Or is it easier just to reinstall Ubuntu when a drive gets changed?
Configuration options for grub2 are done from: /etc/default/grub file.
Custom boot entries can be created in the /etc/grub.d/ directory.
You must run: "sudo update-grub" after making any changes to grub2, so the updates can be written to: /boot/grub/grub.cfg.
Write back if you need more help.

And welcome to the LQ forums!

Last edited by tommcd; 10-29-2010 at 11:46 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] GRUB2 after a minor update of GRUB2 /boot prefix no longer needed?? wikapuki Linux - Software 1 10-24-2010 02:39 PM
LABEL=/1 vs LABEL=/ in linux !! shipon_97 Linux - Newbie 1 06-02-2010 08:33 AM
Grub2 questions: need to know grub.cfg syntax for bootable grub_eltorito iso's?? linus72 Linux - General 11 02-11-2010 06:20 PM
trouble umounting with LABEL=label in fstab JosephS Debian 3 02-01-2010 06:25 AM
Modifying distros iso images to boot with grub2 NightHorse Linux - Distributions 3 10-12-2009 06:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 03:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration