1

I bought myself a new tiny laptop - Asus X201E. It came with windows 8 preinstalled in UEFI mode, I have no DVDs with it - any DVD with drivers nor Windows 8.

Since Im not a big fan of Windows, I would like to install Ubuntu near Windows 8 - but this is a long story for another discussion. My question here is how can I reinstall Windows 8 AFTER installing Ubuntu near Windows 8? Lets say I would like to reinstall everything (Win8 and Ubuntu) later - how can I do this? Can I download Win8 from Microsoft, will it be legal (I DO care if its legal). Summing up:

  1. Now I have only Windows 8 pre-installed in UEFI mode (have no dvds, my laptop doesnt have CD-ROM or DVD drive)
  2. I disabled secure boot and fast boot
  3. I would like to install Ubuntu tomorrow near Windows 8
  4. How can I reinstall Windows8 and Ubuntu after some time later (lets say 5-6 months from today)? Cheers :)
3
  • Does the bios screen have a "press button to go to recovery..." type text? If it does, that's how Windows should be reinstalled. Also does W8 ask you to create your own recovery disks? They were possible to make into iso images. However I'm not sure if you can recover them using a USB stick...
    – varesa
    Sep 19, 2013 at 19:30
  • @varesa: No, I dont have such screen "press button to go to recovery", when I turn on my laptop, I see only ASUS logo (just for 1 second) and then Windows 8 is ready to work. W8 didnt ask to create a recovery disk, I also dont have any program like this preinstalled from ASUS. Any ideas?
    – yak
    Sep 20, 2013 at 10:36
  • The only thing I can think of is to use some (Linux) live operating system from a USB drive to make a backup of the hard drive
    – varesa
    Sep 20, 2013 at 11:40

2 Answers 2

3

At the moment of writing none of the win8 built-in recovery option or asus backtracker are able to reset the system to the factory shape when new disk is installed. They create USB recovery backup disk but restoring from it is impossible.

The goal of this guide it to show how to create win8 factory backup that can be restored to new disk and boot to the factory state. Doing all this completely from linux.

In this example original disk has 6 partitions as follows:

  • EFI
  • Recovery
  • MSR
  • OS
  • DATA
  • Restore

Needed:

  • linux booted from some device
  • backup disk (in my case 12G capacity)
  • original hdd with win8 preinstalled
  • new hdd with capacity less or greater than original disk, but still sufficient to fit all needed stuff

Assume:

  • original/new disk is /dev/sda
  • backup disk is /tmp/backup
  • some mount point e.g. /tmp/mnt

The procedure in short:

  • backup the beginning of a HDD
  • backup the content of the Restore partition
  • restore beginning of HDD
  • recreate OS/DATA/Restore partitions to fit on new disk
  • update win8 to use new disk shape
  • reboot to factory installation

BACKUP

1) Get partitions information from original disk (only last 3 partitions that will be recreated):

[root]# gdisk /dev/sda 
GPT fdisk (gdisk) version 0.8.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sda: 1465149168 sectors, 698.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 11111111-1111-1111-1111-111111111111
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1465149134
Partitions will be aligned on 2048-sector boundaries
Total free space is 3757 sectors (1.8 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          616447   300.0 MiB   EF00  EFI system partition
   2          616448         1845247   600.0 MiB   2700  Basic data partition
   3         1845248         2107391   128.0 MiB   0C01  Microsoft reserved part
   4         2107392       588165119   279.5 GiB   0700  Basic data partition
   5       588165120      1423204351   398.2 GiB   0700  Basic data partition
   6      1423204352      1465147391   20.0 GiB    2700  Basic data partition

Command (? for help): i
Partition number (1-6): 4
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: 44444444-4444-4444-4444-444444444444
First sector: 2107392 (at 1.0 GiB)
Last sector: 588165119 (at 280.5 GiB)
Partition size: 586057728 sectors (279.5 GiB)
Attribute flags: 0000000000000000
Partition name: 'Basic data partition'

Command (? for help): i
Partition number (1-6): 5
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: 55555555-5555-5555-5555-555555555555
First sector: 588165120 (at 280.5 GiB)
Last sector: 1423204351 (at 678.6 GiB)
Partition size: 835039232 sectors (398.2 GiB)
Attribute flags: 0000000000000000
Partition name: 'Basic data partition'

Command (? for help): i
Partition number (1-6): 6
Partition GUID code: DE94BBA4-06D1-4D40-A16A-BFD50179D6AC (Windows RE)
Partition unique GUID: 66666666-6666-6666-6666-666666666666
First sector: 1423204352 (at 678.6 GiB)
Last sector: 1465147391 (at 698.6 GiB)
Partition size: 41943040 sectors (20.0 GiB)
Attribute flags: 8000000000000001
Partition name: 'Basic data partition'

Command (? for help): q

2) The first 3 partitions (and HDD first sectors) must be intact, so do raw copy of them:

