Penguins help clean up broken glass

Earlier this week, my friend brought his laptop to me because Windows 8 refused to boot after a restart. He had attempted to repair it himself, but ended up making things worse, to the point that the manufacturer recovery console and the Windows 8 installer wouldn’t even boot. Thankfully for him, I had the power of Linux with me and we were able to revive his laptop very easily.

1. Backing up important files

The first step to the recovery was to make sure his important files were safe. I always carry around a copy of KNOPPIX with me for emergencies like this, and he had recently bought an external hard drive to put his stuff in. We couldn’t get X working for a graphical session, so we had to make do with the command line. Fortunately for both of us, I’m quite comfortable with using the console, so it was essentially a trivial, albeit time-consuming, task.

An overview of the steps: identify the partitions, mount the partitions you want to read from and write to, and copy.

Identifying partitions

I use lsblk -f to identify partitions, which gives you output like this:

$ lsblk -f                                                       
NAME         FSTYPE LABEL           UUID                                 MOUNTPOINT
sda                                                                      
├─sda1       ntfs   SYSTEM_DRV      9A5CF3AE5CF382F5                     
├─sda2       ntfs   Windows7_OS     961AF60B1AF5E85F                     
├─sda3                                                                   
├─sda4       ntfs   Lenovo_Recovery 2040F1E840F1C516                     
├─sda5       vfat   TEMP            4A02-3CBC                            
├─sda6       ntfs   Data            3C7A37B77A376CB0                     /mnt/ddata
├─sda7       ntfs   Shared          9C967424967400D6                     /data
├─sda8       ext4   home            1d6af6d2-56f1-46c8-b452-1064b895aba4 /home
├─sda9       ext4   root            e9ba9220-46be-4c4a-8b41-488b0f77c38a /
├─sda10      swap   swap            3635c67a-0fc4-4cdb-b5a8-a59b4bf3c601 [SWAP]
├─sda11      ext2   boot            3575b4e0-d694-4b0a-9c78-6556b1a316d4 /boot
└─sda12      ext4   var             a2c24ab7-c366-4f56-b43f-dbb6a94ca267 /var
sdb                                                                      
└─sdb1       ntfs   Elements        A4C45E13C45DE856                     /mnt/backup
sr0                                                                      
loop1                                                                    
└─truecrypt1 vfat   TMP             B9BE-D7FE                            /home/johann/tmp
mmcblk0                                                                  
└─mmcblk0p1  vfat                                                        

Identify find the partition with the data on it (the C: drive) and make note of the name. Also make note of the partition that you’ll be backing up to. I have my system set up differently from most Windows users, but for the sake of example, let’s assume that my files are all on the C: drive. My C: drive is sda2 and my external hard drive is sdb1.

Mounting the partitions

To be able to copy files from one partition to another, they have to be mounted. To mount a partition means to make its contents accessible in the file system. There’s a folder in the Linux file hierarchy intended for manual mount points: /mnt.
The following commands, run as root, set up the mount points and mounts the Windows partition to /mnt/windows (as read-only) and the external drive to /mnt/backup:

# mkdir /mnt/{windows,backup}
# mount -o ro /dev/sda2 /mnt/windows
# mount /dev/sdb1 /mnt/backup

Copying the files

All this identifying and mounting was done so that we could copy files from the Windows partition to the backup location. Copying the files is likely the most time-consuming part of this whole restore, especially if there are a lot of large files to back up.
For this example, I want to copy the Users folder (C:\Users) to a subdirectory the backup location.
I make the subdirectory (I’m going to call it cdrive) with

# mkdir /mnt/backup/cdrive

and copy the folder over with

# cp -av /mnt/windows/Users /mnt/backup/cdrive/

The -a option makes cp act like an archiver, and -v shows you what file cp is copying. The trailing slash at the end of /mnt/backup/cdrive/ is important because it tells cp to copy Users as a subfolder of cdrive instead of copying the contents of Users to cdrive.

2. Preparing the installation medium and attempting to recover

While we were waiting for his data to finish being backed up, we prepared the installation medium. We didn’t have any discs to burn, so we used a 16GB USB flash drive. Fortunately for him, I had a copy of the Windows 8 installation ISO handy. Using my laptop, which is running Arch Linux, I wrote the ISO file (located at ~/iso/win8.iso) to the flash drive (detected as /dev/sdb) using dd:

# dd if=~/iso/win8.iso of=/dev/sdb

Notice how I’m writing to the disk itself (sdb) rather than a partition on the disk (e.g. sdb1).

For some reason, his computer didn’t want to boot the flash drive, so we attempted to redo the process using UNetBootin. It booted, but it displayed a BSOD before reaching the first screen of the installation.

With few options left, we attempted to reset the computer using the factory restore partitions. Even that refused to boot.

It was late and we were both tired, so he decided to buy some blank DVDs the next day to attempt it then. In the meantime, I didn’t want him left without a system to use, so I wrote a copy of Linux Mint to the flash drive using a similar dd command and had him use the LiveUSB. It worked perfectly, and he was able to use it fairly easily.

3. Wiping the partition table

The next day, he came to me with the Windows 8 installation ISO burned to a DVD, presumably using a disc-burning tool on Linux Mint. Attempting to boot to that resulted in a BSOD, similar to the USB drive prepared with UNetBootin. Failing to boot to the disc and the recovery environment, the only thing left to do was to start from scratch.

We used GParted in Mint to delete all the partitions, leaving the entire disk as a single block of unallocated space. Messing around with partitions is not something I’m comfortable doing in the command line (except in DOS), but if you insisted, you could use fdisk.

4. Reinstalling Windows 8

After wiping all the partitions, the Windows 8 installation disc booted. We were able to go through the Windows 8 installation smoothly (even if we managed to spend 10 to 20 minutes thinking of a name for the computer); by the end of it, he had a fresh—and more importantly, working—Windows 8 system.

5. Restoring data

The final step is data restoration and recustomizing the account. I left this for him to do on his own because it’s easy enough, but there was one thing he couldn’t figure out how to do: get his music off his iPhone. It’s a relatively simple task to transfer music from the computer to the iPhone/iPod, but Apple seems to have made it difficult to do the reverse. To solve the problem, I offered [Arch] Linux yet again.

Using ifuse, I mounted the iPhone to a directory and went to the folder where all the music is stored. All the music files are stored in subdirectories with four-letter filenames, similar to F0/CVBN.mp3. Assuming that the destination is /mnt/backup/iphone-music, the command to copy all the files in all subfolders is

$ cp -rv */* /mnt/backup/iphone-music/

Those filenames are highly non-descriptive, and his music was tagged correctly, so I changed the filenames to Artist - Title.mp3 format effortlessly using EasyTAG.


My friend is now very happy to have a working system again, and it’s all possible thanks to Linux. So now you know: it’s not a bad idea to keep a few penguins around to clean up the broken glass in case any windows break.


Advertisements

$ cat your_comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s