12

Case scenario:

$ sudo fdisk -l
Disk /dev/sda: 223,6 GiB, 240057409536 bytes, 468862128 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: 0x13a30a5a

Device  Boot     Start     Final  Sectors Size Id Type
/dev/sda1  *           2048   1333247   1331200   650M 27 WinRE NTFS hidden
/dev/sda2           1333248 264058879 262725632 125,3G  7 HPFS/NTFS/exFAT
/dev/sda3         264060926 468860927 204800002  97,7G  5 Extended
/dev/sda5         264060928 434049023 169988096  81,1G  7 HPFS/NTFS/exFAT
/dev/sda6         434051072 464771775  30720704  14,7G 83 Linux
/dev/sda7         464773120 468860927   4087808     2G 82 Linux swap / Solaris

Windows 10 is installed on /dev/sda2 and I assume that /dev/sda1 is a hidden partition from the same Windows system.

How can I backup my Windows 10 installation from Linux in order to restore it later?

Further data upon request:

  • By "Installation" I mean the "full partition" (or partitions) required to return Windows to the moment the cloning was made.
  • Being able to restore to the same system (computer, hardware) and even hard drive would enough. I.e: I installed Windows 10, made backup, and a few months ago I want to restore the backup I made, so there is no need to perform the full installation of Windows 10 (drivers, printers, programs...etc) again.

Tested until now (all tests performed on the same computer with the same partition layout):

  • PartImage (cloning sda1 and sda2): not working. The restored operating system will not boot.
  • FSArchiver (cloning sda1 and sda2): not working. The restored operating system will not boot.
13
  • 5
    What on Earth is the downvote for???
    – ajeh
    May 15, 2018 at 21:13
  • If by 'installation' you meant the entire partition, then dd is the most reliable way. If however you meant files on the partition, then tar can do that just fine. This is worth clarifying in your question. How are you testing the restore - onto the same drive, or a different drive with a different partition layout?
    – ajeh
    May 15, 2018 at 21:14
  • 1
    I used dd with up to Windows 8.1 images, as well as QNX, Apple Mac, Solaris, FreeBSD and OS/2. I do not have a Windows 10 distro to try, as I consider this a giant malware to stay away from.
    – ajeh
    May 15, 2018 at 22:08
  • 1
    I wouldn't use dd since that will backup empty space too. Instead look at something like clonezilla
    – ivanivan
    May 15, 2018 at 23:42
  • 1
    Not an answer per se, but worth reading for anyone reading this page or considering doing this: *****BOTH*** PartImage & FSArchiver** (I've used them both & read about both extensively) are NOT certified for use for NTFS, in fact it's considered "Experimental" ; They do work fine for FAT 32, but otherwise should be considered "OFF-LIMITS" for any windows backups, System or otherwise. Linux & Win don't play well together---the best "common ground" is FAT 32 (I have a dual boot sys with just a partition I use frequently!) Jul 8, 2020 at 13:53

5 Answers 5

5

pv method

You could use pv (man page) utility like so:

sudo sh -c 'pv < /dev/sda > /destination'

Of course you could become root first:

sudo -i

And then just do the backup:

pv < /dev/sda > /BackupDestination

And then when needed do the restore:

pv < /BackupDestination > /dev/sda

Notes

  • This basically does the same job as dd in the other answer, but is faster and shows progress.

  • This method may be slower than rsync, but that just copies files, which is not intended.

  • It copies everything 1:1, a perfect copy might you say.

  • You need also the boot sector for it to boot later on. The simplest method is to backup the whole drive.

  • To show progress with dd (man page), you could just add to the command:

    status=progress
    

Tip

For you to be able to effectively compress the image afterwards, don't forget to zero free space.

7
  • Why cloning the other partitions? The question is just about backup/restore Windows 10. May 16, 2018 at 0:29
  • pv is not faster than dd unless you give dd a tiny bs value. May 16, 2018 at 8:35
  • 1
    @user1133275 Have you ever made some benchmark? Never mind, don't bother. cat without progress or pv with progress is preferable method of cloning for me at least. May 16, 2018 at 8:47
  • @user1133275 See unix.stackexchange.com/a/9492/20626 and unix.stackexchange.com/q/12532/20626. There is no need to use dd. Just use cat or pv instead.
    – scai
    Sep 3, 2020 at 12:57
  • Is this compatible to the .img files dd writes? Nov 27, 2020 at 22:32
5

I have just successfully finished the described scenario of backing up Windows 10 from Linux to a file and restoring them on a new drive.

With the old disk zero free space from Windows by doing

zdelete -z c:

using SDelete.

Get some live Linux USB to boot and backup MBR and partition table to a spare drive

dd if=/dev/sda of=/somewhere/mbr bs=512 count=63

copy the boot partition to a file

dd if=/dev/sda1 bs=1M status=progress | lz4 > /somewhere/sda1.lz4

copy the system partition to a file

dd if=/dev/sda2 bs=1M status=progress | lz4 > /somewhere/sda2.lz4

Place the new disk into the computer, boot the live Linux again and restore the beginning of the disk

dd of=/dev/sda if=/somewhere/file.mbr

That gets you the same primary partition layout (partitions inside extended partition are stored somewhere else and will not be restored by doing this).

Now restore the two Windows partitions

dd of=/dev/sda1 bs=1M status=progress < lz4cat /somewhere/sda1.lz4
dd of=/dev/sda2 bs=1M status=progress < lz4cat /somewhere/sda2.lz4 

The drive didn't boot at this stage (grub complaining). So boot windows rescue disk or the installation media and select "repair". In Troubleshooting start cmd prompt and run

bootrec /fixmbr

At this stage I got the original Windows system to boot on the new bigger drive. I got 50% compression rate with both gzip and lz4 (with 70% full drive) but gzip was limited by the CPU speed (27MB/s in my case) while lz4 was not (480MB/s CPU limit, 180MB/s my backup drive limit).

My first try was with ntfsclone but that didn't produce bootable Windows (it was complaining of some missing files in \Windows\System32). I am not sure why it didn't work. At the end the dd + lz4 solution created smaller image than ntfsclone by itself. Your mileage may vary based on how full the disk is modulo bugs in ntfsclone - dd seems much easier to get right :-)

