Monthly Archives: April 2013

Restoring boot sector on Windows XP notebook

I had another disk/partition adventure recently. My notebook stopped booting after I updated XUbuntu on the second partition of the HD. Apparently the update screwed-up boot sector on Win XP partition (the first one). So I got a USB flash drive with WinXP SP3 setup and booted from it hoping to use Windows recovery tools: fixboot and fixmbr. Unfortunately the recovery was not able to find any Windows installations; in fact it did not see the disk at all. The notebook uses Intel ICH9 controller and its drivers are not available on the setup disk. Apparently I could not use a floppy to add an extra driver in the boot process, so I needed to add these drivers to the installation. There are instructions on how to do this using nLite, but it looked like it can take a long time. And then I realized that I can disable AHCI mode of the SATA controller. One change in the BIOS settings, and the setup disk could find Windows partition and I fixed boot sector using fixboot. After fixing the boot sector I changed SATA controller mode back to AHCI and everything worked fine.

On other motherboards/notebooks these compatibility modes can be called differently (ATA, IDE, something else?), AHCI is sometimes called “native” mode.

Moving bootable NTFS partition to a new drive

My old video PC started acting up – it was losing BIOS settings randomly. So I’ve replaced the motherboard, installed Windows XP, software, … Everything worked fine but the ancient IDE disk from Maxtor turned out to be very noisy. So I’ve ordered an SSD – the cheapest and hence the smallest I could get. Just enough to install the OS: all videos and music are located on a Samba server. When the new disk arrived, I decided to copy Windows XP partition to the new disk – installing XP again is no fun.

Starting state and notation:

  • Maxtor 160GB disk with 80GB NTFS boot partition – I’ll call it HD
  • OSZ 32GB disk – I’ll call it SSD
  • Windows XP PC – I’ll call it XP
  • Ubuntu PC – I’ll call it Ubuntu

Here is what I did. It is not a step-by-step instruction, just a description of what actually worked (I tried other options). Use at your own risk.

Connected SSD and HD to my Ubuntu, the disks were labeled as:
sdg – SSD (destination)
sdf – HD (source)
Check these labels every time you connect a disk to Ubuntu.

Since I already “played” with the SSD, I needed to clean-up the config area. The command below will delete all partitions, MBR,  EVERYTHING. Be very careful not to use it on a wrong drive:

sudo dd if=/dev/zero of=/dev/sdg count=1024

Plug SSD into XP. Go to the Disk Manager, initialize the disk, create full-disk NTFS partition (32GB), mark this partition as active. Try to boot XP from this disk – it should produce an error “NTLDR not found” It means that MBR is OK and the partition is bootable.

We need to shrink 80GB partition on HD –  SSD is only 32GB. New size will be 24GB:

sudo ntfsresize -s 24G  /dev/sdf1

At this point we have a 24GB NTFS volume on a 80GB partition. Yes, NTFS volumes can be smaller than the partition they are in.

Plug HD into XP and boot from it. The system will check the disk before booting.

Plug SSD and HD into Ubuntu. Clone the 24GB NTFS volume from HD to the 32GB partition on SSD. Flag -O means overwrite existing file (disk partition in our case):

sudo ntfsclone -O /dev/sdg1 /dev/sdf1

Run this command to find the exact size of the partition on SSD:

sudo ntfsresize -i /dev/sdg1

The output should look like this:

ntfsresize v2012.1.15AR.1 (libntfs-3g)
Device name        : /dev/sdg1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 23999996416 bytes (24000 MB)
Current device size: 32012757504 bytes (32013 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 12343 MB (51.4%)
Collecting resizing constraints ...
You might resize at 12342161408 bytes or 12343 MB (freeing 11657 MB).
Please make a test run using both the -n and -s options before real resizing!

We need to resize NTFS volume to fill the partition. In the info above we see that the device size is 32012757504 bytes, so we set new volume size to 32012757 kilobytes:

sudo ntfsresize --size 32012757k  /dev/sdg1

This is it. Plug SSD into XP. The system will check the disk on first boot.

If new partition is bigger than the old one there is no need to shrink the old NTFS volume. Just clone and resize.