The officially official Devuan Forum!

You are not logged in.

#1 2023-04-01 17:50:08

erdos
Member
Registered: 2018-06-04
Posts: 88  

how to easily copy a windows partition?

I have a Hp desktop equipped with 2 HDD, one for windows7, the other for Chimera.

My windows 7 boot partition has run into problem and can't boot.  I would like to reinstall win7 but want to backup the windows boot partition to an external USB hard drive first.  how do I copy the entirely of windows partition to external USB drive from Chimera?

thanks

Last edited by erdos (2023-04-02 23:32:00)

Offline

#2 2023-04-01 18:15:42

steve_v
Member
Registered: 2018-01-11
Posts: 347  

Re: how to easily copy a windows partition?

How long is a piece of string?
There are about 50 bazillion ways to copy a partition, starting with a dead simple 'cp' of the files or 'dd' to an image file...
Personally I quite like the flexibility and features of clonezilla, but it all depends what kind of backup you want - just the files, a full disk image with the boot sectors and all that jazz, or a bitwise clone to another disk?

Last edited by steve_v (2023-04-01 18:19:54)


Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Online

#3 2023-04-02 01:34:06

zapper
Member
Registered: 2017-05-29
Posts: 868  

Re: how to easily copy a windows partition?

The best way to copy partitions that I know of, is to load a linux live distro and plug in a huge fast SSD Flash Drive or Portable SSD Drive  to a usb 3.0, if you want this to not take forever,and then use dd to copy it.

dd if=/dev/sdX of=/media/sdY/your.qcow2 bs=10M status=progress

the X is the location of the windows partition and the Y is the drive where you want to put the image on. qcow2 doesn't need to be the type of format you want. It has to be mounted though.

I have done this many times when I break my installation and I need to clone back to get my OS back to normal.

Thankfully, this is usually not hard at all.

Though you might need a lot of space for this to work. Though, it might still be a fast transition, it depends how you intend to do this.

If you are using 4th gen or newer, this won't take too long even if its a bloody terrabyte or more.

As an obvious, make sure you aren't reckless about dd.

If nothing else, you could also use this as a further preventative measure to protect yourself from a crash if your operating system updates something and it breaks, you will now have a fallback option.


Freedom is never more than one generation away from extinction. Feelings are not facts
If you wish to be humbled, try to exalt yourself long term  If you wish to be exalted, try to humble yourself long term
Favourite operating systems: Hyperbola Devuan OpenBSD
Peace Be With us All!

Offline

#4 2023-04-02 04:52:26

GlennW
Member
From: Brisbane, Australia
Registered: 2019-07-18
Posts: 596  

Re: how to easily copy a windows partition?

I suggest the same as zapper says above. Well worth the time.


pic from 1993, new guitar day.

Offline

#5 2023-04-02 07:42:11

PedroReina
Member
From: Madrid, Spain
Registered: 2019-01-13
Posts: 267  
Website

Re: how to easily copy a windows partition?

I use Partimage: https://www.partimage.org/

Offline

#6 2023-04-02 08:17:57

Camtaf
Member
Registered: 2019-11-19
Posts: 410  

Re: how to easily copy a windows partition?

