Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-16-2006, 02:20 AM   #1
Registered: Aug 2006
Distribution: Ubuntu
Posts: 87

Rep: Reputation: 15
make complete image file from partition file for qemu

Hi all,

I am working on a project building small linux system on Compact Flash (CF) card. I just found the qemu emulation software, and I reallty think it is very nice. I want to use it for my project.

So until now i always install my file system on the first primary partition of the CF card (/dev/sdb1) . I usually make an image file first-e.g. linux.img file-, copy it to the first partition of CF card (/dev/sdb1).

But I notice that qemu needs the whole image file (/dev/sdb - including the bootloader) to emulate the system.
As far as I know (I am newbee), that the whole partition contains the MBR where the bootloader stays.

So it will work if first i copy the image file linux.img to the /dev/sdb1:
dd if=linux.img of=/dev/sdb1
then setup bootloader on CF card, then recopy the CF card to a new image file:
dd if=/dev/sdb of=image.img
Can i directly make the new complete image file of CF card (/dev/sdb) from the image file linux.img for /dev/sdb1?

The problem is:
- the size of /dev/sdb1 image file is 518160384 bytes
- the size of /dev/sdb is 523321344 bytes
so the difference is not really the size of MBR (512 bytes).

a friend suggested me to first get the MBR and concatenate with the image of first partition:
dd if=/dev/sdb of=mbr.img bs=512 count=1
cat mbr.img linux.img >> cf.img
it didnt work, it gives the error "GRUB error 16" with qemu.

Then i tried also to use the same method but different size of mbr.img which is the difference of image files of /dev/sdb and dev/sdb1:
dd if=/dev/sdb of=mbr.img bs=512 count=10080
cat mbr.img linux.img >> cf.img
It didnt work either, it gives endless "GRUB GRUB GRUB ..." text with qemu.

So any hints how to do it?

thanks for any help
Old 11-16-2006, 07:30 AM   #2
LQ 5k Club
Registered: Oct 2003
Location: Western Australia
Distribution: debian IceWM
Posts: 5,555

Rep: Reputation: Disabled
you have not stated if you can boot the current raw image in qemu.

1 lets pretend you can....then allow a live cd to boot and then run the live cd with grub to modify the hd image file.

eg let file be linux.img on your first drive hda
let the optical be /dev/hdd

insert knoppix cd etc

cd /pathway/to/linux.img
qemu -hda linux.img -cdrom /dev/hdd -boot d -net none

knoppix (etc) will detect the partitions of the emulated drive
open a terminal and its commands are
root (hd0,0)
setup (hd0)

change hd0,0 to suit your /boot partition as per my tutorial

close down knoppix and qemu and boot to test
qemu -hda linux.img -boot c -net none
Old 11-16-2006, 08:04 AM   #3
Registered: Aug 2006
Distribution: Ubuntu
Posts: 87

Original Poster
Rep: Reputation: 15
Originally Posted by aus9
you have not stated if you can boot the current raw image in qemu.

i could not boot the image of linux.img directly with qemu. Because it contains only the root file system to be copied on the first (and the only) primary partition of Compact Flash Card, and no boot loader.

So basically i need an idea how to add the bootloader to this image file (linux.img) so i can boot it using qemu.

I can boot it using qemu, if I copy first linux.img to my first partition of my CF card (/dev/sdb1), setup bootloader there, and re-copy the whole CF card (/dev/sdb) to a new image file, and then emulate the new image file.
Can i do that just manipulate the linux.img without writing to the CF card?

I dont get it the way you told me using live cd.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Linux have software can make a ISO image file in KDE? explorer1979 Linux - General 5 06-02-2006 02:01 AM
How to make a image file for my disk( Including win2000&Redhat Linux system)? teradyne Linux - Software 3 06-02-2004 04:25 AM
get .config file for make from builted Image luponec Slackware 1 05-02-2004 01:52 PM
Hard Disk Partition&Make File System Problem jooj Linux - Hardware 3 02-23-2004 04:27 PM
How to grub install to a partition on an image file via a loopback Owen LaGarde Linux - Software 2 12-26-2003 09:06 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration