Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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 /dev/sdb disk which is your new hard disk, whereas your old disk is /dev/sda.

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 /dev/sdb1 bootable using cfdisk (couldn't find a way to do it with gparted).

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 and /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 /newd) 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 /dev/sda).

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.

Copyright © 1995-2006 [email protected]

 
 
  Published under the terms fo the GNU General Public License Design by Interspire