Help on GRUB for linux based project

Asked by Danish

Hi I was working on a project that would be something like a rescue disk, so you can fix GRUB, partitions, create partitions and things like that, one of the options that i cannot miss is to fix grub-itself i mean install it and update the menu.lst by scanning through the system for microsoft windows OS's (which is pretty simple by just having to look for ntldr and making an entry that would chainload ntldr) But looking for a linux partition is a bit complicated.
1) The kernel name can be anything(its generally going to start with vmlinu),
     which is an issue but i'll say that i can search for files beginning with vmlinu and make the entry if no such
     file is found in /boot/ then we can display the directory contents and have the user enter the name of the
     Kernel himself.

2) I have no idea what
    kernel /boot/vmlinuz-2.6.28-11-generic root=UUID=2ac1f243-112f-4460-b5e3-5a73c64b8b9a ro
                        quiet

entry means AFTER root i dont know what UUID does and if it is necessary.

3)I would atleast like to have support for Ubuntu, Fedora& Suse which are the three major ones around.. Is
    there a way to recognise which kernel is installed on a particular partition?
I'd greatly appreciate the solution directly but
Anything that you thong can be useful to me in solving the problem is welcome
Thank you

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Danish (danested) said :
#1

The project is supposed to work from a live cd environment,

Revision history for this message
Ryan Maki (ryan.maki) said :
#2

I can't comment on making a LiveCD for recovery, since that seems to be a rather large project, but I can answer #2.