a) Note the size to copy - the number of sectors up to the OS partition (#4) , so simply the OS partition 'Start (sector)' =2107392, where sector size is commonly =512.

b) Do a copy to the backup device, compressing it:

dd if=/dev/sda conv=sync,noerror bs=512 count=2107392 | gzip -c > /tmp/backup/win8-factory-head.gz

3) Ignore/discard OS and DATA partitions - they will be created empty

4) Backup the last 'Restore' partition with factory install.wim in it:

[root]# mount /dev/sda6 /tmp/mnt

[root]# df -h /tmp/mnt
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6        20G   12G  8.3G  59% /tmp/mnt

Note the original partition is 20G, but the space used is far below that, thus the new partition created might be smaller to gain these few GB.

Do the content file/dir backup, not the raw copy:

[root]# cd /tmp/mnt

[root]# tar -pczf /tmp/backup/win8-factory-restore.tgz .

[root]# cd /

[root]# umount /tmp/mnt

5) Keep this guide and following two files as a complete backup:

  • win8-factory-head.gz
  • win8-factory-restore.tgz

RESTORE

1) Replace original disk with new one. Remember not plugging in original disk together with newly prepared as they will use the same UIDs.

2) Restore HDD beginning:

gunzip -c win8-factory-head.gz | dd of=/dev/sda conv=sync,noerror bs=512

3) The GPT written to new disk must be fixed (unless this is identical disk as original one, then omit steps b,c,e,f,g).

[root]# gdisk /dev/sda

Now continue from gdisk command line.

a) Some warning is expected if the new disk is smaller than the original, e.g.:

Warning! Disk size is smaller than the main header indicates! Loading
secondary header from the last sector of the disk! You should use 'v' to
verify disk integrity, and perhaps options on the experts' menu to repair
the disk.
Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

In case of the following select option '1'.

Found invalid MBR and corrupt GPT. What do you want to do? (Using the
GPT MAY permit recovery of GPT data.)
 1 - Use current GPT
 2 - Create blank GPT

b) If not done before, when making a backup, print the last 3 partitions info:

Command (? for help): i
Partition number (1-6): 4

Command (? for help): i
Partition number (1-6): 5

Command (? for help): i
Partition number (1-6): 6

c) Delete last 3 partitions:

Command (? for help): d
Partition number (1-6): 6

Command (? for help): d
Partition number (1-5): 5

Command (? for help): d
Partition number (1-4): 4

Command (? for help): p
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 11111111-1111-1111-1111-111111111111
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1465149134
Partitions will be aligned on 2048-sector boundaries
Total free space is 1463043757 sectors (697.6 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          616447   300.0 MiB   EF00  EFI system partition
   2          616448         1845247   600.0 MiB   2700  Basic data partition
   3         1845248         2107391   128.0 MiB   0C01  Microsoft reserved part

d) Notice the 'Total free space is 1463043757 sectors (697.6 GiB)' is not correct according to the 'Disk /dev/sda: 976773168 sectors, 465.8 GiB'. Fix this, so the suggested size for newly created partitions will be valid:

Command (? for help): x

Expert command (? for help): e
Relocating backup data structures to the end of the disk

Expert command (? for help): m

Command (? for help): p
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 11111111-1111-1111-1111-111111111111
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 974667757 sectors (464.8 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          616447   300.0 MiB   EF00  EFI system partition
   2          616448         1845247   600.0 MiB   2700  Basic data partition
   3         1845248         2107391   128.0 MiB   0C01  Microsoft reserved part

e) Recreate deleted partitions (for each give resonable size, and valid 'Hex code or GUID' that is the same as in the related original partition):

Command (? for help): n
Partition number (4-128, default 4): 
First sector (34-976773134, default = 2107392) or {+-}size{KMGTP}: 
Last sector (2107392-976773134, default = 976773134) or {+-}size{KMGTP}: +200G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'

Command (? for help): n
Partition number (5-128, default 5): 5
First sector (34-976773134, default = 421537792) or {+-}size{KMGTP}: 
Last sector (421537792-976773134, default = 976773134) or {+-}size{KMGTP}: +250G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'

Command (? for help): n
Partition number (6-128, default 6): 
First sector (34-976773134, default = 945825792) or {+-}size{KMGTP}: 
Last sector (945825792-976773134, default = 976773134) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 2700
Changed type of partition to 'Windows RE'

