How To: Hard Disk Drive Upgrade

Rate this item
(0 votes)

How to copy a Linux system from one disk to another



  1. Introductionb2ap3_thumbnail_iStock_000001984689XSmall.jpg
  2. Install both disks on your system
  3. Unmount non-Linux partitions and network drives
  4. Partition the new disk
  5. Format the new disk
  6. Mount the new disk
  7. Copy files from the old disk to the new disk
  8. Modify /new-disk/etc/fstab as appropriate
  9. Prepare LILO to boot the new disk
  10. Make a boot diskette (optional)
  11. Remove the old disk
  12. Reboot the system, modify LILO configuration file

1. Introduction

This Mini How To describes the transfer (or migration) of an entire Linux system from one disk to another.

Hereinafter we will adhere to the following meanings: "/dev/hda" (first IDE hard disk) means "old" disk, and "/dev/hdb" (second IDE hard disk) means "new" disk.

Specific partitions of old disk are referred to as /dev/hda1, /dev/hda2 Specific partitions of new disk are referred to as /dev/hdb1, /dev/hdb2 and so forth.

All explanations in this How To are based on Red Hat 6.0. They have also been tested with Debian 2.1, Slackware 3.5 and SuSE 6.2; we will indicate differences in distributions.

2. Install both disks on your system

Modern systems support four EIDE devices on one hard disk controller, therefore ideally there should not be a problem with installation of both disks on the system, even if you have other EIDE devices. Hard disks and CD-ROM are typical examples of EIDE devices. Floppy drives and streaming-tape drives are usually connected to the floppy drive controller rather than to hard disk controller.

SCSI adapters are more flexible and support up to seven devices. If you are not lucky (and rich) owner of SCSI adapter, then you might already know what devices are SCSI!

Even very old systems support two devices on the hard disk controller, so you will still be able to install two disks simultaneously. However, if in addition to the old disk you have another device connected to it (for example, if you have hard disk and CD-ROM), then you will have to unmount it to install the new disk.

You also need to set the disks to master or slave by setting jumpers appropriately. Usually information about these settings is written on the disks but if it is not there, read manuals or ask the manufacturer.

You also have to inform BIOS about disks and their geometry. Usually BIOS setup program launches by pressing a ey during system boot-up. Below you will find key options for most common BIOS versions:

Acer Notebooks:

F2 key during Power-On Self-Test (POST)

American Megatrends (AMI):

Del key during Power-On Self-Test (POST)


Del, or Ctrl-Alt-Esc


F10 key after you see a small square in the top right corner of the screen (during system boot-up)



Esc key during Power-On Self-Test (POST)

Hewlett-Packard Pavilion:

F1 key during HP blue screen

IBM Aptiva 535:
F1 key, while a square with wavy lines appears in the upper right corner of the screen

Ctrl-Alt-Del, or Ctrl-Alt-Ins, when the cursor is in the right top corner

Ctrl-Alt-S during Power-On Self-Test (POST)

Packard Bell:
In some models F1 or F2 key during Power-On Self-Test (POST)

Ctrl-Alt-Esc, Ctrl-Alt-S, or Ctrl-Alt-Enter

Many old systems require Installation or Reference Disks.

Reboot the system and login as root. If you use a "su" command to become root, use "su -" (with hyphen).

3. Unmount non-Linux partitions and network drives

Some users mount partitions of other operating systems (DOS, Windows, OS/2, etc.), to use them im Linux. These partitions should be created and copied in their respecitve operating systems and they should be unmounted before copying Linux partitions. For instance, if your DOS partition is mounted to /dos catalog it should be unmounted using the following command:

umount /dos

Please note the syntaxis of umount command, it differs from the Englsih word unmount and does not contain n letter.

You will also have to unmount all network disks in the similar manner.

4. Partition the new disk

To partition the new disk use the following command:

fdisk /dev/hdb

EIDE devices are named as hda, hdb, hdc, and hdd in directory /dev. Partitions on these disks can be numbered from 1 to16 and are also in directory /dev. For instance: /dev/hda4 – is a 4th partition on disk a (first EIDE disk).

SCSI devices are named as sda, sdb, sdc, sdd, sde, sdf, and sdg in directory /dev. Partitions on them are similar to EIDE disks and can be numbered from 1 to 16 and are in directory /dev. For instance: /dev/sda3 – is a 3rd partition on SCSI disk a (first SCSI disk).

For Linux partitions with ext2 file system use file system identificator 83. For swap partitions use 82.

You need to place all files needed for booting Linux within first 1024 cylinders. One of the options is to make a small partition (5 Mb or something like that) only for directory /boot at the beginning of the disk. (Attention to Slackware users: the kernel is in /vmlinuz instead of /boot/vmlinuz, that is why you should copy the kernel to directory /boot/vmlinuz/ as well as to directory /boot to this small partition.)