root=UUID=2ac1f243-112f-4460-b5e3-5a73c64b8b9a refers to the new style of referring to devices. When the device is formatted it is given a UUID (check Wikipedia: http://en.wikipedia.org/wiki/Uuid) instead of just a device name. This has advantages when your devices might change, when running virtual machines, etc.

You will find a corresponding entry in your /etc/fstab in place of the usual /dev/sdaX entries.

I would recommend researching GRUB more before attempting to update the configuration files with a LiveCD. The task you are attempting to automate requires a good deal of system knowledge, and things have changed for all three of those distros in this regard recently.

Revision history for this message
Danish (danested) said :
#3

Thank you for the info UUID, but is the entry in menu.lst suposed to have it or we'd be able to boot without UUID?
its a complicated project but its rather simple using templates i'll explain it in the end of this comment..

i'll include the script which does it but something is missing i'm not able to figure out what exactly is
(** if you plan to run this on your pc then make a backup of your /boot/menu.lst before you do, then you can check menu.lst for the entries that are in it **.. )
in this script first the user is asked to enter the partition which has grub
this is mounted on /bootpart
then it mounts every partition it finds on /temppart checks looks for ntldr if found then adds a corresponding Microsoft entry in menu.lst
if it finds /boot/ it says it found a linux partition( i know its not fool proof but we'll make it harder to decieve later)
then displays /boot/ files then tells the user to enter the name of the kernel, and the initrd name
updates menu.lst
here is the script
-----------------------------------------------------------------------------------------------------------------------------------------------
if [ $X = '3' ] ; then
 clear
 echo "These are the partitions in your system."
 fdisk -l | grep "/dev" | grep -v "Disk" | grep "Linux" | grep -v "swap"
 echo ""
 echo "Please enter the partition that contains grub. This option updates grub's OS List menu."
 echo "So it is essential to have grub installed."
 echo "Typically its the linux partition that has the /boot/grub directory"
 read PART
 mkdir bootpart
 mkdir temppart
 mount $PART bootpart
 rm -f bootpart/boot/grub/menu.lst
 echo "default 0" > bootpart/boot/grub/menu.lst
 echo "timeout 30" >> bootpart/boot/grub/menu.lst
 echo "" > bootpart/boot/grub/menu.lst
 for partition in `fdisk -l | grep "/dev" | grep -v "Disk" | grep -v "swap" | cut -d' ' -f1`; do
  STATUS=`fdisk -l | grep "/dev" | grep -v "Disk" | grep -v "Ext" | grep -v "swap" | grep $partition`
  TMP=`echo $STATUS | grep "Linux"`
  mount $partition temppart
  if [ -r temppart/ntldr ] ; then
   echo "Found a Windows OS installation in "$partition
   echo "Adding entry to /boot/grub/menu.lst"
   TEMP1=`echo $partition | cut -c1-8`
   DEVICE=`grep $TEMP1 /boot/grub/device.map | cut -c2-4`
   TEMP2=`echo $partition | cut -c9`
   TEMP2=`expr $TEMP2 - 1`
   echo "Label Windows Operating System in "$partition >> bootpart/boot/grub/menu.lst
   echo "root ("$DEVICE,$TEMP2")" >> bootpart/boot/grub/menu.lst
   echo "savedefault" >> bootpart/boot/grub/menu.lst
   echo "makeactive" >> bootpart/boot/grub/menu.lst
   echo "chainloader +1" >> bootpart/boot/grub/menu.lst
   echo "" >> bootpart/boot/grub/menu.lst
  fi
  if [ -n "$TMP" ] ; then
   if [ -r temppart/boot ] ; then
    echo "Found a Linux OS installation in "$partition
    echo "Adding entry to /boot/grub/menu.lst"
    TEMP1=`echo $partition | cut -c1-8`
    DEVICE=`grep $TEMP1 /boot/grub/device.map | cut -c2-4`
    TEMP2=`echo $partition | cut -c9`
    TEMP2=`expr $TEMP2 - 1`
    echo "Label Linux Operating System in "$partition >> bootpart/boot/grub/menu.lst
    echo "Found following files in the boot partition."
    dir temppart/boot
    echo "Please enter the name of the kernel. Eg: bzImage, vmlinuz, flux-2.6.27.4 etc"
    read KERNEL
    echo "Please enter the name of the initrd file if any. Eg: initrd.img, initrd-2.6.27.4.img etc"
    read INITRD
    echo "root ("$DEVICE,$TEMP2")" >> bootpart/boot/grub/menu.lst
    echo "kernel "$KERNEL >> bootpart/boot/grub/menu.lst
    echo "initrd "$INITRD >> bootpart/boot/grub/menu.lst
    echo "" >> bootpart/boot/grub/menu.lst
   fi
  fi
  umount temppart
 done
 read P
fi
------------------------------------------------------------------------------------------------------------------------------------------
here is how we get the thing running the above was one of the modules in the project

Its a complicated project but since we are using pauls boot cd template which has the necessary files that are required, .. now since the boot process goes like
kernel mounted from iso linux on cd->
 kernel loads initrd which has basic functionality to be able to mount the file system->
  then rootfs.gz is uncompressed on the ram->
   /etc/sysinit is executed and then /etc/rc.d/rc
since all commands in this file are executed we have given a shell script at the top of rc

#! /bin/sh
#

/bin/flux.sh

since flux.sh is an infinite loop with the only way to come out is to execute the reboot option nothing else needs to be in rc

Revision history for this message
Danish (danested) said :
#4

there was a mistake towards the end
echo "kernel "$KERNEL >> bootpart/boot/grub/menu.lst***************here it has to be "kernel /boot/"$KE...
    echo "initrd "$INITRD >> bootpart/boot/grub/menu.lst***************here it has to be "kernel /boot/"$IN..
    echo "" >> bootpart/boot/grub/menu.lst

but it still doesn't work. i'd have ripped my hairs apart if it had not been for qemu ;)

Revision history for this message
adrian15 (adrian15) said :
#5

>1) The kernel name can be anything(its generally going to start with vmlinu),
My first thought is using file command.
bash-3.2/boot$ file vmlinuz-2.6.27.15-78.2.23.fc9.i686
vmlinuz-2.6.27.15-78.2.23.fc9.i686: Linux kernel x86 boot executable RO-rootFS, root_dev 0x902, swap_dev 0x2, Normal VGA
>2) I have no idea what
> kernel /boot/vmlinuz-2.6.28-11-generic root=UUID=2ac1f243-112f-4460-b5e3-5a73c64b8b9a ro
> quiet
>
>entry means AFTER root
These are the kernel parametres. There should a document on Linux Kernel source code explaining what option is for.
Some kernels do understand uuid, another ones understand root=LABEL=/1, other ones understand root=/dev/sda1. Some of them are able to understand two of these syntaxs.
It is not evident what to choose.

>3)
See file command above.

> mkdir bootpart
> mkdir temppart
Use variables instead of magic strings.

>i'll include the script which does it but something is missing i'm not able to figure out what exactly is
Try
set -x
set -v
at the script beginning to see what actually the script does.

Finally I advice you to use update-grub when possible (check devices.map if you do) or, at least, study it. It seems that you are trying to develop an update-grub replacement. Not a replacement, because it seems that you are able to chainload a ntldr file but something similar.

adrian15

Can you help with this problem?

Provide an answer of your own, or ask Danish for more information if necessary.

To post a message you must log in.