30

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.

Fabby
  • 34,259
tomrozb
  • 511
  • 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. – mchid Jul 18 '16 at 23:47
  • @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. – tomrozb Jul 19 '16 at 00:58
  • 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? – mchid Jul 19 '16 at 01:04
  • @mchid yes, no access to RAM, fans, drive... – tomrozb Jul 19 '16 at 01:15

3 Answers3

35

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... ;-)
Fabby
  • 34,259
  • 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? – tomrozb Aug 07 '16 at 02:13
  • @tomrozb nope, you backup your entire drive into 1 fille.... – Fabby Aug 15 '16 at 23:37
  • ... onto an external drive... ;) – Fabby Aug 15 '16 at 23:49
  • 1
    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? – tomrozb Aug 16 '16 at 15:07
  • Ever heard of sparse files and compression? ;) That's what this uses. Just try it out and be amazed.... – Fabby Aug 16 '16 at 18:04
  • 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. – tomrozb Aug 17 '16 at 08:45
  • nope! It compresses before writing... – Fabby Aug 20 '16 at 22:38
  • 1
    Ok, so that's the easiest and safest way. You should update your answer with this important info. Accepted, thank you! – tomrozb Aug 21 '16 at 10:47
  • @tomrozb: Done and Thank you! Q upvoted as well! – Fabby Aug 21 '16 at 15:57
  • 2
    Whoaa. 500 point Thank You. You're a star :)... have another 10! – WinEunuuchs2Unix Apr 25 '18 at 01:46
  • @WinEunuuchs2Unix Thanks!. Drop by in the AUGR (Ask Ubuntu General Room) some time... – Fabby Apr 25 '18 at 11:18
  • 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. – WinEunuuchs2Unix Apr 25 '18 at 11:31
13

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 
    
David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • 1
    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? – tomrozb Jul 19 '16 at 01:09
  • 2
    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. – Andrea Lazzarotto Jul 19 '16 at 10:34
  • 2
    @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. – tomrozb Jul 19 '16 at 19:27
  • 3
    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} – redbow_kimee Jul 20 '16 at 04:21
  • 1
    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?) – PythonWubiUser Jul 20 '16 at 05:28
  • 2
    @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 Jul 24 '16 at 07:19
  • 2
    @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). – David Foerster Jul 24 '16 at 07:24
  • 1
    @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. – redbow_kimee Jul 25 '16 at 15:39
  • 1
    @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. – David Foerster Jul 25 '16 at 20:53
  • 1
    @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 – redbow_kimee Jul 25 '16 at 21:30
  • 1
    @tomrozb, sorry, I didn't have much free time to write before. I see that Fabby wrote a very good answer involving Clonezilla already. :) – Andrea Lazzarotto Jul 26 '16 at 21:59
  • 1
    @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 Aug 07 '16 at 02:13
  • 2
    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. – Andrea Lazzarotto Aug 07 '16 at 10:14
  • 1
    @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 Aug 16 '16 at 15:04
  • 1
    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. – Andrea Lazzarotto Aug 17 '16 at 15:43
  • 1
    i got invalid number 16m – user391339 Nov 28 '17 at 00:36
2

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.

Elder Geek
  • 36,023
  • 25
  • 98
  • 183