I have 3 images. Each image was done by cloning (by dd) a partition (these partitions formatted using ext3 file system). One partition is boot-able with GRUB1 (CentOS)
How can I combine them to one disk image?
(I can copy the partitions images using dd command, but I don't know how to create partitions table and make boot working).
Create a disk image. The following command will create a 10G sparse image:
Partition the image with fdisk:
Make sure you create partitions that are at least as large as the ones you've imaged! For this example I created the following layout:
Use
kpartx
to create devices corresponding to each one of the partitions:This will create entries under
/dev/mapper
:Now you can copy your partition images onto your partitions:
Now remove the device mappings:
And you're all set!
Notes
You could also accomplish the same thing by using
dd
and theseek
parameter (to start writing at the appropriate offset in your disk image file) instead of usingkpartx
, but I think that usingkpartx
is less error-prone.This will not result in a bootable image. If you want that, you'll also have to install a boot loader onto it.