On Mon, 19 Sep 2016, at 17:49, Colin Law wrote: > On 19 September 2016 at 17:18, Robert McWilliam <r...@allmail.net> wrote: > Is not the partition table in the space before the first partition? So > in the example I posted where I had > > Device Boot Start End Sectors Size Id Type > /dev/sdb1 8192 137215 129024 63M c W95 FAT32 (LBA) > /dev/sdb2 137216 4233215 4096000 2G 83 Linux > > is not the partition table in sectors 0 to 8191? So if I copy sectors > 0 to 2333215 that should include the partition table and all the > partitions. Is that not correct?
Put a 4 in front of that end sector number, lose one of the 3's, and yes, I think you'd get partition table and those two partitions. That kind of transcription error is why I don't think you should play with offsets directly. That looks like a human transcription error so you wouldn't have exactly that type of error in a script, but parsing text to get a number is really fragile (what appears in the "Boot" column there when it has something? Will your parsing be thrown off that? What else might change?). I had thought you were going to grab just the partition you wanted. If you are grabbing everything up to the end of the last partition in the partition table then yeah that'll work and can be written back to any card big enough to take it and be usable (with some unusable space at the end if the card is bigger than the partitions). > To do it that way I believe I would have to write a script to pick up > the partition info from the original card, mount and copy the files in > each partition, and save the partition info with the files. Then to > restore it I would need a script to re-partition the new card and copy > the files across to each partition. If you have an image of the whole card then the partition table is in it, if you have an image of just the partition then you don't need the partition table. For a whole card image you can make loopback devices for the partitions in it: $sudo losetup -Pf --show disk_image.raw then mount the partitions $sudo mount /dev/loop0p1 /mnt/point then copy the files to a card (or anywhere else) with normal file management tools, unmount the image: $sudo umount /mnt/point and detach the loopback device $sudo losetup -d /dev/loop0 For the single partition image you don't need the loopback device and can mount it directly with: $sudo mount -o loop partition_image.raw /mnt/point As for partitioning the destination card: I'd keep them all partitioned with one partition the full size of the card. If you want a clean card to restore an image too: rm -rf /where/its/mounted (be very, very, careful if putting that in a script with something to determine the mount point...). Robert -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/