How to backup/clone Windows creating a recovery image using Ubuntu

28,237

Solution 1

Here's the VeryEasyWay™ to do this:

  • download the CloneZilla Live CD,
  • boot it
  • follow the device-image manual to do the imaging. A disk-to-image will compress the disk image before writing it so the entire space taken up by the image itself will be far less then the allocated space on the disk itself!
  • store the image of the disk you created in your cloud together with the image of the CloneZilla Live CD! (Just in case a future version of CloneZilla would not be able to restore it)
  • Only to be super-safe: keep the CloneZilla CD and the HDD you backed this up to in your bank safe just in case that your cloud software doesn't exist any more in the future and your house burns down afterwards... ;-)

Solution 2

I Would do this:

Change to ROOT mode from a Live CD/USB Preferrably, if not it will still work from a dual-booted Linux install. Open a terminal and type:

sudo -i

Then, find out which partition is your Windows via this command:

fdisk -l

Mine shows this:

/dev/sda1  *         2048    206847    204800   100M  7 HPFS/NTFS/exFAT
/dev/sda2          206848 240818175 240611328 114.8G  7 HPFS/NTFS/exFAT
/dev/sda3       240820224 312498175  71677952  34.2G  5 Extended
/dev/sda5       240822272 312498175  71675904  34.2G  7 HPFS/NTFS/exFAT

So in my case, /dev/sda1 is the recovery bootloader (windows). They vary in size, mine was 100M but I have seen others for example if the image was installed with MDT then they are bigger.

Next Disk Dump Backup the /dev/sda1 partition to a file, and store it anywhere you want. In this case I saved it in my root folder's home directory:

dd if=/dev/sda1 bs=16m of=/home/wubilover/BackupOfSda1-WinRecovPartition.dd

Remember that DD takes a long time to run, so wait until it finishes :)

That's it. To restore it, swap the if= and of= of the above command. :) Enjoy.


To Perform a FULL Backup of the entire Drive you can buy a USB Drive that is larger, and then save it to a .dd file in the bigger drive. This way if you break something, you can boot into the Live CD/USB and attach your external drive and restore.

Full Backup to external drive:

  • Boot into Live CD/USB wait for ubuntu to load and then open a terminal

  • Plug in your external drive which is LARGER then the internal drive, ensure that it is NTFS or EXT3 or higher so that it can hold the large file. This is confirmed via running the command:

    gksudo gparted
    

    Then go ahead and partition it to Ext3 or Ntfs (doesn’t matter, but if you are using windows i recommend ntfs)

  • Confirm that it is mounted via

    df -kh
    
  • BACKUP THE HARD DRIVE to the EXTERNAL HARD DRIVE VIA (Notice the command is different from above):

    dd if=/dev/sda bs=16m of=/media/MyUSBStick/BackupOfSda-TheEntireHD.dd
    
  • And... if something goes wrong you can RESTORE THE EXTERNAL HARD DRIVE's .dd file to the INTERNAL HARD DRIVE VIA (Notice the command is different from above):

    dd bs=16m if=/media/MyUSBStick/BackupOfSda-TheEntireHD.dd of=/dev/sda 
    

Solution 3

This method which images the entire drive works flawlessly to backup any operating system, including any version of Windows. I've used it repeatedly over the years. The only possible downside is that you'll need to restore (and store) the image to a drive of equal (or greater) size due to not using compression. The upside is it takes very little of your time.

Share:
28,237

Related videos on Youtube

tomrozb
Author by

tomrozb

Android, Flutter, GCP, Blockchain

Updated on September 18, 2022

