Tuesday, March 17, 2015

2015 March 17 | Data Recovery | Recovery Partition Restored via Ubuntu Linux

Modern laptops and notebook computers come pre-installed with a recovery partition which enables the user to restore the machine to the default factory settings in the event of some type of problem arising from the normal operation of the machine.

However, in order for this recovery process to function properly, the laptop must have a boot partition configured which can make access to both the recovery software, and the image contained in the recovery partition. Without that partition, things get a bit more complicated.

Goal: Recovery a laptop using the recovery partition when there is no available boot partition.

Symptom: Customer delivered a laptop in need of a restore. The machine had become unresponsive and sluggish. Typically, these are good conditions to restore to factory settings. However, attempts at restoring had previously failed and the C: drive software became damaged from hard resets.

Results: Using a bootable USB thumb drive containing Ubuntu Linux 14.04 Desktop version, the software stored in the system's recovery partition was successfully restored to the newly formatted C: drive and the system returned to working order. Note: The actual end-result for this repair case was that inevitably, the physical hardware failed and a new HDD was needed, however the technique for restoring the OS in this post is effective and valid. 

Reason: Windows operating systems seem to "collect dust" over long periods of time. Rather than becoming more efficient over time of usage, the systems fill up with temporary files, extraneous registry entries, and software all contributing to the gradual poor performance of the original machine.

Note: One important step many users forget to perform before beginning to use a new machine is to create recovery CD/DVD containing the factory images. In the past, these CD/DVD would be included with the machine, but for cost savings and convenience this is no longer the case. The manufacturers leave it up to the user to take initiative and create backups of the system on their own. This might be an oversight by the big PC makers to assume the average user has enough confidence and skill with a computer to perform this operation.

  • Bootable Ubuntu Linux USB Thumb Drive
    • Windows how-to instructions here.
    • Linux how-to instructions here.
  • Linux tool called "wimlib-imagex" (installation described below)
  • Windows 8 laptop with damaged C: partition and recovery partition

First, configure the laptop BIOS to boot from USB. If this is not possible, you may have to seek alternate methods for booting Ubuntu. You might be able to make a CD/DVD and boot from that, however those instructions won't be covered in this post. Check http://www.ubuntu.com for details.

Next, boot the laptop from the USB thumb drive. When Ubuntu starts, select the "Try Ubuntu" option instead of the "Install" option.

When the desktop appears, open a "Terminal" window. Search for "terminal" by clicking the icon on the upper left side of the desktop.

From the terminal, type "sudo gparted" to launch the graphical partition editor. From the partition editor, it is possible to see the "layout" of the Windows drive. Here, the C: drive can be recreated. Be careful not to damage the recovery partition and if possible use the partition manager to make a copy of the recovery partition onto a blank USB thumb drive if available. (see gparted copy/paste function for that process).

For the purposes of clarity, the C: drive partition in this exercise will be labeled "Windows" and the recovery partition will be labeled "Recovery." When mounting these partitions in Ubuntu (just click the disk icon showing in the menu bar on the left hand side to mount), they will be accessible from the following directories respectively:

C: partition (Windows) --> /media/ubuntu/Windows
D: partition (Recovery) --> /media/ubuntu/Recovery

Note: Change the label of the drive using the partition editor gparted if necessary, or simply use the labels on the drives as is, but be aware of the mount points and change commands as needed.

Once the partitions are created and mounted, it will be necessary to install the imaging software. Many manufacturers use "imagex.exe" as a method for creating the Windows image that gets stored in recovery partitions. However, that software is for the Windows OS and in this example the Linux version will be used. If the files in the recovery partition contain the "swm" extension, then those files were probably made using imagex.exe.

In the terminal, type the following commands to install:
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install wimtools
Be sure to accept any prompts with [Enter] or "Y" by instructions given (read carefully). Note: Since Ubuntu is running only in memory, if the system is restarted the software will need to be installed once again. If the Ubuntu thumb drive has "persistent storage" then the software should remain once installed.

Now that the software is installed, it is time to spool out the recovery partition to the C: drive. Make sure both partitions are mounted before proceeding, and then run the following command:
sudo wimlib-imagex apply /media/ubuntu/Recovery/Recovery/install.swm --ref="/media/ubuntu/Recovery/Recovery/install*.swm" /media/ubuntu/Windows
Overview of the command: wimlib-imagex
  • Command option: apply <-- this instructs wimlib-imagex to apply/extract the image
  • Source image file name: /media/ubuntu/Recovery/Recovery/install.swm <-- check your directory and filename before running this command. This example shows this use case.
  • References: /media/ubuntu/Recovery/Recovery/install*.swm <-- These are all the files that make up the image. The "*" is a wildcard since there may be any number of these files and it is difficult to type in a really long file list.
  • Target directory: /media/ubuntu/Windows <-- Where the image gets unwrapped.
This command takes some time to run depending on how big the image file is that gets restored. However, once that is complete there are still a couple final steps to do to make the restored partition bootable. 

Using the "gparted" command, make sure the flags on the C: drive include a "boot" option. Without that, the system won't be able to boot. See "gparted" flags for more details.

Next, the MBR (Master Boot Record) will need to be repaired. For this case, a Windows 7 boot disk was available for that purpose. Restarting the laptop and booting from the CD, choose the "Repair" option and Windows should detect the broken MBR and ask for a fix.

Once the repair of the MBR is complete, the system should restart into Windows 8 once again. Please post comments, questions, or corrections if there are any. Good luck with your repairs!