[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to create qemu-bootable image using debootstrap?



Hi,

Andrew Sackville-West wrote:
> On Mon, Jul 07, 2008 at 01:18:22AM -0700, David Barrett wrote:
>> Andrei Popescu wrote:
>>> On Sun, Jul 06, 2008 at 11:34:52PM -0700, David Barrett wrote:
>>>> Carl Fink wrote:
>>>>> On Sun, Jul 06, 2008 at 09:00:38PM -0700, David Barrett wrote:
>>>>>> David Barrett wrote:
>>>>>>> What's the best way to create a raw disk image using 
>>>>>>> debootstrap that can be booted with qemu?
>>>>>> Following up on my previous post: I've figured out some of the 
>>>>>> steps, but I'm stuck on installing Grub.  Do you know how to 
>>>>>> install grub on a raw device file?
>>>>> Forgive a silly question, but why do you want to install grub on 
>>>>> the image? Are you planning to dd it onto a physical disk?
>>>> No, I'm just going to use it as a QEMU image.  It'll stay virtual, 
>>>> but it'll need to boot all the same.  Unless there's some way to get 
>>>> it to boot without grub?
>>> If I recall correctly, qemu can boot a linux kernel directly so you  
>>> *probably* don't need grub.
>> Aha!  I completely forgot about those options.  This works great:
>>
>> sudo qemu -kernel-kqemu -kernel newtest.mount/boot/vmlinuz-2.6.18-6-486  
>> -append "root=/dev/hda1 ro" -initrd  
>> newtest.mount/boot/initrd.img-2.6.18-6-486 newtest.raw
>>
>> It makes the command line a bit awkward, but does the trick.  This is  
>> great workaround, thanks!
>>
>> That said, if possible, I'd still like to get grub installed to make it  
>> self-contained and boot up like normal (else I need to update all the  
>> startup scripts to be aware of the exact kernel version).
> 
> can you not use the grub floppy disk image and just cat it into the
> boot sector? 
> 
> Another idea: write a script to install grub from a chroot,
> copy that script into the image, and then chroot in and run that
> script from your other script. 
> 
> or: make a barebones image with grub installed by some other
> non-automated method and then use that bare image as the starting
> point for your script, eliminating the dd step.
> 
> just .02
> 
> 
> A

Previously, I had the same problem but I did not know how to deal with
the partions (btw. I still have too figure out how did you got those
numbers to be able to create smaller disks). The `parted' stuff you
posted before was a missing piece of information. Here is a complete
sequence of commands that
- creates a harddisk image
- install multiboot specification compliant kernel to it
- install grub to the harddisk image
--------------------------------------------------
sudo dd if=/dev/zero of=disk.img bs=1024 count=1048576
sudo parted disk.img mklabel msdos
sudo parted disk.img mkpart primary ext2 0 954
sudo parted disk.img mkpart extended 954 1069
sudo parted disk.img mkpart logical  linux-swap 954 1069
sudo parted disk.img set 1 boot on
sudo parted disk.img mkfs 1 ext2
sudo mount -o loop,offset=16384 -t ext2 disk.img mnt
sudo mkdir mnt/grub
sudo cp /boot/grub/stage1 mnt/grub
sudo cp /boot/grub/stage2 mnt/grub
sudo cp /boot/grub/e2fs_stage1_5 mnt/grub
# The contents of the `menu.lst' file should be:
#
#     timeout 0
#     default 0
#     title minimal-kernel
#     kernel (hd0,0)/minimal-kernel
#
sudo cp menu.lst mnt/grub
# The contents of the `grub.input' file should be:
#
#     device (hd0) disk.img
#     root (hd0,0)
#     setup (hd0)
#     quit
#
sudo grub --device-map=/dev/null < grub.input
# We finally copy a multiboot specification compliant kernel
# to our disk image. You can get the one I have tried here:
#
#     http://altair.sk/uploads/minimal-kernel
#
# Its homepage :)
#
#     http://altair.sk/mediawiki/index.php/Minimal_Kernel
#
sudo cp minimal-kernel mnt
sudo umount mnt
# And you can boot it ...
qemu -m 100 -hda disk.img -boot c -no-kqemu
--------------------------------------------------
Somehow this way.


Reply to: