FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 07-07-2008, 12:18 AM
David Barrett
 
Default How to create qemu-bootable image using debootstrap?

What's the best way to create a raw disk image using debootstrap that
can be booted with qemu?


I think I've almost figured it out, but I'm not savvy with the low-level
file commands. Can you point me in the right direction?


I'm hacking together a few sources -- most notably
http://www.debian.org/releases/stable/i386/apds03.html.en -- but I'm
missing a couple steps. This is what I think I've got so far:


#-------------- 1. Create the raw image ------------
# Create 1GB raw image
dd if=/dev/zero of=image.raw bs=1024 count=1048576

# Format it with ext3 file system
??? how to do this ???
??? can I do it all with a single partition ???

# Mount it
mkdir -p image.mount
sudo mount -o loop,offset=32256 image.raw image.mount

#-------------- 2. Configure a chroot --------------
# Debootstrap it
/usr/sbin/debootstrap --arch i386 etch image.mount
http://ftp.us.debian.org/debian

# Create /etc/fstab as follows:
??? what goes in here ???

# Mount the file system inside the chroot
sudo chroot image.mount mount -a


# ---------- 3. Enable networking ----------------
# Though it'll ultimately be a qemu image, we need
# to temporarily use the host's network interface
# in order to get apt working.
sudo cp /etc/resolv.conf image.mount/etc
sudo cp /etc/hosts image.mount/etc


#----------- 4. Make it bootable -----------------
# First install the kernel
sudo chroot image.mount apt-get update
sudo chroot image.mount apt-get install
linux-image-2.6.24-17-generic

# Then install grub
sudo chroot image.mount apt-get install grub
sudo chroot image.mount apt-get grub-install /dev/????
sudo chroot image.mount apt-get update-grub


# ----------- 5. Done, boot it up! ------------
sudo qemu -kernel-kqemu image.raw


Granted, at this point its networking will be screwed up, but that's a
task for another day. I'm just trying to get it to boot. With this in
mind, can you fill in any of the blanks in the above script? Thanks!


-david


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 04:00 AM
David Barrett
 
Default How to create qemu-bootable image using debootstrap?

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?


Basically, grub-install appears to require an actual device, unlike
"parted" (which was unexpectedly happy being given a simple raw file).
My work-in-progress script for creating a bootable qemu image from
scratch is here; can you help me finish it?


echo "Creating 1GB file of zeros in $1.raw"
dd if=/dev/zero of=$1.raw bs=1024 count=1048576

echo "Formating $1.raw with ext2 filesystem"
/sbin/parted $1.raw mklabel msdos
/sbin/parted $1.raw mkpart primary ext2 0 954
/sbin/parted $1.raw mkpart extended 954 1069
/sbin/parted $1.raw mkpart logical linux-swap 954 1069
/sbin/parted $1.raw set 1 boot on
/sbin/parted $1.raw mkfs 1 ext2

echo "Mounting $1.raw on $1.mount"
mkdir -p $1.mount
sudo mount -o loop,offset=16384 -t ext2 $1.raw $1.mount

echo "Installing Etch into $1.mount"
sudo debootstrap --arch i386 etch $1.mount http://ftp.us.debian.org/debian

echo "Setting up host networking in $1.mount for apt"
sudo cp /etc/resolv.conf $1.mount/etc
sudo cp /etc/hosts $1.mount/etc

echo "Installing kernel and grub into $1.mount"
sudo chroot $1.mount apt-get update
sudo chroot $1.mount apt-get -y install linux-image-2.6-486 grub
sudo grub-install --root-directory=$1.mount/root $1.raw

Basically, this last command doesn't work; it fails as follows:

david@SonOfLappy:~/test$ sudo grub-install
--root-directory=blah.mount/root blah.raw

Probing devices to guess BIOS drives. This may take a long time.
Format of install_device not recognized.

Any ideas? Thanks!

-david


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 04:36 AM
Carl Fink
 
Default How to create qemu-bootable image using debootstrap?

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?
--
Carl Fink nitpicking@nitpicking.com

Read my blog at blog.nitpicking.com. Reviews! Observations!
Stupid mistakes you can correct!


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 06:13 AM
Joey Hess
 
Default How to create qemu-bootable image using debootstrap?

David Barrett wrote:
> 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?

You may be able to get grub-install to work using the --grub-mkdevicemap
option and a dummied up device map that points to the disk image.

> echo "Creating 1GB file of zeros in $1.raw"
> dd if=/dev/zero of=$1.raw bs=1024 count=1048576

But wouldn't it be easier to stop here and run:

qemu -cdrom mini.iso -hda $1.raw -boot c

(Downloading an appropriate d-i mini.iso or other iso first.)

--
see shy jo
 
Old 07-07-2008, 06:34 AM
David Barrett
 
Default How to create qemu-bootable image using debootstrap?

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?


-david


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 06:57 AM
David Barrett
 
Default How to create qemu-bootable image using debootstrap?

Joey Hess wrote:

David Barrett wrote:
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?


You may be able to get grub-install to work using the --grub-mkdevicemap
option and a dummied up device map that points to the disk image.


Ah, this sounds good -- can you give me any more detail on this? I'm
not finding anything particularly good with my own searches. I've read
the wiki page:


http://wiki.debian.org/Grub/grub-mkdevicemap.manpage

But I'm not quite sure where to go next. You see the script I'm working
on; can you propose a next step?


If it helps, I can copy /boot/grub/device.map from a working/bootable
QEMU image. But I don't know what to do with it. Can you offer me any
suggestions?




echo "Creating 1GB file of zeros in $1.raw"
dd if=/dev/zero of=$1.raw bs=1024 count=1048576


But wouldn't it be easier to stop here and run:

qemu -cdrom mini.iso -hda $1.raw -boot c

(Downloading an appropriate d-i mini.iso or other iso first.)


Heh, what fun would that be!

-david


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 07:41 AM
Andrei Popescu
 
Default How to create qemu-bootable image using debootstrap?

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.

Regards,
Andrei
--
If you can't explain it simply, you don't understand it well enough.
(Albert Einstein)
 
Old 07-07-2008, 08:18 AM
David Barrett
 
Default How to create qemu-bootable image using debootstrap?

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).


One way would be to boot the VM with the above trick and then install
grub from the inside... but there's *got* to be a way to install it
from the outside, straight into the raw image.


Joey's idea of grub-mkdevicemap sounds good; I'll need to look into that
more.


Thanks everyone for all the help!

-david


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 11:27 AM
Carl Fink
 
Default How to create qemu-bootable image using debootstrap?

On Mon, Jul 07, 2008 at 10:41:30AM +0300, 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.

That's where I was leading. I don't know qemu, but I do recall, for
instance, loadlin, and made a mental analogy.
--
Carl Fink nitpicking@nitpicking.com

Read my blog at blog.nitpicking.com. Reviews! Observations!
Stupid mistakes you can correct!


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-07-2008, 07:55 PM
Andrew Sackville-West
 
Default How to create qemu-bootable image using debootstrap?

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
 

Thread Tools




All times are GMT. The time now is 12:57 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org