You only need your actual/personal data, so use a 'live' Linux pendrive to copy it to a USB drive, (formatted as NTFS would probably be best, for re use/re installing by/to Windows partition.

Online

#7 2023-04-02 12:12:50

delgado
Member
Registered: 2022-07-14
Posts: 168  

Re: how to easily copy a windows partition?

'partition' and 'drive' seem a bit mixed-up. To see what you have:

 $ lsblk

Offline

#8 2023-04-02 12:41:26

steve_v
Member
Registered: 2018-01-11
Posts: 347  

Re: how to easily copy a windows partition?

zapper wrote:

dd if=/dev/sdX of=/media/sdY/your.qcow2 bs=10M status=progress

GlennW wrote:

I suggest the same as zapper says above. Well worth the time.

dd is simple, but it's also pretty slow as it'll copy everything, including empty blocks.

zapper wrote:

load a linux live distro

Camtaf wrote:

use a 'live' Linux pendrive

There's no need for a live distro here, regardless of the method used.
Just make the windows partition is not mounted and you can do it from Devuan (as the OP requested). dd is of course available by default, and partimage and clonezilla (which includes partimage) are in the repos.


Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Online

#9 2023-04-02 21:13:27

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

zapper wrote:

The best way to copy partitions that I know of, is to load a linux live distro and plug in a huge fast SSD Flash Drive or Portable SSD Drive  to a usb 3.0, if you want this to not take forever,and then use dd to copy it.

dd if=/dev/sdX of=/media/sdY/your.qcow2 bs=10M status=progress

thank you!  I used above command to backup my windows partition C on external drive.  Works perfect!

I reinstalled windows 7 onto the partition #1 in hard disk #1 (/dev/sda1), now how do i restore the qcow2 image on my external drive to this partition?

erdos@htpc-devuan:~/Downloads/m64py-0.2.5$ sudo fdisk -l
[sudo] password for erdos: 
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WD5000AAKS-6
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: 0x1549f232[/c]

[c]Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048 204812287 204810240  97.7G  7 HPFS/NTFS/exFAT
/dev/sda2       204812685 309670262 104857578    50G a5 FreeBSD
/dev/sda3       309861721 953151487 643289767 306.7G  f W95 Ext'd (LBA)
/dev/sda4       953152515 976768064  23615550  11.3G  7 HPFS/NTFS/exFAT
/dev/sda5       309861784 953151487 643289704 306.7G  7 HPFS/NTFS/exFAT[/c]

[c]Partition table entries are not in disk order.[/c]

[c]Disk /dev/sdb: 55.9 GiB, 60022480896 bytes, 117231408 sectors
Disk model: Corsair Force LS
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: 0x287905c2[/c]

[c]Device     Boot     Start       End  Sectors  Size Id Type
/dev/sdb1  *         2048  39063551 39061504 18.6G 83 Linux
/dev/sdb2        39065598 117229567 78163970 37.3G  5 Extended
/dev/sdb5        39065600 113283071 74217472 35.4G 83 Linux
/dev/sdb6       113285120 117229567  3944448  1.9G 82 Linux swap / Solaris 

Last edited by erdos (2023-04-02 23:33:33)

Offline

#10 2023-04-03 08:54:22

Camtaf
Member
Registered: 2019-11-19
Posts: 410  

Re: how to easily copy a windows partition?

There's no need for a live distro here, regardless of the method used.
Just make the windows partition is not mounted and you can do it from Devuan (as the OP requested). dd is of course available by default, and partimage and clonezilla (which includes partimage) are in the repos.

how do I copy the entirely of windows partition to external USB drive from Chimera?

I don't use Chimera, so using a 'live' Linux pendrive would be safest, in my opinion....

....how ever, it seems that they used 'dd', & now want to restore their files, so will have to 'mount' that 'disk image' to get at them.....

OP should really have just copied them to an external drive!

Last edited by Camtaf (2023-04-03 08:56:13)

Online

#11 2023-04-03 10:32:23

steve_v
Member
Registered: 2018-01-11
Posts: 347  

Re: how to easily copy a windows partition?

Camtaf wrote:

OP should really have just copied them to an external drive!

Or, ya know, answered the question I posed in the very first reply WRT what kind of backup they wanted. Vague questions beget suboptimal answers, what else is new. roll

@OP: "Restoring" a dd disk image is simply reversing the dd command, and will return the disk to the exact state it was in when you imaged it (broken windows install included). However this is likely not what you want.
To restore files from the image you will first need to mount it as a loopback filesystem.

Assuming it's a raw disk image (i.e the ".qcow" extension is irrelevant and qemu is not involved), you want something like 'mount -o loop,offset=[offset of the partition you want] [image file] [mountpoint]', or 'losetup --partscan --find [image file]' to find the partitions for you and create device nodes you can mount like any other filesystem.
Examples of several approaches here, among other places easily found with a web search.

If you want accurate advice, please be accurate WRT to partitions, disks, filesystems, and most importantly, your end-goal. As Camtaf said, this would have been easier if we had known you wanted to restore your files rather than the entire disk.

Last edited by steve_v (2023-04-03 11:18:13)


Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Online

#12 2023-04-04 03:10:02

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

steve_v wrote:

If you want accurate advice, please be accurate WRT to partitions, disks, filesystems, and most importantly, your end-goal. As Camtaf said, this would have been easier if we had known you wanted to restore your files rather than the entire disk.

thank you for the reply! smile

It turned out that my windows partition failed to boot because incorrect SATA settings in BIOS.  I changed bios setting for Sata controller mode from 'RAID' to 'AHCI' during adding a SSD to use devuan.  that rendered windows partition unbootable.  Now after reinstall windows, I had it fixed by changing windows registry in 'IDE' mode to support 'AHCI' mode for dual boot with Devuan. 

Fortunately I made a disk copy of my previous windows partition with everything on it. I can launch 'qcow2' image in VM to recover those installed apps.

Offline

#13 2023-04-04 06:35:47

zapper
Member
Registered: 2017-05-29
Posts: 868  

Re: how to easily copy a windows partition?

@steve its not as slow as you think if you connect to a port with usb 3.0+ and are using SSD or better.

Btw,  it is actually possible to disk clone from SSD to qcow2 image on a usb storage drive like onto this:

/media/sdb/files

Not even on just doing /dev/sdb directly, but putting it in the partition itself as a qcow2.

I love that this is possible as a final edit!

@erdos Glad it helped, I do this a lot, because I use a testing version of Hyperbola. I have done this with Devuan as well though. big_smile

Btw, I actually suggested you copy them to a usb drive just to be safe. If I thought copying to a different partition within it, I would have suggested it. I didn't because that might cause a can of worms.

Glad you listened to that part and yeah, steve is correct, reversing it was what I was suggesting.

Although, as steve also mentioned, if you wanted to restore files,  a better option would have been available.

Funny thing, btw I use partimage afterwards! @GlennW mentioned partimage so I thought I would respond.

I actually have had to resize my installs from time to time when I do something foolish, so I usually end up doing the following:

I have a Hyperbola install that is light, like less than 150GB, with the stuff I want more or less.

Then I copy to /dev/sda, in emergencies and IF I know the image is RIGHT one.

Then I load a devuan persistent install via portable ssd and then finally I do what is needed to reclaim space via cfdisk /dev/sda

Then finally, once I have done the other steps to get it running properly, which I forget due to it being on a different laptop.

I'll modify this post later, but once its been added to the point where I can use lvm to add it to the partitions, at that point, I load the normal OS and do the last step via lvmextend.

If this sounds like a huge massive amount of work, it is.

You will have less steps probably due using Devuan and not Hyperbola.

That being said, I like DIY distros like Hyperbola.

big_smile

Its not like Arch which breaks a lot but it also is still DIY.

Anywho, glad to be useful for once.

If you ever are concerned about losing your files very badly, that command you used will be a good fallback.

As long as you keep it both safe and on usbs that aren't likely to fail.

Rant over...

wink

Last edited by zapper (2023-04-04 06:37:16)


Freedom is never more than one generation away from extinction. Feelings are not facts
If you wish to be humbled, try to exalt yourself long term  If you wish to be exalted, try to humble yourself long term
Favourite operating systems: Hyperbola Devuan OpenBSD
Peace Be With us All!

Offline

#14 2023-04-04 16:41:46

ribcage
Member
Registered: 2020-11-10
Posts: 7  

Re: how to easily copy a windows partition?

Why the hell do you make everything so complex? How in the world did qcow2 get in here?

This makes a copy of your Windows partition to your usb drive or whatever:

dd if=/dev/sda1 of=/yourusbdrive/win7backup

Then you mount your backup:

mount /yourusbdrive/win7backup /mnt

And copy all your stuff from /mnt to your new Windows install. No need for virtual machines or any of this crap.

Offline

#15 2023-04-05 07:13:19

zapper
Member
Registered: 2017-05-29
Posts: 868  

Re: how to easily copy a windows partition?

ribcage wrote:

Why the hell do you make everything so complex? How in the world did qcow2 get in here?

This makes a copy of your Windows partition to your usb drive or whatever:

dd if=/dev/sda1 of=/yourusbdrive/win7backup

Then you mount your backup:

mount /yourusbdrive/win7backup /mnt

And copy all your stuff from /mnt to your new Windows install. No need for virtual machines or any of this crap.

This is true, but having a backup isn't a bad idea just in case.  wink


Freedom is never more than one generation away from extinction. Feelings are not facts
If you wish to be humbled, try to exalt yourself long term  If you wish to be exalted, try to humble yourself long term
Favourite operating systems: Hyperbola Devuan OpenBSD
Peace Be With us All!

Offline

#16 2023-04-08 14:26:44

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

Hi guys

I need help to restore the windows image I created back to my HDD. 
My backup image is on /media/erdos/easystore/Backup/, and I tried to restore to first partition of HDD #1,  identified by devuan as /dev/sda1,  devuan is on /dev/sdb

error received running dd command:

erdos@htpc-devuan:/etc/samba$ sudo dd if=/media/erdos/easystore/Backup/HP.qcow2 of=/dev/sda1 bs=10M status=progress
[sudo] password for erdos: 
104857600000 bytes (105 GB, 98 GiB) copied, 2935 s, 35.7 MB/s
dd: error writing '/dev/sda1': No space left on device
10000+1 records in
10000+0 records out
104862842880 bytes (105 GB, 98 GiB) copied, 2936.54 s, 35.7 MB/s
You have new mail in /var/mail/erdos
erdos@htpc-devuan:/etc/samba$

afterwards, I reboot my machine, but windows won't boot, throwing error,  returning to devuan and output of 'fdisk',  HDD #1 now shows up as on '/dev/sdb' instead of /dev/sda neutral

erdos@htpc-devuan:/etc/grub.d$ sudo fdisk -l
[sudo] password for erdos: 
Disk /dev/sdb: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WD5000AAKS-6
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: 0x1549f232

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sdb1  *         2048 204812287 204810240  97.7G  7 HPFS/NTFS/exFAT
/dev/sdb2       204812685 309670262 104857578    50G a5 FreeBSD
/dev/sdb3       309861721 953151487 643289767 306.7G  f W95 Ext'd (LBA)
/dev/sdb4       953152515 976768064  23615550  11.3G  7 HPFS/NTFS/exFAT
/dev/sdb5       309861784 953151487 643289704 306.7G  7 HPFS/NTFS/exFAT

Partition table entries are not in disk order.

Disk /dev/sda: 55.9 GiB, 60022480896 bytes, 117231408 sectors
Disk model: Corsair Force LS
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: 0x287905c2

Device     Boot     Start       End  Sectors  Size Id Type
/dev/sda1  *         2048  39063551 39061504 18.6G 83 Linux
/dev/sda2        39065598 117229567 78163970 37.3G  5 Extended
/dev/sda5        39065600 113283071 74217472 35.4G 83 Linux
/dev/sda6       113285120 117229567  3944448  1.9G 82 Linux swap / Solaris

Disk /dev/sdh: 12.73 TiB, 14000519643136 bytes, 27344764928 sectors
Disk model: easystore 264D  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: B0F4FD99-AACA-4B97-BBF2-A3E7661D0DF4

Device     Start         End     Sectors  Size Type
/dev/sdh1   2048 27344762879 27344760832 12.7T Microsoft basic data

when I tried to mount windows system partition to /dev/sdb1,

erdos@htpc-devuan:/etc/grub.d$ sudo mount -t ntfs /dev/sdb1 /mnt
Failed to read last sector (204812620): Invalid argument
HINTS: Either the volume is a RAID/LDM but it wasn't setup yet,
   or it was not setup correctly (e.g. by not using mdadm --build ...),
   or a wrong device is tried to be mounted,
   or the partition table is corrupt (partition is smaller than NTFS),
   or the NTFS boot sector is corrupt (NTFS size is not valid).
Failed to mount '/dev/sdb1': Invalid argument
The device '/dev/sdb1' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?

I can mount the backup image without issue

erdos@htpc-devuan:/etc/grub.d$ sudo mount '/media/erdos/easystore/Backup/HP.qcow2' /mnt
[sudo] password for erdos: 
erdos@htpc-devuan:/etc/grub.d$ ls /mnt
'$Recycle.Bin'   BOOTSECT.BAK  'Documents and Settings'   img2-001.raw       'Linksys Driver'   PerfLogs        'Program Files (x86)'         TightVNC      Windows
 Boot            Brother        hiberfil.sys              inetpub             MSOCache          ProgramData      Recovery                     Users
 bootmgr         Config.Msi     hp                        INSTALLHELPER.LOG   pagefile.sys     'Program Files'  'System Volume Information'   WebMapCache
erdos@htpc-devuan:/etc/grub.d$ ls -l /mnt
total 3351397
drwxrwxrwx 1 root root       4096 Jul 22  2015 '$Recycle.Bin'
drwxrwxrwx 1 root root       4096 May 24  2013  Boot
-rwxrwxrwx 1 root root     383786 Nov 20  2010  bootmgr
-rwxrwxrwx 1 root root       8192 Oct 19  2012  BOOTSECT.BAK
drwxrwxrwx 1 root root          0 Jan 31  2015  Brother
drwxrwxrwx 1 root root          0 May 18  2019  Config.Msi
lrwxrwxrwx 2 root root         10 Jul 14  2009 'Documents and Settings' -> /mnt/Users
-rwxrwxrwx 1 root root 3220664320 May 22  2019  hiberfil.sys
drwxrwxrwx 1 root root       4096 Jan  8  2009  hp
-rwxrwxrwx 1 root root     921624 Mar 28  2016  img2-001.raw
drwxrwxrwx 1 root root          0 Jul 24  2015  inetpub
-rwxrwxrwx 2 root root        112 Jun 23  2012  INSTALLHELPER.LOG
drwxrwxrwx 1 root root          0 Jul 10  2009 'Linksys Driver'
drwxrwxrwx 1 root root          0 Jul 17  2009  MSOCache
-rwxrwxrwx 1 root root  209715200 May 21  2019  pagefile.sys
drwxrwxrwx 1 root root          0 Jul 13  2009  PerfLogs
drwxrwxrwx 1 root root      12288 Nov 23  2018  ProgramData
drwxrwxrwx 1 root root       8192 Oct 10  2016 'Program Files'
drwxrwxrwx 1 root root      20480 Oct 10  2016 'Program Files (x86)'
drwxrwxrwx 1 root root          0 Oct 19  2012  Recovery
drwxrwxrwx 1 root root      28672 Aug 23  2016 'System Volume Information'
drwxrwxrwx 1 root root          0 Sep 18  2012  TightVNC
drwxrwxrwx 1 root root       4096 Jul 30  2015  Users
drwxrwxrwx 1 root root       4096 May 10  2016  WebMapCache
drwxrwxrwx 1 root root      40960 Jan 22  2019  Windows
erdos@htpc-devuan:/etc/grub.d$

please advise

Last edited by erdos (2023-04-08 14:32:21)

Offline

#17 2023-04-11 18:05:35

delgado
Member
Registered: 2022-07-14
Posts: 168  

Re: how to easily copy a windows partition?

Just thinking about the error messages - not a solution, to many assuptions! And probably unreadeable anyway.

tl;dr: Summery of the text below is: The last 5MB were (might) not written back to /dev/sdb1.

dd error:

Sizes of partition and disk-image:
The partition size of /dev/sdb1 by fdisk output: 204810240 Sectors * 512 Byte/Sector = 104862842880 Byte
The partition size of /dev/sdb1 divided in blocks of 10M is "10000.5" (echo 204810240*512/1024/1024/10 | bc -l). Block count in dd is not supposed to be a fractional number!
Assumed behavior of dd during image creation: It read 10001 whole blocks. EDIT: WRONG at this point - the rest are follow-up errors!
Resulting image-file size then is: 10001 * 10M = 104868085760 byte (or 5MB bigger than /dev/sdb1). Please confirm or report the actual size of HP.qcow2.
This would cause the error when restoring.

dd parameters can be tuned to restore without an error:
(half block size and doubled block count result in integer numbers and the size of /dev/sdb1)

dd if=/media/erdos/easystore/Backup/HP.qcow2 of=/dev/sdb1 bs=5M count=20001  status=progress

Unclear behaviour of dd in case of fractional blocks:
dd error: "10000+0 records out" may mean the last "half" block is not written at all (5MB less than size of /dev/sdb1)
dd error: "104862842880 bytes (105 GB, 98 GiB) copied" which is the size of /dev/sdb1.

On my system, I would try re-write only the last 5MB of the partition:
This would be fast compared to rewriting the whole 100GB. But I'm not 100% sure about the offset!

dd if=/media/erdos/easystore/Backup/HP.qcow2 of=/dev/sdb1 bs=5M seek=20000 skip=20000 count=1

PS: Warning
All numbers may be wrong.
Don't do anything of the above you don't understand.
Mistakes incorporating dd can be very very harmful.

Last edited by delgado (2023-04-16 09:23:02)

Offline

#18 2023-04-12 01:00:02

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

thanks for the reply! 

The size of backup image file HP.qcow2:
97.7 GiB (104,864,062,464 bytes)

and to answer the earlier question of hard drive disk /partition info

erdos@htpc-devuan:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0  55.9G  0 disk 
├─sda1   8:1    0  18.6G  0 part /
├─sda2   8:2    0     1K  0 part 
├─sda5   8:5    0  35.4G  0 part /home
└─sda6   8:6    0   1.9G  0 part [SWAP]
sdb      8:16   0 465.8G  0 disk 
├─sdb1   8:17   0  97.7G  0 part 
├─sdb2   8:18   0    50G  0 part 
├─sdb3   8:19   0     1K  0 part 
├─sdb4   8:20   0  11.3G  0 part 
├─sdb5   8:21   0 306.7G  0 part 
├─sdb6   8:22   0    48G  0 part 
└─sdb7   8:23   0     2G  0 part 
sdg      8:96   0  12.7T  0 disk 
└─sdg1   8:97   0  12.7T  0 part /media/erdos/easystore
sr0     11:0    1   3.1G  0 rom  
You have new mail in /var/mail/erdos

Offline

#19 2023-04-15 13:46:58

delgado
Member
Registered: 2022-07-14
Posts: 168  

Re: how to easily copy a windows partition?

Thanks for posting the file size.

Testing:
Just dd'ed a small 100M partition using bs=13M to have a "fractional block count". Sizes of image-file and device are equal. Also tried dd with "bs=15M" and "bs=512", and pure cat. All image files are identical. On daedalus and on chimaera. No errors at all during creation and restore.

The main question is now:
Why is the image-file (104864062464 bytes) bigger than the partiton (104862842880 bytes)? How is this possible?

The partititon must have been shrinked after creating the backup image.
I don't see any other possibility.

EDIT:
fdisk -lbefore the reinstalltion of windows would be informative.
Older (windows-)partition schema start at sector 63 (not sector 2048) and there is a gap of 398 sectors (or 0.2 MB) between sda1 and sda2. This is 1.2 MB potential addional space for sda1. The image file is 1.1 MB bigger than sda1.

Last edited by delgado (2023-04-16 09:06:01)

Offline

#20 2023-04-16 09:05:34

delgado
Member
Registered: 2022-07-14
Posts: 168  

Re: how to easily copy a windows partition?

Finally a suggestion:

The image file is working (mountable) and the target device is a bit smaller the image itself.
The solution is simple and straight forward: Resize the image to fit the device.

Get some information:

ntfsresize -i HP.qcow2

ntfsresize works directly on the device or image file, a copy is recommended. The last command expands the filesystem to partiton size.

cp HP.qcow2 HP.shrinkme.img
ntfsresize -s 97G  HP.shrinkme.img
sudo dd if=HP.shrinkme.img of=/dev/sda1 bs=10M
sudo ntfsresize -x /dev/sda1

And it should be done.

Alternatively:
Grow /dev/sda1 to fit HP.qcow2.

Offline

#21 2023-04-22 15:40:27

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

Thanks!

to answer the size of image file doesn't match the size of partition: I attempted to install a fresh copy of win7 onto the same partition using win7 installation DVD, during the process, I deleted and recreated the windows partition at same location, not sure whether this leads to the partition change.

edit:  attached screenshots when I installed fresh win7 onto the HDD,  one showing the result of chkdsk on original partition when backup with 'dd' was done, the other shows the partition info during installation. 
https://flic.kr/p/2ov6AMk
https://flic.kr/p/2ov7Hgg

here's the result of running commands as described,  it doesn't seem the image was resized (i.e. as show wih 'ls -l') even thought it reports success, the restoring of the image file still results error.

erdos@htpc-devuan:/media/erdos/easystore/Backup$ ls -l
total 204812644
drwxrwxrwx 1 erdos erdos            0 Apr  1 23:17 Config.Msi
-rwxrwxrwx 1 erdos erdos 104864062464 Apr  2 00:48 HP.qcow2
-rwxrwxrwx 1 erdos erdos 104864062464 Apr 18 21:07 HP.shrinkme.img
drwxrwxrwx 1 erdos erdos        20480 Apr  1 23:24 Windows
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo ntfsresize -s 97G  HP.shrinkme.img
[sudo] password for erdos: 
ntfsresize v2017.3.23AR.3 (libntfs-3g)
Device name        : HP.shrinkme.img
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 104864059904 bytes (104865 MB)
Current device size: 104864062464 bytes (104865 MB)
New volume size    : 96999997952 bytes (97000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 71757 MB (68.4%)
Collecting resizing constraints ...
Needed relocations : 838839 (3436 MB)
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device 'HP.shrinkme.img'.
You can go on to shrink the device for example with Linux fdisk.
IMPORTANT: When recreating the partition, make sure that you
  1)  create it at the same disk sector (use sector as the unit!)
  2)  create it with the same partition type (usually 7, HPFS/NTFS)
  3)  do not make it smaller than the new NTFS filesystem size
  4)  set the bootable flag for the partition if it existed before
