How to install a new hard drive and copy your Slackware install without loosing any data.

I have (had) Slackware installed on an 8.4gb Quantum Fireball and a 12.9gb Seagate, both drives were about two years old and I was running out of room, so it was time to do a hard drive upgrade. I chose a Seagate Barracuda IV 80gb 7200rpm ATA100 as my new drive and the following article details how I migrated my Slackware Linux 8.1 installation to the new drive without loosing any data or settings. Most of the information contained in this article is from the Hard-Disk-Upgrade Mini How-To, I strongly suggest you read this first but it was last updated in April 2000.

The first step is to install the new drive to a spare IDE controller, as I already had two hard drives, a DVD-ROM and CDRW I had to remove one of the optical drives first, I chose the CDRW. Note: Don't forget to set the drive jumpers.

After the installation you will need to partition and format the new drive, boot to runlevel 3, login as root and run cfdisk to create your partitions (Note: The How-To advises that you unmount all network drives and dos partitions at this stage), "cfdisk /dev/hd*" (where * is the location of your drive).

Format the partitions in your prefered filesystem, I use ReiserFS so the command is "mkreiserfs", if you use ext2/3 then "mkfs" is the command to use, to format your swap partition use the "mkswap" command (see the man pages for the full options).

Now we need to mount the new drive, the following is copied from Chapter 6 of the How-To and assumes you have chosen ext2 as your filesytem.


6. Mount the new disk


Create a directory where you'll mount the new disk, for example /new-disk, and mount it there:
mkdir /new-disk
mount -t ext2 /dev/hd** /new-disk

If the new disk will have more than one Linux partitions, mount them all under /new-disk with the same organization they'll have later.
Example. The new disk will have four Linux partitions, as follows: /dev/hd*1 /
/dev/hd*2 /home
/dev/hd*3 /var
/dev/hd*4 /var/spool

Mount the four partitions under /new-disk as follows:
/dev/hd*1 /new-disk
/dev/hd*2 /new-disk/home
/dev/hd*3 /new-disk/var
/dev/hd*4 /new-disk/var/spool

You must create the mount points for each level before you mount the partitions at that level.
Example.
mkdir /new-disk
mount -t ext2 /dev/hd*1 /new-disk [1st level]
mkdir /new-disk/home
mount -t ext2 /dev/hd*2 /new-disk/home [2nd level]
mkdir /new-disk/var
mount -t ext2 /dev/hd*3 /new-disk/var [2nd level also]
mkdir /new-disk/var/spool
mount -t ext2 /dev/hd*4 /new-disk/var/spool [3rd level]

If you've created a mount point at /new-disk/tmp, you'll need to correct the directory's permissions to let all users access it:
chmod 1777 /new-disk/tmp



In my case I had / on the quantum (/dev/hda1) and /home + swap were on the old seagate (/dev/hdb1 and /dev/hdb2), so I created two 20gb reiserfs partitions and a 512mb swap on the new drive, when I decide what to do with all the extra space I'll create the needed partitions out of the unallocated space (I may use some of the room for backups - but that will be another article:-)

mkdir /new-disk
mount -t reiserfs /dev/hdd1 /newdisk
mkdir /newdisk/home
mount -t reiserfs /dev/hdd2 /new-disk/home
After this my directory tree looked like the following,

/
/bin
/boot
/dev
/etc
/home
/lib
/mnt
/new-disk
/opt
/proc
/root
/sbin
/tmp
/usr
/var

The next step is the big one - copy the files to the new disk!
Change to single user mode before you go any further with "telinit 1", when we do the copy we want all directories and files (including links) but not /new-disk or the contents of /proc.
The How-To provides three methods for the copy operation, I used the third option, "cp -a".

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

You'll notice that I left out /proc and /new-disk, that's because /proc is a virtual filesystem and only contains information on the services running on the system, we create the proc directory after the cp command has completed, and we leave out /new-disk because otherwise this would copy it to itself.
Now go and make a cup, no make that a pot, of coffee, it's going to take a while to completely copy everything to the new drive.

After the operation has completed create the /proc directory,
"mkdir /new-disk/proc"

Next we need to edit /new-disk/etc/fstab to reflect how our new drive will look when it's connected to the primary master ide controller (/dev/hda), do "mcedit /new-disk/etc/fstab", and make the appropriate changes.

The next two chapters in the How-To deal with preparing lilo and making a boot floppy to boot the new drive, I skipped both of these chapters and went straight to chapter 11 of the How-To.


Chapter 11.


Remove the old disk(s). Shut down the system and remove the old disk(s). Remember to modify the disk jumpers and the BIOS information to reflect the changes.



On a modern system with the bios set to auto detect ide devices your new disk should appear without any changes needed from you, however it's a good idea to check the settings anyway.

Now we need to boot the new drive, turn on the power, go into your bios and make sure your new drive is detected correctly and that you are booting from you CD-ROM before your hard drive, reboot with your Slackware-8.1-install CD and when you get to the boot: prompt type "Linux root = /dev/hda1" (to boot Linux on the first partition of the primary master drive - change this to whatever is needed for your setup), login as root again and edit your /etc/lilo.conf or grub config (don't forget to run lilo after making changes to lilo.conf), and the job is finished.

You should now have your system running on your shiny new hard drive, for those that are interested here are the specs of my new drive (as provided by hdparm).

root@grendel /$ hdparm -tT /dev/hda
/dev/hda:
Timing buffer-cache reads: 128 MB in 0.80 seconds =160.00 MB/sec
Timing buffered disk reads: 64 MB in 1.97 seconds = 32.49 MB/sec

root@grendel /$ hdparm -i /dev/hda

/dev/hda:

Model=ST380021A, FwRev=3.19, SerialNo=3HV4050F
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
BuffType=unknown, BuffSize=2048kB, MaxMultSect=16, MultSect=1
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=156301488
IORDY=on/off, tPIO={min:240,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
AdvancedPM=no WriteCache=enabled
Drive conforms to: device does not report version: 1 2 3 4 5

root@grendel /$ hdparm /dev/hda

/dev/hda:
multcount = 1 (on)
IO_support = 3 (32-bit w/sync)
unmaskirq = 1 (on)
using_dma = 1 (on)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 8 (on)
geometry = 9729/255/63, sectors = 156301488, start = 0

Thanks go to Yves Bellefeuille and Konrad Hinsen for the original Hard-Drive-Upgrade Mini How-To.