This is going to be tricky to fix by hand. I hope you haven't modified any more data on this disk, apart from the broken partition table you wrote to it.
Using sfdisk, fdisk, etc to create a backup of the partition table is a good idea (when you don't accidentally type the wrong command :) ). But for extra insurance I like to back up the boot sectors of my drives using dd.
Are you sure that sda1 starts at block 1, or was that a guess? It used to be common that only 1 block was used at the start of a disk, since that's all you need to hold the MBR and (primary) partition table, but in recent years it's been common for partitioning software to reserve more space, eg a starting sector of 63 for the 1st partition is not unusual. I've also seen partitioning software (gparted, IIRC) reserve a megabyte at the start of a drive and then force all subsequent partitions onto megabyte boundaries.
On older systems it was important for partitions to start and stop on cylinder boundaries. IOW, unpartitioned region at the start of the disk should be a whole number of cylinders, and so should each subsequent primary partition; there will generally also be unallocated space at the end of the disk. But that's generally not been an issue for many years, but a lot of partitioning software still mentions it, just in case you're interested. :)
However, partitions do have to start and stop on sector boundaries. And that makes analysis of your block-oriented data in the 1st listing a lot easier. Thus 2441214+ blocks can only refer to 2441214.5 blocks = 4882429 sectors = 2499803648 bytes.
But rather than trying to fix this by hand, you should seriously consider using a tool like testdisk. You may even have it already installed on your distro, if not, it should be in your repos.
Try this:
dd if=<path of squashfs root> of=~/filesystem.img bs=1m
The should give you a raw mountable partition. If you run into errors, mounting, try without the bs argument. It will be slower, but it’s safer.
Best Answer
You can do this on the host machine. Most tools like
fdisk
will operate on files, andkpartx
gives you access to partitions in a file.Create a new empty 100GiB sparse image (make this slightly bigger than the size of the partition image)
Partition the image file with
fdisk
Make the partitions in the image file available is individual devices
Copy the partition image into the partition
Extend the filesystem to fill the entire partition
Close the partitions
Dismantle the loopback device