Otherwise you won't be able to access NTFS or can't boot from the disk!
If you make a mistake and don't have a partition table backup then you
can recover the partition table by TestDisk or Parted's rescue mode.
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo fdisk -l
Disk /dev/sdb: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WD5000AAKS-6
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: 0x1549f232

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sdb1  *         2048 204812287 204810240  97.7G  7 HPFS/NTFS/exFAT
/dev/sdb2       204812685 309670262 104857578    50G a5 FreeBSD
/dev/sdb3       309861721 953151487 643289767 306.7G  f W95 Ext'd (LBA)
/dev/sdb4       953152515 976768064  23615550  11.3G  7 HPFS/NTFS/exFAT
/dev/sdb5       309861784 953151487 643289704 306.7G  7 HPFS/NTFS/exFAT

Partition table entries are not in disk order.

Disk /dev/sda: 55.9 GiB, 60022480896 bytes, 117231408 sectors
Disk model: Corsair Force LS
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: 0x287905c2

Device     Boot     Start       End  Sectors  Size Id Type
/dev/sda1  *         2048  39063551 39061504 18.6G 83 Linux
/dev/sda2        39065598 117229567 78163970 37.3G  5 Extended
/dev/sda5        39065600 113283071 74217472 35.4G 83 Linux
/dev/sda6       113285120 117229567  3944448  1.9G 82 Linux swap / Solaris