Command (? for help): p
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 11111111-1111-1111-1111-111111111111
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          616447   300.0 MiB   EF00  EFI system partition
   2          616448         1845247   600.0 MiB   2700  Basic data partition
   3         1845248         2107391   128.0 MiB   0C01  Microsoft reserved part
   4         2107392       421537791   200.0 GiB   0700  Microsoft basic data
   5       421537792       945825791   250.0 GiB   0700  Microsoft basic data
   6       945825792       976773134   14.8 GiB    2700  Windows RE

f) Since newly created partitions have default parameters, update them so they exactly mimic values from original partitions.

Fix names (probably not necessary):

Command (? for help): c
Partition number (1-6): 4
Enter name: Basic data partition

Command (? for help): c
Partition number (1-6): 5
Enter name: Basic data partition

Command (? for help): c
Partition number (1-6): 6
Enter name: Basic data partition

Fix unique GUID:

Command (? for help): x

Expert command (? for help): c
Partition number (1-6): 4
Enter the partition's new unique GUID ('R' to randomize): 44444444-4444-4444-4444-444444444444
New GUID is 44444444-4444-4444-4444-444444444444

Expert command (? for help): c
Partition number (1-6): 4
Enter the partition's new unique GUID ('R' to randomize): 55555555-5555-5555-5555-555555555555
New GUID is 55555555-5555-5555-5555-555555555555

Expert command (? for help): c
Partition number (1-6): 4
Enter the partition's new unique GUID ('R' to randomize): 66666666-6666-6666-6666-666666666666
New GUID is 66666666-6666-6666-6666-666666666666

Fix attributes (actually it is needed only for the 'Restore' partition):

Expert command (? for help): a
Partition number (1-6): 6
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automount

Attribute value is 0000000000000000. Set fields are:
  No fields set

Toggle which attribute field (0-63, 64 or <Enter> to exit): 0
Have enabled the 'system partition' attribute.
Attribute value is 0000000000000001. Set fields are:
0 (system partition)

Toggle which attribute field (0-63, 64 or <Enter> to exit): 63
Have enabled the 'do not automount' attribute.
Attribute value is 8000000000000001. Set fields are:
0 (system partition)
63 (do not automount)

Toggle which attribute field (0-63, 64 or <Enter> to exit): 

g) From the NEXT command note the 'Start (sector) =945825792' for the last #6 partition.

Expert command (? for help): p
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 11111111-1111-1111-1111-111111111111
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          616447   300.0 MiB   EF00  EFI system partition
   2          616448         1845247   600.0 MiB   2700  Basic data partition
   3         1845248         2107391   128.0 MiB   0C01  Microsoft reserved part
   4         2107392       421537791   200.0 GiB   0700  Basic data partition
   5       421537792       945825791   250.0 GiB   0700  Basic data partition
   6       945825792       976773134   14.8 GiB    2700  Basic data partition

h) Store changes on disk

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

4) Make the systems to reload new disk:

[root]# partprobe /dev/sda

5) Format newly created partitions

[root]# mkfs.ntfs -f -L OS /dev/sda4
[root]# mkfs.ntfs -f -L DATA /dev/sda5
[root]# mkfs.ntfs -f -L Restore /dev/sda6

6) Restore the 'Restore' partition content.

[root]# mount /dev/sda6 /tmp/mnt
[root]# cd /tmp/mnt
[root]# tar -pxzf /tmp/backup/win8-factory-restore.tgz .
[root]# cd /
[root]# umount /tmp/mnt

7) Update recovery data so system will be restored to factory settings on reboot (omit this step if original disk is used without repartitioning)

[root]# mount /dev/sda2 /tmp/mnt
[root]# vi /tmp/mnt/Recovery/WindowsRE/ReAgent.xml

a) Compute the byte offset basing on sector offset (from step 3g above) for the last partition, 945825792*512=484262805504

b) Update following line in ReAgent.xml file with new offset value:

<OsInstallLocation path="\RecoveryImage" id="0" offset="484262805504" guid="{11111111-1111-1111-1111-111111111111}" index="2"/>

c) remove mount

[root]# umount /tmp/mnt

8) Reboot, use F9 to enter the recovery environment, select the 'Reset PC' option. This will restore the OS as with the first boot.

1

Most Windows recovery systems included on modern computers restore the computer to the factory state. This means that if you use them, you'll lose your Linux installation. Thus, you really have two options:

  • Make a backup of Windows in a near-pristine state and use that for recovery, if/when it becomes necessary. You should do this either using Windows tools that enable restoring to a smaller partition or do it after you shrink the Windows partition, though. (Note that some tools do not permit restoring to a smaller partition, so be sure to check on this detail!)
  • Obtain a Windows 8 retail DVD and use it in conjunction with your current installation's serial number. This question and answer cover obtaining legal Windows 8 DVDs. I'm not sure about the serial number, but I know it can be found in some way.

Personally, I'd want to be prepared with both options.

You must log in to answer this question.

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