Partitions for other systems (other than Linux) shoud be made in their respective systems using their fdisk or something similar, but not with the help of fdisk from Linuxs.

5. Format the new disk

To format ext2fs partitions on the new disk use the following command:
mkfs.ext2 /dev/hdb1
To make the program search for bad blocks (physical defects) in partition that is being formatted, add option -c before /dev/hdb1.
In case the new disk will have more that one Linux partition, format them all by running "mkfs.ext2 /dev/hdb2", "mkfs.ext2 /dev/hdb3" respectively. Add option -c, if necessary.

(Note: in older distributions command "mkfs -t ext2 -c /dev/hdb1" did not check for bad blocks in Red Hat, Debian and Slackware, but it had to according to man. Now it has been corrected.)

To format swap partition use the following command:

mkswap /dev/hdb1

You can also add an option -c to check for bad blocks on partition "/dev/hdb1".

6. Mount the new disk

Create directory for the new disk, for example /new-disk and connect it there:
mkdir /new-disk
mount -t ext2 /dev/hdb1 /new-disk
If new disk has more than one partition, mount them all in directory /new-disk in the same order they will be later.

Example: New disk will contain 4 Linux partitions, accordingly:

/dev/hdb1: /
/dev/hdb2: /home
/dev/hdb3: /var
/dev/hdb4: /var/spool

Mount them in directory /new-disk respectively, as:

/dev/hdb1: /new-disk
/dev/hdb2: /new-disk/home
/dev/hdb3: /new-disk/var
/dev/hdb4: /new-disk/var/spool

Before mounting you will have to create mount points on respective levels, for example:


mkdir /new-disk [1st level]
mount -t ext2 /dev/hdb1 /new-disk

mkdir /new-disk/home [2nd level]
mount -t ext2 /dev/hdb2 /new-disk/home

mkdir /new-disk/var [2nd level also]
mount -t ext2 /dev/hdb3 /new-disk/var

mkdir /new-disk/var/spool [3rd level]
mount -t ext2 /dev/hdb4 /new-disk/var/spool

If you create new mount point to directory /new-disk/tmp, you will need to modify permit to this directory to enable everyone to access it:
chmod 1777 /new-disk/tmp

7. Copy files from the old disk to the new disk

Most probably you will have to shift to single user mode before copying the disk, it is required to turn off system daemons, logs and to prevent users from logging into the system:
/sbin/telinit 1

When copying the hard disk you need to copy all directories and files, including links.

However, you need not copy the directory /new-disk, because it is the new disk!

Moreover, you need to create the /proc directory on the new disk but do not copy its contents: /proc – is a virtual file system and it does not contain real files, it contains only information about system and processes in it.

There are 3 different ways to copy the old disk to the new disk. It can be a time consuming operaiton, especially if your disk is large and RAM is small. Minimum copy speed is around 10 Mb/min, though in all probability in reality it will be much faster.

You can follow the copy process by using the command "df" from another terminal. Use "watch df" or "watch ls -l /new-disk" to see the report that is updated once in two seconds; press Ctrl-C to stop viewing. Please bear in mind that using "watch" command can slowdown the copy process.

cp -ax / /new-disk

This one is the easiest way but it works only if your original system was on a single disk partition.

The -a option saves original file system as much as possible. The -x option limits cp to a single file system – therefore you need not worry about /new-disk and /proc directories.

For SuSE users: When using this method you need to create /dev/pts directory on the new disk. Use the following command "mkdir /new-disk/dev/pts".

(Note: New versions of cp, when using the –x option will create empty directories /new-disk/new-disk and /new-disk/proc. In this case you need to delete /new-disk/new-disk directory and leave /new-disk/proc..)

cd / && echo cp -a `/bin/ls -1Ab | egrep -v "^new-disk$|^proc$"` /new-disk | sh

(write it all in one line)

This command goes to root directory and then copies all files and directories except /new-disk and /proc in /new-disk. Note that the first symbol after ls is the number 1, not the letter L!

This command should work anyway.

cp -a /bin /boot /dev /etc /home /lib /lost+found /mnt /root /sbin /tmp /usr /var /new-disk

(write it all in one line)

The last directory /new-disk, is the destination for the cp command. All the other directories are the sources. Therefore, we copy all directories from the list to /new-disk.

With this method you simply list the directories to be copied. Here we mentioned all directories except /new-disk and /proc. If you cannot use first two methods for some reasons, then you can always manually list all directories to be copied.

Also take into account that if root directory has some files, they also have to be copied with another command. In particular, it is required with Debian and Slackware, since these two distributions put files in the root directory:

