I'm creating an image in memory (/tmp is a tmpfs):
$ dd if=/dev/zero of=/tmp/sdcard.img bs=512 count=3147775
It's supposed to hold a partition table and the first 3 partitions of a device
$ losetup /dev/loop0 /tmp/sdcard.img $ dd if=bootloader.img of=/dev/loop0 bs=512
The first 2048 sectors contain a partition table.
$ fdisk -l /tmp/sdcard.img Disk /dev/loop0: 1.5 GiB, 1611660800 bytes, 3147775 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x0000de21 Device Boot Start End Sectors Size Id Type /dev/loop0p1 2048 1050623 1048576 512M c W95 FAT32 (LBA) /dev/loop0p2 1050624 2099199 1048576 512M 83 Linux /dev/loop0p3 2099200 3147775 1048576 512M 83 Linux
But I have a problem.
I want to add a fourth partition /dev/loop0p4, that starts at 3147775 and ends at 37748724.
I don't want to physically create the partition, but I want to modify the partition table so that it thinks this drive exists.
However, when I use
fdisk for this purpose it complains
Value out of range.
How can I force
fdisk to just do it. I don't care that the partition table is invalid. I'm going to be dding this to a larger disk and then formatting it later. I'd like the parition table to be part of what I dd to that larger disk (there are reason for this, would rather not delve into those details). All I want to know is how I can write a partition table with these arbitrary values without pulling out the hex editor.