Disk /dev/sdg: 12.73 TiB, 14000519643136 bytes, 27344764928 sectors
Disk model: easystore 264D  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: B0F4FD99-AACA-4B97-BBF2-A3E7661D0DF4

Device     Start         End     Sectors  Size Type
/dev/sdg1   2048 27344762879 27344760832 12.7T Microsoft basic data
erdos@htpc-devuan:/media/erdos/easystore/Backup$ ls -l
total 204812644
drwxrwxrwx 1 erdos erdos            0 Apr  1 23:17 Config.Msi
-rwxrwxrwx 1 erdos erdos 104864062464 Apr  2 00:48 HP.qcow2
-rwxrwxrwx 1 erdos erdos 104864062464 Apr 22 07:53 HP.shrinkme.img
drwxrwxrwx 1 erdos erdos        20480 Apr  1 23:24 Windows
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo dd if=HP.shrinkme.img of=/dev/sdb1 bs=10M
dd: error writing '/dev/sdb1': No space left on device
10000+1 records in
10000+0 records out
104862842880 bytes (105 GB, 98 GiB) copied, 2967.54 s, 35.3 MB/s
You have new mail in /var/mail/erdos
erdos@htpc-devuan:/media/erdos/easystore/Backup$ 

Last edited by erdos (2023-04-22 20:50:19)

