Hi! To my understanding, it should be possible and supported to install Grub 0.9x onto a loop device. In practice, it seems impossible with (the latest stable) sys-boot/grub-0.97-r14 and produces unexpected expr: non-integer argument output too, see below. Disk preparation ---------------- The idea of using a linear device mapper device is from http://ebroder.net/2009/08/04/installing-grub-onto-a-disk-image/ , was a hope of mine, fails similar to going straight to the loop the device, but has the advantage of making the rest of the script easier to read and re-produce. # touch grubdisk # truncate --size $((200 * 1024**2)) grubdisk # /usr/sbin/parted grubdisk mklabel msdos # /usr/sbin/parted --script grubdisk mkpart primary 0% 50% # /usr/sbin/parted --script grubdisk mkpart primary 50% 100% # GRUB_DISK_DEVICE="$(sudo losetup --show -f grubdisk)" # sudo dmsetup create grub-disk-linear --table \ "0 $(sudo blockdev --getsz ${GRUB_DISK_DEVICE}) linear ${GRUB_DISK_DEVICE} 0" # sudo kpartx -a /dev/mapper/grub-disk-linear # sudo mkfs.ext4 /dev/mapper/grub-disk-linear1 # sudo mkfs.ext2 /dev/mapper/grub-disk-linear2 # mkdir mnt # sudo mount /dev/mapper/grub-disk-linear1 mnt/ # sudo mkdir mnt/boot # sudo mount /dev/mapper/grub-disk-linear2 mnt/boot/ Installing Grub 0.9x -------------------- # sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear Probing devices to guess BIOS drives. This may take a long time. Unknown partition table signature /dev/mapper/../dm-8 does not have any corresponding BIOS drive. # ls -l /dev/mapper/grub-disk-linear* lrwxrwxrwx 1 root root 7 Jan 16 21:00 /dev/mapper/grub-disk-linear -> ../dm-8 lrwxrwxrwx 1 root root 7 Jan 16 21:02 /dev/mapper/grub-disk-linear1 -> ../dm-9 lrwxrwxrwx 1 root root 8 Jan 16 21:02 /dev/mapper/grub-disk-linear2 -> ../dm-10 # cat mnt/boot/grub/device.map (fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb # sudo sed 's|^\((hd0).\).*|\1/dev/mapper/../dm-8|' -i mnt/boot/grub/device.map # cat mnt/boot/grub/device.map (fd0) /dev/fd0 (hd0) /dev/mapper/../dm-8 (hd1) /dev/sdb # sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear expr: non-integer argument /dev/mapper/../dm-10 does not have any corresponding BIOS drive. ## NOTE: So what are my options now? ## I cannot put "(hd0,0)<tab>..." in there as that is unsupported syntax ## and would give a (misleading) "No close parenthesis found" error. ## So let's try mapping to yet another "(hd2)". # sudo sh -c 'echo -e "(hd2)\t/dev/mapper/../dm-10" >> mnt/boot/grub/device.map' # cat mnt/boot/grub/device.map (fd0) /dev/fd0 (hd0) /dev/mapper/../dm-8 (hd1) /dev/sdb (hd2) /dev/mapper/../dm-10 # sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear expr: non-integer argument expr: non-integer argument Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature Unknown partition table signature The file [..]/mnt/boot/grub/stage1 not read correctly. ## Any ideas?
This does work properly with sys-boot/grub:2, so you might consider switching to that.
(In reply to Mike Gilbert from comment #1) > This does work properly with sys-boot/grub:2, so you might consider > switching to that. Thanks, I'm aware. I am working on a Grub theme preview tool that does support Grub2 only so far. I tried adding support for Grub 0.9x for people sticking to that version. That's how I ran into the issue.
grub:0 is gone