How to Create a Multi Partition Sd Disk Image Without Root Privileges

How to mount one partition from an image file that contains multiple partitions on Linux?

Let's say $IMAGE is set to the path to your image file.
You could write a small script by using

fdisk -u sectors -l $IMAGE

to get a list of partitions inside the image. And then use a sequence of

mount -o ro,loop,offset=$OFFSET -t auto $IMAGE /media/$DEST

Where offset is calculated means the info from fdisk (start sector * size of a sector in bytes) and $DEST a unique name for each of the partitions.

That's not directly the solution but I hope a pretty good indication on how to realize it. If you make the job once, you've some small nice beginning for some forensic toolkit!​​​​​​​​​​​​​​​​​​​​​

How to create an .IMG image of a disc (sd card) without including free space?

The best thing to do is

  1. Copy all the files from all the partitions preserving meta data

    mkdir -p myimage/partition1

    mkdir myimage/partition2

    sudo cp -rf --preserve=all /media/mount_point_partition1/* myimage/partition1/

    sudo cp -rf --preserve=all /media/mount_point_partition2/* myimage/partition2/

  2. Extract the MBR

    sudo dd if=/dev/sdX of=myimage/mbr.img bs=446 count=1

    replace /dev/sdX with the corresponding device.

  3. Partition the destination disk into partitions with sizes greater than copied data and should be of the same format and same flags using gparted. Google how to partition a disk.

  4. Mount the freshly formatted and partitioned disk. On most computers, you just need to connect the disk and you can find the mounted partitions in /media folder.

  5. Copy the previously copied data to destination partitions using following commands

    sudo cp -rf --preserve=all myimage/partition1/* /media/mount_point_partition1/

    sudo cp -rf --preserve=all myimage/partition2/* /media/mount_point_partition2/

  6. Copy back the MBR

    sudo dd if=myimage/mbr.img of=/dev/sdX bs=446 count=1

Now njoy Ur new disk!

Creating ext3 image from yocto class

Thanks for the answers. IMAGE_FSTYPES I am aware of. For several embedded platforms there is a class which handles the sdcard population, this bbclass is selected via IMAGE_FSTYPES.

I looked at WIC which I was not aware of. It looks promising. In this stage I do not have the time to check if it is capable to fullfill all my requirements and since I already had a working bbclass where I only wanted to change from FAT to ext3.

The advantage of a custom class is that you basically can do anything you want. Create an SD card with main and redundant kernel and root partition. Bootloader and preloader at specific locations. dedicated partitions for system recovery and persistent data.

Well to answer my own question: e2tools
It allows to create directories on and copy files to ext2/ex3 file images. It is an easy replacement for mtools which works on FAT partitions.



Related Topics



Leave a reply



Submit