On Wed, Jul 12, 2017 at 9:09 AM, Hao Lee <address@hidden> wrote:
3. Attach the whole image to /dev/loop0 and attach the first partition
to /dev/loop1
sudo losetup /dev/loop0 hd.img
You're fine up to here.
sudo losetup -o $((2048*512)) /dev/loop1 hd.img
This is where your problem is. When you run grub-install it detects
two disks, /dev/loop0 and /dev/loop1 where /dev/loop0 appears to be a
partitioned disk with none of its partitions mounted and /dev/loop1
appears to be a disk without any partition table where the whole disk
is mounted to /mnt/.
Instead, you should run "sudo kpartx -a /dev/loop0" which will probe
the partition table of /dev/loop0 and add device nodes in /dev/mapper/
for each of the partitions found. In this case, it would create a
device node /dev/mapper/loop0p1 . When grub-probe looks at
/dev/mapper/loop0p1 it will be able to detect that it is a partition
of the disk /dev/loop0 and thus grub-install will configure things
appropriately.