Lets create an image that looks like the following
Image to Copy
sudo parted Nacho\'s\ Image.img unit B print
Model: (file)
Disk /share/CACHEDEV1_DATA/tv/incoming/nacho/Nacho's Image.img: 63864569856B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194304B 63963135B 59768832B primary fat16 boot, lba
2 63963136B 63864569855B 63800606720B primary ext4
Create a blank image
dd if=/dev/zero of=image.img bs=1G count=55
Add partitions
parted image.img
(parted) mklabel
mklabel
New disk label type? msdos
msdos
Warning: The existing disk label on
/image.img will be destroyed and all
data on this disk will be lost. Do you want to continue?
Yes/No? y
y
(parted) unit B
unit B
(parted) mkpart
mkpart
Partition type? primary/extended? primary
primary
File system type? [ext2]? fat16
fat16
Start? 4194304B
4194304B
End? 63963135B
63963135B
(parted) mkpart
mkpart
Partition type? primary/extended? primary
primary
File system type? [ext2]? ext4
ext4
Start? 63963136B
63963136B
End? 100%
100%
(parted) print
Model: (file)
Disk /image.img: 59055800320B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194304B 63963135B 59768832B primary lba
2 63963136B 59055800319B 58991837184B primary
(parted) set 1 boot on
set 1 boot on
(parted) print
Model: (file)
Disk /image.img: 59055800320B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194304B 63963135B 59768832B primary boot, lba
2 63963136B 59055800319B 58991837184B primary
(parted) quit
Mount the partiion to a loopback device
losetup -o 4194304 -f image.img
Copy contents from one device to another
dd if=/dev/loop5 of=/dev/loop6 bs=1K
Make filesystem on partition
mkfs -t ext4 /dev/loop6
or
mke2fs -t ext4 /dev/loop6
Mount the partition
sudo mount -t ext4 -o loop,offset=63963136 image.img p2
Copy contents from one folder to out newly mounted partition
rsync -av <source> p2