Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an old kernel ( 2.4.37.9 ) and I want to override or substitute the root=XXXXX parameter to send to the kernel inside the initrd script.

I already made some attempt to do that but it seems that at the end of initrd grub alway pass to kernel the root parameter define inside the menu.lst file, while I'm tryng to define a dynamic value ( ex. hda1 or hdc1 ) depending of the layout of th mother board.

title Linux-2.4.37.9_CCL_20130122 with INITRD
    root (hd0,0)
    kernel /boot/vmlinuz-2.4.37.9_CCL_20130122  ro root=XXXXXX console=ttyS0,9600 console=tty0 apm=off
    initrd /boot/initrd-CCL.img.gz

Any suggestions ?

share|improve this question
    
I don't understand your question, the parameters provided in menu.lst are provided to the kernel. If you want to do something dynamic you should just do it in your initramfs and mount the root device accordingly. The kernel or init don't really care about the root parameter as long as your initramfs takes care of everything. –  Ulrich Dangel Feb 21 '13 at 8:26
    
In old kernel I have to use initrd ( not initramfs ) and despite I have tried to mont the device inside the script of initrd at the end there is always an attempt to old the device specified in root parameter which lead to a kernel paci error –  enzo2 Feb 21 '13 at 10:04

2 Answers 2

You can't, it's not supported.

What you can do is extract initrd /boot/initrd-CCL.img.gz, find the part that mounts root, and modify the corresponding part, add the script to detect hard drive layout, and mount the right drive.

The recommended way is set a UUID for your root drive, and change the root= part to root=UUID=XXX instead, I'm not sure if it's supported on old distros. In that way, no matter how device layout changes, it always mount the right device.

share|improve this answer
    
Inside initrd I was able to check the available device and mount it but when I exit from initrd scritp , grub always send the old root parameter to kernel. –  enzo2 Feb 21 '13 at 10:05
    
@enzo2 you are doing it wrong, in your initrd you should mount the device, run pivot_root or chroot to the new directory and execute init, that is it. grub sets the parameter to the kernel before your initrd is executed –  Ulrich Dangel Feb 21 '13 at 10:13
    
"grub sets the parameter to the kernel before your initrd is executed" that's what was I thinking, but after several attempt I see that, at least with the revision I'm workin on , something work differently. After executing initrd grub still call the kernel with the old parameters. –  enzo2 Feb 25 '13 at 7:42
up vote 0 down vote accepted

This is not the more polite solution to this problem, but it works and mybe should be helpfull to some other so I brifly describe here how I solved my problem to have a DOM capable to change it boot device automatically.

Inside the linuxrc, the script of initrd, I detect wich device is available and based on that result I set the default startup option used by grub

my linuxrx i something like this

#!/bin/ash

restart=0
mntdev=""

target="hda"
echo "--> check fdisk ${target} "

mount -t ext2 /dev/${target}1 /mnt/tmp
if [ -f /mnt/tmp/etc/slackware-release ]; then
  echo "Found $target "
  mntdev="/dev/${target}1"
      olddef=$( cat /mnt/tmp/boot/grub/default )
      if [ $olddef -ne 0 ]; then
          echo "0" > /mnt/tmp/boot/grub/default
          restart=1
      fi
fi
umount /mnt/tmp
# ================================
if [ -z $dskroot ]; then
    target="hdc"
    echo "--> check fdisk ${target} "

    mount -t ext2 /dev/${target}1 /mnt/tmp
    if [ -f /mnt/tmp/etc/slackware-release ]; then
      echo "Found $target  "
      mntdev="/dev/${target}1"
      olddef=$( cat /mnt/tmp/boot/grub/default )
      if [ $olddef -ne 1 ]; then
          echo "1" > /mnt/tmp/boot/grub/default
          restart=1
      fi
    fi
    umount /mnt/tmp
fi
# ================================

if [ $restart -eq 1 ]; then
  echo "Changed grub default : Rebooting PC "
  echo "===================================="
  sleep 2
  mount -t ext2 $mntdev /mnt/tmp
  chroot /mnt/tmp <<EOF
  /sbin/reboot -f
EOF
fi

And inside the grub menu I reserver the first two entry , the 0 for device hda and 1 for device hdc

default saved

title Linux-2.4.37.9_CCL_20130122 with INITRD hda pos 0
        root (hd0,0)
        kernel /boot/vmlinuz-2.4.37.9_CCL_20130122  ro root=/dev/hda1 console=ttyS0,9600 console=tty0 apm=off
        initrd /boot/initrd-CCL.img.gz

title Linux-2.4.37.9_CCL_20130122 with INITRD hdc pos 1
        root (hd0,0)
        kernel /boot/vmlinuz-2.4.37.9_CCL_20130122  ro root=/dev/hdc1 console=ttyS0,9600 console=tty0 apm=off
        initrd /boot/initrd-CCL.img.gz
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.