Bembel-B Blog

2006/04/22

The SATAnic Power of State-of-the-Art OSes and Installing Them

I recently did a clean install of Windows XP and Fedora Core 5 on my SATA HDD and it was quite an odyssey to get it working. I’ll briefly describe the odds I was confronted with. The real problem was to get Windows NTLDR/boot.ini bootstrap and the GRUB bootloader installed and configured correctly. One source of trouble seems to be that I had my old (even though unpartitioned) IDE HDD still plugged in and it could not be disabled in the BIOS. I am using an Asus A7N8X-E Deluxe mainboard.

Installing Windows XP

Of course one needed to have the Sil SATA driver on a floppy disk and press F6 when the Windows XP Install CD got booted. I knew this already. But downloading that 20+ MB driver package from the Asus website took over 30 minutes with about 13KB/s.. Very frustrating!
The strange thing with the Windows install was that it wouldn’t let me install on the SATA HDD without having enough free space on the IDE HDD. I had to create some partition on the IDE HDD and then the first step of installation continued.
Funny enough, the Windows bootloader got installed on that IDE HDD. So I had my Windows installed on drive C: (SATA) and the bootloader on drive D: (IDE) with a boot.ini configured to load Windoze from the second (SATA) HDD.
To fix that, I had to change the boot.ini to use the first HDD. I edited the file using a Linux Live-CD and copied it to a floppy disk (as there is no text editor included in the Windows Recovery Console AFAIK). Then I booted the Windows Recovery Console and copied all files from the IDE drive and the fixed boot.ini from the floppy disk to the SATA drive. This of course only was sufficient, as I wanted to use GRUB as my bootloader. Quite interesstingly, the drive letters using the Recovery Console where different, i.e. C: was IDE and D: was SATA.. Stupid drive letters anachronism I say!

Installing Fedora Core 5

The installation process was quite straight forward. Only thing that was annoying: There was only the option to install GRUB into the boot sector of the IDE drive or into the beginning of the first Linux partition (SATA). So I had to reinstall GRUB giving the desired destination after the OS was installed.
But this wasn’t enough. The problem is that I booted from CD and therefore the CD-ROM drive was seen as first boot drive and the HDD was considered the second drive. So I had to edit /boot/grub/system.map and define the HDD to be the first boot drive and do a reinstall of GRUB (grub-install /dev/sda).

Conclusion

Some part of problems I think were caused because I had that IDE HDD still installed. On the other hand the installer programs should be smart enough to automagically get around these problems. Sadly I didn’t find the solution as directly as it may sound. Searching the web I didn’t find anything describing my case, so this is why I wrote this..
My description of problems and how I solved them is surely very compressed for such a complex and confusing topic. So feel free to ask for clarification etc. by commenting.

ChangeLog

[2006-04-23: Add tags.]

2005/10/25

How to clone a defective hard drive, migrate a Linux installation, and locate defective files

As my (just 15 months old Samsung IDE) hdd continuously had more and more bad sectors, I had to replace it with a new (Seagate SATA) one. Here’s what I did to save as much data as possible, keeping my old filesystems (NTFS, FAT32, ext3, swap).

old opened hard disk drive

Cloning

Boot from the Linux Live-CD Knoppix 4.0.2 enabling DMA at the boot prompt with knoppix dma.

cat /proc/swaps shows me Knoppix is using the swap partition on my defective hdd.

All following commands in this entire HOWTO have to be issued as user root! Use su - to switch to root.

So I unmount the swap partition with swapoff /dev/hda6.

Now the cloning process using dd_rescue is started, filling unreadable sectors with zeroes.

dd_rescue -A /dev/hda /dev/sda

About two hours later copying of all 160GB is finished.
As I didn’t set a logfile for dd_rescue to report bad sectors and Knoppix’ dmesg has only a small buffer space (and the syslog file isn’t used at all), I sadly ain’t able to name all the bad sectors positions at this time. So you would better use that logfile option!
So for now I only know the number of bad blocks (1328!), the total amount of unreadable data (~700kB), and, from what I could read scrolling down the terminal screen, the approximate locations of the bad blocks given in MB counted from the beginning of the hdd.

