0

I have googled a lot for this problem. I found this, but it didn't solve my problem. Other solutions suggest me to reinstall grub (run grub-install), which didn't work either.

Here is what I am doing: (my grub version is 2.02)

  1. I use grub2-mkrescue to make my X.iso
  2. I boot a VMWareWorkstation virtual machine, which has a 1.0GB SATA disk, from X.iso
  3. I install X.iso on disk, the details are:

3.1. erase /dev/sda in case there are old partitions on it: dd if=/dev/zero of=/dev/sda bs=1M count=1

3.2. Create 3 primary partitions on /dev/sda as dev/sda1,sda2,sda3 (the size is 100M, 30M and 70M), and toggle sda1 to be bootable

Disk /dev/sda: 1024 MB, 1073741824 bytes, 2097152 sectors
130 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sda1 *  0,1,1       12,191,50           63     204862     204800  100M 83 Linux
/dev/sda2    12,191,51   16,147,2        204863     266302      61440 30.0M 83 Linux
/dev/sda3    16,147,3    25,127,37       266303     409662     143360 70.0M 83 Linux

3.3. Format the 3 partitions as ext2, and mount /dev/sda1

mkfs.ext2 /dev/sda1
mkfs.ext2 /dev/sda2
mkfs.ext2 /dev/sda3
ROOTFS_PATH=/var/.rootfs
mkdir $ROOTFS_PATH
mount /dev/sda1 $ROOTFS_PATH

3.4 copy files...

for i in bzImage initrd.img vmlinuz-*; do
    cp -rf /boot/$i $ROOTFS_PATH/boot
done
cp -f /boot/grub/device.map $ROOTFS_PATH/boot/grub/device.map
for i in init linuxrc; do
    cp -rf /$i $ROOTFS_PATH
done
for i in bin etc lib sbin share usr; do
    cp -a /$i $ROOTFS_PATH
done
for i in dev var proc sys tmp data log; do
    mkdir -p $ROOTFS_PATH/$i
done

3.5 Install grub and make grub config file

chroot $ROOTFS_PATH <<EOF
mount -a
mdev -s
grub-install $tdisk
grub-install --recheck $tdisk
grub-mkconfig -o /boot/grub/grub.cfg
exit
EOF
  1. reboot

It says:

.
error: disk 'hd0,msdos1' not found
Entering rescue mode...
grub rescue>

And the most strange thing is that ls command shows nothing in grub-rescue cli ---- as someone says, it should show disk list.

error after reboot

0
cp -f /boot/grub/device.map $ROOTFS_PATH/boot/grub/device.map

So, you copied the GRUB device.map file from the GRUB rescue ISO image to your disk? It might be forcing grub-install to associate the GRUB device identifier hd0 with a disk device other than /dev/sda.

Before running grub-install, verify that the device.map file actually associates hd0 with the disk you're installing GRUB to (i.e. /dev/sda in your case).

Also, why are you doing all this? It looks like you're trying to make a grub2-mkrescue VM image that might be useable in rescuing some other VM that has lost its bootloader - is that what you're planning to do? If so, simply booting the problem VM using an ISO image of any Live CD/DVD Linux distribution would give you a more extensive set of tools and more comfortable environment for fixing your original problem, whether it's a missing bootloader or something else.

If you specifically need grub2-mkrescue, you already have your X.iso - why you are trying to convert it to a virtual-disk-based installation?

  • thanks for your reply. What I'm trying is to build a very small x86 Linux distro with only a few feature. Just like other Linux distro, Ubuntu,CentOS - Someone download a ubuntu-x.iso, boot from it and install it into the disk.That's what I want. – Hurry Zeng Mar 5 at 6:21
  • I want a disk-based installation, instead of a virtual-disk-based installation. However, I'm testing it on the virtual machine, before a real machine. – Hurry Zeng Mar 5 at 6:28
  • As this page says: If the device map file does not exist, then the GRUB utilities will assume a temporary device map on the fly. This is often good enough, particularly in the common case of single-disk systems. So I delete device.map from X.iso and donot copy it when installing, But the problem remained the same. Any other suggestions? – Hurry Zeng Mar 5 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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