Offline

#22 2023-04-23 10:21:32

delgado
Member
Registered: 2022-07-14
Posts: 168  

Re: how to easily copy a windows partition?

erdos wrote:

it doesn't seem the image was resized (...), the restoring of the image file still results error.

I did not know that the size of the image file would be the same, sorry.
However. The file system in the image file has become smaller. The last 7 GB are present, but unused by now - df will tell.

$ sudo mount -o loop HP.shrinkme.img /mnt
$ df

The error at restore using dd should not matter here. If you really want to be sure and write it again:

$ sudo ntfsclone -f -o /dev/sdb1 HP.shrinkme.img

The file system should be in a mountable condition. Probably it isn't ... .

Did you try to mount /dev/sdb1 ?
If you want back the shrinked 7GB HDD space, you still need to:

$ sudo ntfsresize -x /dev/sdb1
erdos wrote:

I deleted and recreated the windows partition at same location, not sure whether this leads to the partition change.

HDD situation:
There is the "master boot record" (mbr) and "partition start sector 2048" from the new installation, and the file system from the old installation (different mbr and "partition start sector 63") to fit the image size to the HDD space. I'm not aware of all implicit issues.
The disk itself will likely not boot. grub form the other disk may or may not be able to help ($ sudo update-grub).

Does the first version of the win7-install-cd the start-at-sector-63 partitioning? Think so, but not 100% sure. Probably, if you have such a install-cd, it may recreate the partition as before.
I'm not used to read chkdsk output.

