get the disk size of your source disk
sudo fdisk -l /dev/sda
output: Disk /dev/sda: 465,8 GiB, 500107862016 bytes, 976773168 sectors
read the original partition layout into image
sudo dd if=/dev/sda of=sparse.img bs=1M count=1
fill the image with "nothing" up to the above size. - This will not take any space on disk.
sudo dd if=/dev/zero of=sparse.img bs=1 count=0 seek=500107862016
check there are no other loop-devices active - if the output is not empty, see trouble shooting section
losetup -l -a
check if partition layout is the same as source drive
fdisk -l sparse.img
create loop devices for access of the partitions in the image
sudo kpartx -av sparse.img
output: add map loop0p1 (253:0): 0 976771072 linear 7:2 2048
read the data into the image using partclone
- this will increase space usage by "data size" plus "overhead".
sudo partclone.ntfs -s /dev/sda1 -o /dev/mapper/loop0p1 -b -L sparse.log
remove source drive to keep it save
shrink using gparted
- should be at least 10% smaller than target drive
create links because gparted
does not understand the devs kpartx
created.
ln -s /dev/mapper/loop0p1 sparse.img1
use gparted
to shrink the partition
sudo gparted sparse.img
alternatively you can shrink using ntfsresize
but you have to shrink the partition, too afterwards.
get min size
sudo ntfsresize -i /dev/mapper/loop0p1
test resize
sudo ntfsresize -n -s 100G /dev/mapper/loop0p1
real resize - this will increase space usage by up to "data size"
sudo ntfsresize -s 100G /dev/mapper/loop0p1
TODO: shrink partition
(unnecessary because shrinked not enlarged?) delete and recreate the loop devices because partition size changed
sudo kpartx -dv sparse.img
sudo kpartx -av sparse.img
(optional) TODO truncate image
check using ntfsresize
- for me this gives an OK answer
sudo ntfsresize -i /dev/mapper/loop0p1
insert target drive - double check you inserted the correct drive
(does not work because ntfsresize
marked the fs dirty) partclone
the image to the new drive
sudo partclone.ntfs -o /dev/sdXX -s /dev/mapper/loop0p1 -b -L restore.log
instead dd
the image to the new drive - either do not give a size or be 10% over the shrinked partition size
sudo dd if=sparse.img of=/dev/sdXX
check using ntfsresize
- FAILS for me, this should not happen as the image was OK and we created an identical copy of the image!!!
sudo ntfsresize -i /dev/sda1
delete loop devices
sudo kpartx -dv sparse.img
delete any loop devices that were not cleanly removed - if still some persist, either reboot or search the web on this.
sudo losetup -D
Finally you should try booting the disk then run Windows chkdsk / f
. After that use gparted
to expand the partition to it's full size.
1maybe try ntfsclone? – JPT – 2018-10-13T18:04:41.693
"A disk fails" <- there's your problem. Otherwise just shrink the partition on the source disk before copying. Then if you really want you can expand the partition on the source disk again. I would just use the Gparted live disk from https://gparted.sourceforge.io/
– BeowulfNode42 – 2018-10-27T07:21:35.993Well, I prefer not to mess with the source drive without having a backup. But of course you could do a standard backup with partclone first. – JPT – 2018-10-29T11:12:15.997