Recreate a bigger openwrt disk image based on the official original disk image

I try to recreate a bigger disk image file based on this one by the following steps:

# Obtain the partion table info on the original disk image file: 
$ sudo parted openwrt-19.07.7-x86-64-combined-ext4.img u s p
Model:  (file)
Disk /home/werner/vmware/openwrt-19.07.7-x86-64-combined-ext4.img: 558080s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End      Size     Type     File system  Flags
 1      512s    33279s   32768s   primary  ext2         boot
 2      33792s  558079s  524288s  primary  ext2

# Extract the partion image files:
$ dd if=openwrt-19.07.7-x86-64-combined-ext4.img of=0.img ibs=512 obs=1M skip=512 count=32768 oflag=direct,sync status=progress
$ dd if=openwrt-19.07.7-x86-64-combined-ext4.img of=1.img ibs=512 obs=1M skip=33792 count=524288 oflag=direct,sync status=progress

# Create a new empty but big disk image file with the same partition table type:
$ dd if=/dev/zero of=disk.img bs=1024k seek=1k count=0
$ sudo parted disk.img mklabel msdos

Then use gparted to create two partitions on it with unformatted file system and activate the boot flag on the 1st partition, as shown below:

$ sudo parted disk.img u s p
Model:  (file)
Disk /home/werner/vmware/disk.img: 2097152s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start    End       Size      Type     File system  Flags
 1      2048s    206847s   204800s   primary               boot
 2      206848s  2097151s  1890304s  primary

Rewrite the partition image files onto the newly created image:

$ sudo kpartx -av disk.img 
add map loop11p1 (253:2): 0 204800 linear 7:11 2048
add map loop11p2 (253:3): 0 1890304 linear 7:11 206848
$ sudo losetup --show -fP 0.img 
$ sudo losetup --show -fP 1.img 

$ sudo dd if=/dev/loop12 of=/dev/mapper/loop11p1 bs=1M oflag=direct,sync status=progress 
16+0 records in
16+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.993139 s, 16.9 MB/s
$ sudo dd if=/dev/loop13 of=/dev/mapper/loop11p2 bs=1M oflag=direct,sync status=progress 
253755392 bytes (254 MB, 242 MiB) copied, 14 s, 18.1 MB/s
256+0 records in
256+0 records out
268435456 bytes (268 MB, 256 MiB) copied, 14.8922 s, 18.0 MB/s
$ sudo kpartx -dv disk.img 

Change the PARTUUID info in the /boot/grub.cfg to reflect the new value of the image file. Then convert it to vmdk format, which can be tested in a vmware workstation:

$ qemu-img convert -f raw -O vmdk disk.img disk.vmdk

But it turns out that the newly created image file failed to boot within vmware, while the vmdk image converted from the original openwrt official imaga can boot successfully.

Any hints for this problem will be highly appreciated.



Thanks a lot. It does the trick. But this is just a resize focused method. I really want to find a from-scratch method which only use the partitions extracted from the official image.


Thank you very much for telling me the startup procedure on systems using BIOS firmware. The following manipulations should be appended to the initial post in this issue:

$ sudo losetup --show -fP disk.img

$ sudo grub-install --target i386-pc --boot-directory /media/werner/57f8f4bc-abf4-655f-bf67-946fc0f9f25b/boot/ /dev/loop10

Adapt the PARTUUID/UUID in the /boot/grub.cfg with appropriate value, i.e., for the current case, as shown below:

$ lsblk -o name,mountpoint,size,uuid,partuuid | grep loop10
loop10                                      1G                                      
├─loop10p1                                100M 57f8f4bc-abf4-655f-bf67-946fc0f9f25b 02d16efe-01
└─loop10p2                                923M 57f8f4bc-abf4-655f-bf67-946fc0f9f25b 02d16efe-02

Then unmount the disk image and convert it to VMDK format for testing in the VMware environment:

$ sudo losetup -d /dev/loop10
$ qemu-img convert -f raw -O vmdk disk.img disk.vmdk

It's all done now.



This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.