Let the cloned Linux installation use the new hdd

As I wasn’t able to mount the cloned partitions immediately afterwards, I did a reboot of Knoppix and it worked then. Good thing!

mount -o remount,rw /dev/sda2
mount -o remount,rw /dev/sda3

I now have to fix the partitions locations definitions for my cloned Linux installation to use the new hard drive.

I add the line (hd1) /dev/sda to my boot partition at /mnt/sda2/grub/device.map.

Also change the grub bootloader configuration at /mnt/sda2/grub/grub.conf from hd0 to hd1 and the kernel parameter root like this:

--snip---
splashimage=(hd1,1)/grub/splash.xpm.gz
#hiddenmenu
title Fedora Core (2.6.12-1.1372_FC3)
        root (hd1,1)
        kernel /vmlinuz-2.6.12-1.1372_FC3 ro root=/dev/sda3 rhgb quiet
        initrd /initrd-2.6.12-1.1372_FC3.img
--snip---

Then there’s to fix the fstab at /mnt/sda3/etc/fstab. I change the device from /dev/hda to /dev/sda and also switch from using labels (/boot and /) for my Linux partitions to using the distinct device node names (/dev/sda2 and /dev/sda3).

Also mtab at /mnt/sda3/etc/mtab has to be fixed the same way.

And as I am using automount, these configuration files (/mnt/sda3/etc/auto.*) have to be fixed too.

Only thing left is the swap partition. I fixed that simply by rebooting from the new hdd (as defined in the BIOS settings) and typing this in the terminal:

swapon /dev/sda6
swapoff /dev/hda6

UPDATE: The above configuration still uses the bootloader in the old HDD’s MBR. The old HDD is still seen as the first boot device by the BIOS (therefore I use hd1 and not hd0). I figured that out when I wiped my old HHD’s partitions.
To exclusively boot from the new (cloned) HDD, you have to reinstall GRUB on this HDD. The process I would have had to use is a little tricky, and can be found in my posting about installing OSes on a SATA HDD.
In brief, one boots from the Fedora Rescue CD and chroots to the Fedora partition on the new HDD. Then fix the /boot/grub/system.map to see the HDD as first boot device and reinstall grub on this HDD. You would also have to fix /boot/grub/grub.conf to use hd0 instead of hd1 and configure your BIOS to boot from this HDD.
If you still have your old HDD intact (i.e. the system is booting from HDD), you most probably can skip the step of booting from the Rescue CD and simply boot from the HDD.

Let the cloned Windows XP installation use the new hdd

Heheh.. No way, dude! At least it would take hours and days from my knowledge. You would have to edit \boot.ini and also the System Registry’s drive and partition definitions. And then all paths and drive letters still point to the old hdd (as far it’s still plugged in).
So, once again, Microsith’s ultimate answer is: Reformat and reinstall! Outch!

Find bad sectors and affected files

The SMART system will only name the first bad sector it finds. On Linux there’s a tool called badblocks. I only tried its non-desctructive read-write test and it’s slow but reliable. But if you kept the dd_rescue log (unlike me), you find the block numbers there.

To locate a file by block number on a Linux filesystem (ext2, ext3, minix, reiserfs etc.), one can use debugfs as described in a HOWTO at smartmontools.

Locating files by sector or block number on a NTFS partition is possible under Linux with the use of ntfscluster found in the ntfsprogs utility suite by the Linux-NTFS Project.

How to do this on FAT or NTFS systems is still unknown to me. After googling for quite a long time I still did not come up with a solution. I guess one should be able to accomplish this with a disk editor. Still the question, which one would that be?!

Copyright notice

The photograph showing an old opened hard disk drive used in this entry is in the Public Domain and thus free of any Copyright restrictions. The content is provided by Michael Connors and Morguefile and has the ref id# 13218.

ChangeLog

[2006-04-23: Add tags.]
[2006-07-21: Reinstall GRUB to be able to boot exclusively from the clone. Locate files by sector or cluster number on NTFS partitions. More tags.]

Create a free website or blog at WordPress.com.