Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1O8SJr-000466-41 for mharc-grub-devel@gnu.org; Sun, 02 May 2010 02:06:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8SJo-00045A-6C for grub-devel@gnu.org; Sun, 02 May 2010 02:06:20 -0400 Received: from [140.186.70.92] (port=59363 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8SJk-00043Z-FQ for grub-devel@gnu.org; Sun, 02 May 2010 02:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8SJi-0005JC-GE for grub-devel@gnu.org; Sun, 02 May 2010 02:06:16 -0400 Received: from ananke.wxnz.net ([58.28.4.122]:44938) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8SJh-0005Il-Ny for grub-devel@gnu.org; Sun, 02 May 2010 02:06:14 -0400 Received: from [192.168.1.64] (ip-118-90-24-154.xdsl.xnet.co.nz [118.90.24.154]) by ananke.wxnz.net (Postfix) with ESMTP id F263F1707AE for ; Sun, 2 May 2010 18:06:07 +1200 (NZST) From: Simon Kitching To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="=-cjS6qtW+5YdsXfs+0dRV" Date: Sun, 02 May 2010 18:05:57 +1200 Message-ID: <1272780357.467.11.camel@simon-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: getting grub booting in qemu.. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2010 06:06:20 -0000 --=-cjS6qtW+5YdsXfs+0dRV Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit I'm trying to set up a qemu image for testing grub; see attached script. When I start qemu with the resulting image file, via "qemu raw.img" I get: Booting from Hard Disk.... Welcome to Grub! error: no such disk. Entering rescue mode... grub rescue> _ If I type $root I get back Unknown command `hd0,1' So it would seem that the MBR and embedded core.img are working well, but that core.img cannot find /boot/grub. Any ideas why, given that $root appears to be correct? I've tried explicitly defining the disk in grub-mkimage with "--prefix=(hd0,1)/boot/grub", and confirmed with gdb that this is indeed being recognised, but it had no effect. I have been trying to debug this by putting some print-statements in disk/i386/pc/biosdisk.c to show what disk is being accessed, but this code doesn't appear to be run. How exactly is "kernel.img" built anyway? I've looked in the makefiles and can't see what source files kernel.img is made from. File genmk.rb perhaps has something to do with it, but I just don't understand.. And I see that in grub-mkimage there is something to do with qemu: #elif defined(GRUB_MACHINE_QEMU) .... Is this relevant or not? Any ideas how I might debug this further? Thanks, Simon --=-cjS6qtW+5YdsXfs+0dRV Content-Type: application/x-shellscript; name="inst.sh" Content-Disposition: attachment; filename="inst.sh" Content-Transfer-Encoding: 7bit #!/bin/sh # ============================================================================== # Script to create a "clone" of the locally installed operating system in a # qemu disk image, in order to then be able to boot that image in a virtual # machine for testing/debugging. # # As much work is done using the account of the user invoking this script, in # order to avoid any danger of writing to a real disk etc. However some steps # do require root privileges, and therefore use "sudo". # ============================================================================== # ------------------------------------------------------------------------------ # Set up target disk partitions and filesystems # ------------------------------------------------------------------------------ # Clean up in case this script is run multiple times... echo "mounts cleanup.." sudo umount fs 2>/dev/null echo "losetup cleanup.." sudo losetup -d disk 2>/dev/null sudo losetup -d part 2>/dev/null echo "filesystem cleanup.." rm -f raw.img rm -rf fs # Create some device nodes locally for use with the loopback device, rather # than use the nodes /dev/loopN. When using nodes in /dev, udev interferes by # running its rules whenever the device is opened/closed, resetting permissions # and ownership. Having "local" nodes here avoids that problem. echo "creating loop nodes.." rm -f disk part sudo mknod disk b 7 200 sudo chown simon disk sudo mknod part b 7 201 sudo chown simon part # Create and format a disk image... echo "creating image.." qemu-img create raw.img 4G echo "mapping block device 'disk' to file raw.img.." sudo losetup disk raw.img echo "doing parted.." #cat parted.sh | parted --script disk parted disk mklabel msdos parted disk mkpart primary ext2 65536s 100% # Explicitly mount the newly created partition as a separate loop device using # the known offset of the first partition, and format it as ext2. echo "mapping block device 'part' to the first partition within file raw.img.." sudo losetup -o 32768 part raw.img echo "making a filesystem on the partition.." mke2fs part echo "mounting new filesystem..." mkdir fs sudo mount -t ext2 part fs sudo chmod a+rwx fs # ------------------------------------------------------------------------------ # Set up grub in /boot/grub and the MBR of the disk image.. # ------------------------------------------------------------------------------ echo "copying grub files.." mkdir -p fs/boot/grub cp -r /usr/lib/grub/i386-pc/* fs/boot/grub echo "grub-mkimage.." cp ~/kernel.img fs/boot/grub grub-mkimage --directory=fs/boot/grub --prefix='(hd0,1)/boot/grub' --output=fs/boot/grub/core.img ext2 part_msdos # Now install grub into the disk MBR, and "embed" core.img into the blocks following the MBR. echo "grub-setup.." echo "(hd9) disk" > fs/boot/grub/device.map echo "(hd9,1) part" >> fs/boot/grub/device.map echo "(hd0) disk" >> fs/boot/grub/device.map echo "(hd0,1) part" >> fs/boot/grub/device.map #gdb grub-setup --directory=fs/boot/grub --device-map=fs/boot/grub/device.map --root-device='(hd9,1)' disk #grub-setup --directory=fs/boot/grub --device-map=fs/boot/grub/device.map --root-device='(hd9,1)' '(hd9)' grub-setup --directory=fs/boot/grub --device-map=fs/boot/grub/device.map --root-device='(hd9,1)' '(hd9)' # gdb --args grub-setup --directory=fs/boot/grub --device-map=fs/boot/grub/device.map --root-device='(hd9,1)' '(hd9)' # ------------------------------------------------------------------------------ # and now optionally copy the current OS files onto the target system # ------------------------------------------------------------------------------ # /bin # /etc # /lib # /opt # /root # /sbin # /srv # /sys # mkdir /tmp # /usr # /var # /boot: kernels # now just need a grub.cfg... # # best to copy /boot/grub/grub.cfg and edit by hand; grub-mkconfig assumes that it is creating a grub.cfg for # the currently running OS. --=-cjS6qtW+5YdsXfs+0dRV--