cp -dp /* /.* /new-disk

After using any of the above methods you will also need to create /proc directory on the new disk, if it is not yet there:

mkdir /new-disk/proc

Then you can check the file system of the new disk, if you want:

umount /new-disk

fsck.ext2 -f /dev/hdb1

mount -t ext2 /dev/hdb1 /new-disk

If there is more than one partition on the new disk, then you will need to unmount them from the bottom up before running fsck.ext2: in accordance with the example above first you need to unmount 3 level partitions followed by 2 level and only then 1 level.

You may also comapre the two disks to make sure that everything has been copied correctly:

find / -path /proc -prune -o -path /new-disk -prune -o -xtype f -exec cmp {} /new-disk{} \;

(write it all in one line)

For Slackware users: standard ‘basic’ Slackware installation (only A series files) does not include "cmp", therefore you will not be able to run this command if you have only basic files installed. "cmp" command is in “AP1” series files.

This will only compare regular files, not character or block devices (from /dev directory), sockets, etc., are not included, since the "cmp" command doesn’t work properly with these..

8. Modify /new-disk/etc/fstab as appropriate

If partitions or their organization on the new disk is different from the old disk, modify the file /new-disk/etc/fstab on the new disk appropriately.

Make sure that partition names (first column) correspond to partition organization that you created on the new disk and that old disk partitions have been removed and that you mount only one partition as the root partition "/" (it is written in the second column).

For swap partitions, use a line similar to this one:

/dev/hda1 swap swap defaults 0 0

9. Prepare LILO to boot the new disk

We assume that you want to install LILO on the Master Boot Record (MBR). It is done in most cases. You want to install LILO on second disk that will become the first.

Edit the file /new-disk/etc/lilo.conf similar to the following one:

disk=/dev/hdb bios=0x80 # Tell LILO to treat the second
# disk as if it was the first
# disk (BIOS ID 0x80).
boot=/dev/hdb # Install LILO on the second hard
# disk.
map=/new-disk/boot/map # Location of “map file”.
install=/new-disk/boot/boot.b # File to copy to hard disk
# boot sector.
prompt # LILO should show
# "LILO boot:" prompt.
timeout=50 # Boot default system after 5
# seconds. (value is set in tenths
# of a second.)
image=/new-disk/boot/vmlinuz# Linux kernel location. The real name can
# include version number
# for example,
# "vmlinuz-2.0.35".
label=linux # Name of Linux system.
root=/dev/hda1 # Location of root directory
# of the new disk. Modify it
# according to new system.
# Note, you should use the name
# of the future location, once the old disk
# has been removed.
read-only # First mount partitions in read-only
# to run fsck.

For Slackware users: Use image=/new-disk/vmlinuz.

If you use SCSI disk, then, perhaps, you may have to add a line with "initrd". See your existing file /etc/lilo.conf.
Install LILO on the new disk:

/sbin/lilo -C /new-disk/etc/lilo.conf

The -C option tells LILO which configuration file it should use.

10. Make a boot diskette (optional)

You may, if you want, make a boot diskette to avoid boot issues, should they appear during booting from the new disk.
Insert an empty diskette, format it, create file system on it and mount it:

fdformat /dev/fd0H1440

mkfs.ext2 /dev/fd0

mount -t ext2 /dev/fd0 /mnt

For Debian users: In Debian 2.x version use /dev/fd0u1440 instead of /dev/fd0H1440. In Debian 1.x version, use /dev/fd0h1440, with a lower case h.

For Debian users: In Debian version 2.x, use superformat instead of fdformat. You can ignore the error mformat: command not found. In Debian version 1.x, in case you do not have fdformat command, you can skip it if the disk has been already formatted. You can simply check the diskette for bad blocks by adding the -c option to mkfs.ext2 command.

For Slackware users: Use /dev/fd0u1440 instead of /dev/fd0H1440. In very old versions try using /dev/fd0h1440, with lower case h.

For SuSE users: Use /dev/fd0u1440 instead of /dev/fd0H1440.

Copy all files from directory /boot to the diskette:

cp -dp /boot/* /mnt

For Red Hat users: If directory /boot contains vmlinux and vmlinuz files (note the difference in the last letter), then you need to copy only vmlinuz. It is no different from vmlinux, it is simply compressed to save space.)

For Slackware users: Also copy /vmlinuz file to the diskette, use command cp /vmlinuz /mnt.

Create a new file /mnt/lilo.conf in accordance with the following:

boot=/dev/fd0 # Install LILO on floppy disk.
map=/mnt/map # Location of “map file”.
install=/mnt/boot.b # File to copy to floppy’s
# boot sector.
prompt # LILO should show
# "LILO boot:"
timeout=50 # Boot default system after 5
# seconds. (Value is in tenth of
# of a second.)
image=/mnt/vmlinuz # Location of Linux kernel on floppy.
# Real name may include version number,
# for example,
# "vmlinuz-2.0.35".
label=linux # Name of Linux system.
root=/dev/hda1 # Location of root partition
# of the new hard disk. Modify it
# as appropriate for the new system.
# Note that you must use
# the name of the future location, once
# the old disk has been removed.
read-only # At first mount partitions read-only
# to run fsck.

Install LILO to boot diskette:

/sbin/lilo -C /mnt/lilo.conf

The -C option points to LILO which boot diskette to use:

Unmount the diskette:

umount /mnt

11. Remove the old disk

Shut down the system and remove the disk. Remember to modify the new disk settings and BIOS information.

12. Reboot the system, modify LILO configuration file

Reboot the system. Should you have any problems, use boot diskette that you have just made. To boot from it, just modify BIOS boot-up sequence to A:, C:.

You should modify the /etc/lilo.conf if you want to run LILO again later. Below is an example:

boot=/dev/hda # Install LILO on the first hard
# disk.
map=/boot/map # Location of "map file".
install=/boot/boot.b # File to copy to
# boot sector of the hard disk.
prompt # LILO should show
# "LILO boot:".
timeout=50 # Boot default system after 5
# seconds. (Value is in tenths
# of a second.)
image=/boot/vmlinuz # Location of Linux kernel. Real
# name may include a
# version number, for example,
# "vmlinuz-2.0.35".
label=linux # Name of Linux system.
root=/dev/hda1 # Location of root partition
# of the new hard disk. Modify
# it as approptiate for the new system.
read-only # At first mount partitions read-only
# to run fsck.

For Slackware users: Use image=/vmlinuz.

That's it. All done.

Last modified on Thursday, 21 May 2015 22:00
Data Recovery Expert

Viktor S., Ph.D. (Electrical/Computer Engineering), was hired by DataRecoup, the international data recovery corporation, in 2012. Promoted to Engineering Senior Manager in 2010 and then to his current position, as C.I.O. of DataRecoup, in 2014. Responsible for the management of critical, high-priority RAID data recovery cases and the application of his expert, comprehensive knowledge in database data retrieval. He is also responsible for planning and implementing SEO/SEM and other internet-based marketing strategies. Currently, Viktor S., Ph.D., is focusing on the further development and expansion of DataRecoup’s major internet marketing campaign for their already successful proprietary software application “Data Recovery for Windows” (an application which he developed).


  • Comment Link Lachlan Saturday, 03 March 2018 22:26 posted by Lachlan

    So we began looking into doggie daycare places.

  • Comment Link Summer Sunday, 25 February 2018 18:48 posted by Summer

    Arborists specialize in the care of individual timber.

  • Comment Link Brandie Friday, 23 February 2018 12:29 posted by Brandie

    The other type of base is the coarse asphalt base.

  • Comment Link Debbra Friday, 23 February 2018 01:21 posted by Debbra

    We additionally present service in downtown towing Miami.

  • Comment Link Britt Tuesday, 20 February 2018 08:46 posted by Britt

    Worldwide motor yacht brokerage specialists.

  • Comment Link Leta Wednesday, 07 February 2018 01:14 posted by Leta

    Hi, Neat post. There's an issue with your site in internet explorer, may test this?
    IE still is the marketplace leader and a good element of people
    will pass over your excellent writing because of this

  • Comment Link Claire Wednesday, 31 January 2018 07:16 posted by Claire

    Greetings from Florida! I'm bored to tears at work so I decided to check out your website on my iphone during lunch
    break. I really like the knowledge you present here and can't wait to take
    a look when I get home. I'm amazed at how quick your blog loaded on my phone ..
    I'm not even using WIFI, just 3G .. Anyways, good blog!

  • Comment Link Katherin Saturday, 06 January 2018 11:15 posted by Katherin

    Hey there! I've been reading your site for a long time now and finally got the
    courage to go ahead and give you a shout out from Kingwood Tx!
    Just wanted to tell you keep up the fantastic work!

  • Comment Link Tyson Friday, 15 December 2017 17:05 posted by Tyson

    You actually make it appear really easy along with your presentation but I in finding this matter to be really one thing that I
    feel I'd never understand. It seems too complicated and extremely vast for me.
    I'm looking ahead on your next submit, I'll attempt to get the hang of

  • Comment Link Leora Friday, 24 November 2017 18:07 posted by Leora

    Wonderful website. Plenty of useful information here.
    I am sending it to some buddies ans additionally
    sharing in delicious. And of course, thank you for your sweat!

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.