Comments

  • tomrozb
    tomrozb over 1 year

    I bought a new laptop with Windows installed on it. I'm going to wipe all partitions and install Ubuntu.

    One day I'll probably sell that laptop, so it'll be nice to recover it to the manufacturer state. I want to backup recovery partition, save it to some file and keep that in cloud. One day I'll restore it and reinstall Windows from the recovery partition.

    What tools should I use to make it painless? I tried some Windows tools with my current laptop when I first bought it, but after 3 years I'm unable to recover the partition. I created the backup on Windows, so now I don't want to make the same mistake twice.

    • mchid
      mchid almost 8 years
      I would like to see a good answer to this but if you can't get a good answer, you could always buy a new hard drive and swap it out.
    • tomrozb
      tomrozb almost 8 years
      @mchid this is a laptop with no access to hard drive, you have to disassemble it to swap the drive - and you're also going to void your warranty.
    • mchid
      mchid almost 8 years
      I guess there is no access plate like there usually is on the bottom of the laptop? You need to disassemble the laptop for routine maintenance such as fan cleaning anyhow, double check that warranty?
    • tomrozb
      tomrozb almost 8 years
      @mchid yes, no access to RAM, fans, drive...
  • tomrozb
    tomrozb almost 8 years
    I assume that I've to keep information about current partition sizes, types etc. Before restoring backup I'll have to restore the partitions, then use dd command to write files to these partitions? You sure it's not going to mess anything with the built-in recovery mechanism?
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 8 years
    I would strongly suggest to backup starting from the first sector (partition table), including the recovery partition and possibly a bit more. :) Actually, it could be easier to backup using Clonezilla.
  • tomrozb
    tomrozb almost 8 years
    @AndreaLazzarotto could you please post full answer, with detailed description what should be backed up, to recover it easily? I also think simply backing up the recovery partition is not enough to restore Windows from such recovery partition in the future. This is the mistake I did using Windows tool, which probably created only a copy of recovery partition and nothing else, that's why I'm unable to install Windows from this partition right now.
  • redbow_kimee
    redbow_kimee almost 8 years
    I also like to pipe dd through gzip for compression. on a brand new laptop there will be a lot of empty blocks to compress for cheap. it should look something like dd if=${drive} bs=512k conv=sync,noerror | gzip | dd of=${file}
  • WubiUbuntu980 Unity7 Refugee
    WubiUbuntu980 Unity7 Refugee almost 8 years
    Interesting, does GZIP uncompress though? If your image is 2000GB as Tar.bz, but if you Gunzip and then pipe it back to DD, it will fill up your memory and the dd restore will fail. Also what is the conv=sync,noerror mean (and is that applicable to ssd?)
  • David Foerster
    David Foerster almost 8 years
    @KissMeKimmi: On most drives it would be much faster yo use an I/O block size in the ranges of multiple megabytes. I typically use 8 or 16 MiB, since a slightly too large buffer doesn't decrease throughput significantly as long as you have enough memory (so if you're not on an embedded system).
  • David Foerster
    David Foerster almost 8 years
    @WubiUbuntu1980: Decompression would work like this: gunzip < backup.dd.gz | dd of=/dev/sdX bs=8m. The conv=sync,noerror are completely unnecessary and even pointless in my opinion unless you have a very specific use case for them (which you don't).
  • redbow_kimee
    redbow_kimee almost 8 years
    @DavidFoerster good point on the buffer size. larger buffers are better, but I often do this on RasPi's so smaller is my brain's default... the conv=sync,noerror means that it will ignore read errors and continue, which is often necessary if usb-ports are old and wearing out.
  • David Foerster
    David Foerster almost 8 years
    @KissMeKimmi: I know what the options do, but I really think that you should use a connection interface that doesn't destroy your data in transit instead. noerror masks the errors at best and fixes nothing. In general you want to know about possible errors unless you already know about them, so you shouldn't suggest them to someone without a specific reason (which – again – doesn't exist here). And sync just forces flushing in-kernel buffers for the device after every I/O block – another option that you don't need except under special circumstances where you need synchronized I/O.
  • redbow_kimee
    redbow_kimee almost 8 years
    @DavidFoerster I think you're right about situation dependency. I started doing conv=sync,noerror and it's just something I've never questioned. Now that you question it, I don't see the need for sync but occasionally do see the use for noerror
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 8 years
    @tomrozb, sorry, I didn't have much free time to write before. I see that Fabby wrote a very good answer involving Clonezilla already. :)
  • tomrozb
    tomrozb almost 8 years
    @AndreaLazzarotto the last question, applies to both methods: should I copy entire disk or copy all but the let's call "C:/" partition is enough (assuming there's only one partition for system and data)? I just don't want to keep a lot of data in the cloud, recovery + 3 other partitions should be 12GB, with Windows installed (full disc copy) It'd be almost 50GB.
  • tomrozb
    tomrozb almost 8 years
    do I understand correctly that I don't have to backup all partitions? I've 5 partitions, the biggest one has Windows installed on it. I'm going to backup 4 of them, creating a file for each on the 5th partition. Is that enough to restore the partitions and recover Windows later if I wipe the disc by removing current partitions, then formatting them to ext and installing Linux?
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 8 years
    Copying the disk including the boot sector and the whole recovery partition should be enough. But don't put it in the cloud (well, not only there). I suggest you invest some euros/dollars into a 16 GB USB drive and keep it in a safe, dry place.
  • Fabby
    Fabby over 7 years
    @tomrozb nope, you backup your entire drive into 1 fille....
  • Fabby
    Fabby over 7 years
    ... onto an external drive... ;)
  • tomrozb
    tomrozb over 7 years
    @AndreaLazzarotto I still don't understand how to copy the boot sector with Clonezilla. It allows me to select sdaX partitions (X is a number), is the boot sector a partition? How to distinguish it?
  • tomrozb
    tomrozb over 7 years
    Your solution is fine, but I'll end up with 512GB (I know the size is smaller than 512GB) file where 500GB is just an empty space. Isn't it possible to copy just what I want without copying the unnecessary space that I don't care of? Like the C:/ partition?
  • Fabby
    Fabby over 7 years
    Ever heard of sparse files and compression? ;) That's what this uses. Just try it out and be amazed....
  • tomrozb
    tomrozb over 7 years
    But first I need a drive that's >512GB large to copy the file and compress it to have ~1XGB file in the end. Thanks for help but I'll just copy all but C:/ partitions using Clonezilla.
  • Andrea Lazzarotto
    Andrea Lazzarotto over 7 years
    No, it isn't. Doesn't it allow you to clone the entire drive also? If it is a freshly installed drive, it will likely be almost empty so the compressed CloneZilla image will take less space than its real size.
  • Fabby
    Fabby over 7 years
    nope! It compresses before writing...
  • tomrozb
    tomrozb over 7 years
    Ok, so that's the easiest and safest way. You should update your answer with this important info. Accepted, thank you!
  • Fabby
    Fabby over 7 years
    @tomrozb: Done and Thank you! Q upvoted as well!
  • user391339
    user391339 over 6 years
    i got invalid number 16m
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    Whoaa. 500 point Thank You. You're a star :)... have another 10!
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    Um you know your link is to a Fabby answer who is already slated to be awarded the 500 point bounty for his answer above? ;)... Nonetheless +1 here and +1 on the link.
  • Elder Geek
    Elder Geek about 6 years
    @WinEunuuchs2Unix The link was a typo. Thanks for the heads up. Yes, I know Fabby is explicitly slated for the bounty.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    Elder I already upvoted your new link some time last year or the year before. It's a good answer.
  • Fabby
    Fabby about 6 years
    @WinEunuuchs2Unix Thanks!. Drop by in the AUGR (Ask Ubuntu General Room) some time...
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 6 years
    A fortnight or two ago you invited me in and my anti-war rant about Trump almost got me another 30 day chat ban :D You should check out other bounties today that are about to be lost with no answers of 2+ votes.
  • Fabby
    Fabby over 5 years
    Oh! Just noticed this one! +1 ;-)