Bembel-B Blog


Hddtemp with SATA Support on Ubuntu 7.04 and Debian

I switched my home PC from Fedora Core 5 to Ubuntu 7.04 Feisty Fawn on Sunday, which went quite smoothly and satisfying. Aside, the currently available hddtemp package (0.3-beta15-33) of Ubuntu 7.04 is not capable of reading temperatures of SATA drives. I found that bug report, after fiddeling with the configuration files and init scripts.

Ubuntu Logo

To get my temperatures with hddtemp I added my drive to /etc/hddtemp.db determing the needed values with sudo smartctl -d ata -a /dev/sda (see man hddtemp).

root@p512o:/etc# diff hddtemp.db.orig hddtemp.db
> "ST3250823AS"                         194  C  "Seagate Barracuda 7200.8 250GB SATA"

I also had to rebuild the deb package with the Debian unstable hddtemp_0.3-beta15-36 sources as follows.
You can download the i386 package, but beware: I’m a noob and didn’t change anything of the package (like mentioning that I built it for Ubuntu), which might be necessary.

Prepare build environment:

mkdir -p ~/debbuild/hddtemp
pushd $_
dget -x
cd hddtemp-0.3-beta15/

Build (without signing because of seahorse-agent problems) and install:

debuild -rfakeroot -uc -us
sudo dpkg -i ../hddtemp_0.3-beta15-36_i386.deb

The hddtemp daemon was restarted with the installation. Test daemon output:

netcat localhost 7634

Maybe I could just have installed the binary Debian package or just wait for the Ubuntu package to be updated. But as I’m new to the Debian world, having mainly used Red Hat style Linux until now, I see this as an exercise. Mixing apt repositories for Ubuntu with Debian ones is not recommended as far as I understand.

Here’s some related information I’ve bookmarked about deb packages:


[070513 Add logo]
[070523 Download link for i386 deb package]
[2009-04-26: Fix links.]



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


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/

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

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

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/ 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.


[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