replacing a hard drive

The idea is to totally replace a hard drive with a new one, this means copying all the data from each partition of the old hard drive to a new one. why? :

  • Your hard drive is old and/or \"almost\" broken (see smartmontools)
  • Your hard drive is full and so you want to replace it with a bigger disk.
  • You are bored
  • For replicating a system

What you need :

  • a computer
  • a hard drive - to be replaced
  • a \"new\" drive - the replacement
  • a Debian install CD (netinst will suffice) or any other liveCD (all we need is to get a shell that\'s not running off the system on the disk drive)

What needs to be done :

  • plug the new disk drive on the computer as \"sda\" (or hda), and the old (current) drive as \"sdb\" (or hdb)
  • in the example we have

    • sda - new 320GB
    • sdb - old - 80GB
      • sdb1 10GB ext3
      • sdb2 1GB swap
      • sdb3 69GB ext3

Booting off the Debian CD, partitioning et formatting

Boot off the Debian CD and go through the first options, mostly keyboard options. (stop anywhere before using partitioning tool). Then get a terminal by pressing alt - F2. If you have already partitioned the disk than yay for you, otherwise you can do this with fdisk. You must keep in mind that sda1 should be at least as big as sdb1 (or at least have enough space to contain the contents of sdb1), the same goes for sda3. As for the swap partition, in this case sda2, you can do whatever you want of course. On the Debian install CD \"fdisk\" is available, this tutorial does not cover this, for that you can make a request. Different boot and/or live CDs may have other partitioning and/or formatting software. So basically, create your partitions. I use ext3 filesystem, but of course you can do whatever you want, actually you can even use this process if you wanted to just safely change the filesystem (if you do change the filesystem than don\'t forget to update the fstab that you copy to sda1). Here is an example with basic ext3 fs.

mke2fs -j /dev/sda1 mke2fs -j /dev/sda3

Data copying

It\'s possible to simply use cp to copy the data with the option \"-a\" which is the equivalent to \"-dpR\" which means :

  • -d same as --no-dereference --preserve=links
  • -p same as --preserve=mode,ownership,timestamps
  • -R, -r, --recursive

Mount the disks as follows :

cd /mnt mkdir sda1 sdb1 sda3 sdb3 mount /dev/sda1 /mnt/sda1 mount /dev/sdb1 /mnt/sdb1 mount /dev/sda3 /mnt/sda3 mount /dev/sdb3 /mnt/sdb3

now the super simple part, it can take forever though :

cp -a /mnt/sdb1/* /mnt/sda1/ cp -a /mnt/sdb3/* /mnt/sda3/

Next, initiate the swap partition

mkswap /dev/sda2

And finally, install grub (or lilo) on the MBR

chroot /mnt/sda1 grub-install # or \'lilo\' halt

Swell, the machine should be off and you can unplug the \"old\" disk drive et maybe even rid the CD-Rom drive of the boot CD.. :] .. voilĂ , you can now boot onto your same old system with a brand new, bigger, faster, awesomer disk drive.. . .. . if .. if everything went well.. :]

And then.. .

Yes, there is a bit more to do, you should recycle your old equipement of course, but before doing that, you might want to destroy the data before disposing (or selling/giving) your hard drives.. you can check the programs shred and wipe

Leave a comment
You may use the following HTML tags: <p> <a> <strong> <b> <em> <i> <cite> <blockquote> <code> <pre>

Your comments WILL NOT be submitted to any third party (not even for anti spam verification).