23.10 Upgrade a Hard Disk
You may find your self wanting to replace an older disk with a larger, faster, or newer hard disk, while still maintaining the machine as it is. That is, you want the new disk to replace the old disk in a single disk machine, including operating system. Sometimes this is forced on one if your old disk is starting to fail.
The first step is to install the new disk in your machine. The example here is installing a new 160GB SATA hard disk to replace a faulty, but still functioning, 120GB SATA hard drive. Plug the new hard drive into your machine, connecting up the power (there are usually spare power connectors in the machine) and data (you may need to purchase a SATA data cable for about $3). When rebooting the machine go into the BIOS to ensure the new disk is set to be accessed.
After rebooting you will probably have a new
which is your new hard disk, whereas your old disk is
Log in as normal, and then as root unmount any network drives and non-linux drives, just to keep other drives out of the way.
Now partition and format the new disk, perhaps using
gparted. You can mimic the partitions as they are on
/dev/sda to keep it simple—for example your old disk might
have three partitions: one of about 15GB for the root partition
/); one of about 5GB for swap; and one to take up the rest
of the space for
/home. Also make
using cfdisk (couldn’t find a way to do it with
We want to next mount the new partitions in readiness for copying all
data from the old disk to the new disk. Create mount points for
mounting the new disk partitions:
/newd/home. Mount the new disk partitions:
$ sudo mount /dev/sdb1 /newd $ sudo mount /dev/sdb2 /newd/home
We now go into single user mode to shutdown daemons that might otherwise be writing to files as we try to copy them. This will also terminate any current login sessions and XWindows sessions:
$ sudo telinit 1
Now copy all files to new disk:
# cp -a /bin /boot /dev /etc /home /initrd /lib /lib64 /newd # cp -a /media /mnt /opt /root /sbin /tmp /usr /var /newd # cp -a /vmlinux* /newd # mkdir /newd/proc /newd/sys
Have a look at the old and new roots (
and check for other directories in
/ not copied and for
different permissions that should be made the same. The following
might be useful:
$ ls -l / > LLo $ ls -l /newd > LLn $ diff -c0 LLo LLn
Once everything looks okay shutdown the computer.
We should now be in a position to treat the new hard disk as the main
hard disk (
/dev/sda), so open up the computer and swap the SATA
cables over between the two hard drives.
Reboot the computer, but boot from the second (i.e., old) SATA drive,
since you probably can not boot from the new one yet! Perhaps boot as
single user mode (recovery mode). This boots using the MBR (master
boot record) from the old SATA but loads the system from the new SATA
(which is now
Hopefully it all boots just fine. This is now using the new hard disk!
Next we need to tell grub to set up a master boot record (MBR) so we can boot from this new disk:
$ grub grub> root (hd0,0) grub> setup (hd0) grub> quit
Finally, reboot and all should be fine, booting from the new hard drive, without any involvement of the old hard drive. If so, remove the old hard drive once it is no longer needed and tell the BIOS that it should no longer look for it, if you need to.
Your donation will support ongoing availability and give you access to the PDF version of the book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.