On Wed, Jul 12, 2017 at 9:09 AM, Hao Lee <[email protected]> wrote: > Hi, > > I encounter a problem when making a bootable disk image because GRUB > only offers a rescue shell. > > I want to create a disk image and install GRUB 2 on it and then use > Bochs to run it. The steps are as follows. > > System Environment: > OS: Fedora 25 x86 > GRUB version: grub2-install (GRUB) 2.02~beta3 > Bochs version: 2.6.9 > > 1. Create a empty disk image. > > dd if=/dev/zero of=hd.img bs=$((16*63*512)) count=100 > > 2. Create a primary partition. > > fdisk -u -C100 -S63 -H16 hd.img > > The partition table is: > Device Boot Start End Sectors Size Id Type > hd.img1 2048 100799 98752 48.2M 83 Linux > > 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/. grub-install performs an installation that would work if that were the case (try passing /dev/loop0 and /dev/loop1 as disks to bochs and it should boot). 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. > > 4. Format the first partition to ext4 and mount it to /mnt/ > > sudo mkfs.ext4 /dev/loop1 > sudo mount -t ext4 /dev/loop1 /mnt sudo mkfs.ext4 /dev/mapper/loop0p1 sudo mount -t ext4 /dev/mapper/loop0p1 /mnt/ > > 5. Create GRUB directory. > > sudo mkdir -p /mnt/boot/grub2 > > 6. Install GRUB 2 > > sudo grub2-install --boot-directory=/mnt/boot /dev/loop0 > > 7. Start Bochs. > > bochs -f test.bxrc > > These steps are straight and simple. However, GRUB only offers a > rescue shell instead of entering normal mode. > When I use the set and ls command to show more information, I can only > see (hd0) and the first partition (hd0,1) is disappeared. The screen > output is as follows: That is because grub-install detected that /boot/grub/ was on a "disk" with no partition table, and thus didn't include the part_msdos module in the core.img. Again, the solution to that problem is described above. -- Jordan Uggla (Jordan_U on irc.freenode.net) > ---------------------------------------------------- > Bochs BIOS - build: 02/16/17 > ata0 master: Generic 1234 ATA-6 Hard-Disk ( 49 MBytes) > Press F12 for boot menu. > Booting from Hard Disk... > . > error: no such device: c5b2c483-70c2-4212-840b-da5f965d0555. > error: unknown filesystem. > Entering rescue mode... > grub rescue> set > prefix=(hd0)/boot/grub2 > root=hd0 > grub rescue> ls > (hd0) > grub rescue> > ---------------------------------------------------- > > Could someone help me out? Many thanks! > > Regards, > Hao Lee > > _______________________________________________ > Help-grub mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/help-grub _______________________________________________ Help-grub mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-grub
