Modifying grub.conf file in linux

I edited the 'grub.conf' file of my linux system and changed the 'timeout' value in it and added some other line so as to solve the timeout issue of 'xm console guest' command. I was fool to assume that this 'timeout' parameter in grub.conf is actually related to 'xm console timeout and change it to very large value. So it led me to a big problem. Now when I rebooted my linux machine, it just hangs at boot screen even after manually selecting the Kernel to boot.

So basically I want to undo the changes I did in grub.conf file while booting or through grub. Or somehow force the system to boot once and undo the changes afterwards. I am not able to do it. One way to do it it to boot from the Linux CD in rescue mode and undo it, but I can not do it as it is a virtual machine on XEN and I can't find a way to boot it from external CD.

Is there any way to resolve the mess I created?


You can mount the diskfile on the host using losetup

sudo losetup -o32256 /dev/loop0 /path/to/harddiskimage.xm
sudo mount /dev/loop0 /media/mydisk

The -o refers to the offset for the boot sector. This is normally 32256 but can change if, for example, you have multiple partitions on the guest.

To make sure what your offset is, you can do the following:

sudo losetup -d /dev/loop0
sudo losetup /dev/loop0 /path/to/harddiskimage.xm
sudo fdisk -ul /dev/loop0

It will show the number of Units and sector/track. Just multiply these two to get the offset.

Once you are done, editing the grub.conf in the mounted folder, you can unmount it:

sudo umount /dev/loop0
sudo losetup -d /dev/loop0

You can edit the boot options right from the grub menu before selecting an option. I believe you press "e" to edit the entry. You can then change the options for that boot to something different.

Once you are booted into the system, you can edit your grub.conf file again.