2

Yes, the most simple solution is

dd if=/dev/sda of="/media/usb/$(date).img"

That is slow and takes up a lot of space so you can

  • just copy the partition[s] + boot sector you want
  • zero and compress free space
  • file instead of block based backups
  • rdiff-backup for reverse diffs (dramatic size reduction after the first)
  • rsync (for dramatic speedup over slow networks)
  • cow FS (btrfs/zfs) for faster/smaller than rsync/diff backups are only an option if you put windows in a VM, and I'm not sure how well they are suited to that scenario.

Likely you missed the boot sector, UUIDs and should read up on grub and https://en.m.wikipedia.org/wiki/Windows_Vista_startup_process

2
  • Why cloning the other partitions? The question is just about backup/restore Windows 10. May 16, 2018 at 0:29
  • 2
    @SopalajodeArrierez the whole thing is the simple method, otherwise you need to think about partition tabe type, boot sector, UUIDs, alignment, flags, utility partitions etc. May 16, 2018 at 1:15
1

Like other solutions posted until now, this one show progress (like the pv solution, not relative to total, just number of MB transferred) and does not compress (a 100GB partition would result in a 100GB file), but it backups only the partition file system (sda1), not the entire disk or partition:

dcfldd if=/dev/sda1 of=Image.dd bs=2M

The dcfldd tool is a simple dd that shows progress.
The buffer size bs=2M seems to me a good value for USB devices (a 120 GB partition copied in about 15-20 minutes).

Tested working on Windows 10 version 1803. No need (or so it seems) to backup too the entire hard disk, happily.

Of course, compressing the resulting file later would probably be a good idea.

0
1

I did a backup of a freshly installed Windows computer, following Zbyněk Winkler's answer above. I tried lzma and gzip --fast, but those became a bottleneck (my two SSDs managed a transfer speed of 2 GB/s without compression). Actual command line:

$ sudo dd if=/dev/nvme0n1 bs=1M status=progress | pzstd -o /tmp/windows-disk.zst

The process took about eight minutes, and the 1 TB SSD was compressed to an 8 GB file. Note, this was a fresh install, so just Windows, no user data or applications.

Restore with :

$ pzstd -d /tmp/windows-disk.zst -c | sudo dd of=/dev/nvme0n1 bs=1M status=progress

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .