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
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/
Extract the MBR
sudo dd if=/dev/sdX of=myimage/mbr.img bs=446 count=1
replace
/dev/sdX
with the corresponding device.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.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.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/
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
How to Parse Http Headers Using Bash
How to List All Binary File Extensions Within a Directory Tree
How to Find The Memory Consumption of a Particular Process in Linux for Every 5 Seconds
How to Take Advantage of The Vdso Object with Your Own Programming Language
Sudo Apt-Get Update Fail on Ubuntu 17.04
Using Socat for Raw Serial Connection
In a Sigill Handler, How to Skip The Offending Instruction
Using Netcat to Pipe Unix Socket to Tcp Socket
How to Add an Icon to The Bash Prompt
Expect, Interact and Then Again Expect
Pcre Issue When Setting Up Wsgi Application
How to Manually Install The Eclipse-Cdt Plugin from an Archive/Zip on Ubuntu
Unix Domain Sockets Not Accessable Across Users
Linux Kernel Device Driver to Dma into Kernel Space