Or just use the new installation and copy back all the files form the mounted image.

Offline

#23 2023-04-23 15:55:15

erdos
Member
Registered: 2018-06-04
Posts: 88  

Re: how to easily copy a windows partition?

I was able to mount both shrinked image file and /dev/sdb1 successfully,  resize of the shrinked image is not successfully,  after updating grub menu, I tried to boot windows, but only got a blank screen with blinking cursor at top left corner.  Rebooted with win7 DVD disc, it doesn't detect win7 installation on the HDD. 

Then I remembered the sata controller setting, I entered Bios and changed the setting for sata to 'IDE' from 'AHCI'  and used windows 7 DVD disk to boot again, this time bootable disc sees windows 7 installation on hdd, and reported error and prompted for repair, accepted the repair and rebooted, still couldn't past the blinking cursor screen. 

thanks for the advice and help!  Next I will probably use DVD bootable disc to see if i could repair the restored win and reboot it.

erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo mount -o loop HP.shrinkme.img /mnt
[sudo] password for erdos: 
erdos@htpc-devuan:/media/erdos/easystore/Backup$ ls -l
total 204812644
drwxrwxrwx 1 erdos erdos            0 Apr  1 23:17 Config.Msi
-rwxrwxrwx 1 erdos erdos 104864062464 Apr  2 00:48 HP.qcow2
-rwxrwxrwx 1 erdos erdos 104864062464 Apr 22 07:53 HP.shrinkme.img
drwxrwxrwx 1 erdos erdos        20480 Apr  1 23:24 Windows
erdos@htpc-devuan:/media/erdos/easystore/Backup$ df -h
df: /run/user/1000/doc: Operation not permitted
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           394M  2.6M  391M   1% /run
/dev/sda1        19G  6.4G   11G  37% /
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           1.2G     0  1.2G   0% /dev/shm
/dev/sda5        35G   28G  5.8G  83% /home
tmpfs           394M  792K  393M   1% /run/user/1000
/dev/sdg1        13T  207G   13T   2% /media/erdos/easystore
/dev/loop0       91G   67G   24G  74% /mnt
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo umount /mnt
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo mount -t ntfs /dev/sdb1 /mnt
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo umount /mnt
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo ntfsresize -x /dev/sdb1
ntfsresize v2017.3.23AR.3 (libntfs-3g)
ERROR: Could not get the old volume parameters from the backup bootsector
erdos@htpc-devuan:/media/erdos/easystore/Backup$ sudo update-grub
Generating grub configuration file ...
Found theme: /usr/share/desktop-base/grub-themes/desktop-grub-theme/theme.txt
Found linux image: /boot/vmlinuz-5.10.0-9-amd64
Found initrd image: /boot/initrd.img-5.10.0-9-amd64
Found linux image: /boot/vmlinuz-4.19.0-9-amd64
Found initrd image: /boot/initrd.img-4.19.0-9-amd64
Found Windows 7 on /dev/sdb1
Found FreeBSD 12.2-RELEASE-p12 on /dev/sdb2
Found Windows Vista on /dev/sdb4
Found FreeBSD 12.2-RELEASE-p12 on /dev/sdb6
done

Offline

Board footer