```

# make the images into /dev devices

sudo losetup /dev/loop0 ./source.img    # source.img is on /dev/loop0

sudo losetup /dev/loop1 ./target.img.   # target.img is on /dev/loop1


# make sure you have `gdisk` installed for these

sudo sgdisk /dev/loop0 -R /dev/loop1   # this copies the partition
table from source.img to target.img

sudo sgdisk -G /dev/loop1     # This randomizes the GUIDs on the new
partition table so your OS doesn't get confused


# do a partprobe to tell the kernel that the new partitions exist

sudo partprobe /dev/loop1


# Verify loopback devices have partitions you expect

#   adjust `for i in {0..3}` below if for some reason the partition
index (/dev/loop0p# and/or /dev/loop1p#) starts with 1 instead of 0

ls -lahtr /dev/loop*


# dd if/of each partition from source.img to target.img

for i in {0..3}; do sudo dd status=progress if=/dev/loop0p${i}
of=/dev/loop1p${i} ; done


# for good measure and because I'm old

sync


# how to detach the images from /dev devices

sudo losetup -d /dev/loop0

sudo losetup -d /dev/loop1

```


On Sat, Nov 29, 2025 at 6:00 PM prk0ghy via GNU coreutils General
Discussion <[email protected]> wrote:

> Hello Everyone,
>
> thank you for the great work on coreutils, i use them so often and would
> not know what to do without them. I have an issue with dd that I am not
> able to solve myself, that is why I am seeking for help here.
> I am trying to copy parts of a disk image to another file. I do this
> because the original disk image is 500GB in size but only ~25GB are
> actually used by partitions. My Idea was to copy only the first part of the
> image. fdisks displays the partitions like this:
>
> ```
> fdisk -l ./source.imgDisk ./source.img: 465.76 GiB, 500107862016 bytes,
> 976773168 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: gpt
> Disk identifier: AAAAA-AAAAA-AAAAA-AAAAA-AAAAA
>
> Device                                   Start      End  Sectors  Size Type
> ./source.img1    2048   616447   614400  300M Windows recovery environment
> ./source.img2  616448   821247   204800  100M EFI System
> ./source.img3  821248  1083391   262144  128M Microsoft reserved
> ./source.img4 1083392 52891647 51808256 24.7G Microsoft basic data
> ```
>
> I tried it like this:
>
>
> ```
> sudo dd status=progress count=52891647 if=/source.img of=/target.img
> ```
>
> After the operation is finished I get:
>
>
> ```
> ❯ fdisk -l ./taget.imgGPT PMBR size mismatch (976773167 != 52891646) will
> be corrected by write.
> Disk ./taget.img: 25.22 GiB, 27080523264 bytes, 52891647 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: 0x4afd3a95
>
> Device                                               Boot Start      End
>  Sectors  Size Id Type
> ./taget.img1          1 52891646 52891646 25.2G ee GPT
> ```
>
>
>
> I have no Idea what is happening. I tried iflag=sync conv=sync but the
> result is the same. Is there something I am missing?
>
>
> Thank you very much and have a nice time
>
>
> prk0ghy
>
>
> ---
> Version:
> coreutils.x86_64                                     9.6-6.fc42
>                    <unknown>coreutils-common.x86_64
>      9.6-6.fc42                              <unknown>
> Kernel:
> Linux host 6.17.1-300.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Oct  9
> 18:53:18 UTC 2025 x86_64 GNU/Linux
>
>
> OS:
> Description: Bluefin (Version: gts-42.20251125)

Reply via email to