Migration of a Linux installation from a old to a new bigger disk.
Boot the CRK. Load modules for the storage and network controller
you need, as well the filesystem drivers you need :
[tinker:root]:(~)# lsmod
Module Size Used by Not tainted
ext3 64800 0
jbd 51432 0 [ext3]
aic7xxx 122136 0
e100 49932 1
[tinker:root]:(~)#
[tinker:root]:(~)# cd /etc/rc.d/init.d/
[tinker:root]:(/etc/rc.d/init.d)# ./network stop
[tinker:root]:(/etc/rc.d/init.d)# ./network start
[tinker:root]:(/etc/rc.d/init.d)# ping newton
PING newton (10.0.18.70): 56 data bytes
64 bytes from 10.0.18.70: icmp_seq=0 ttl=255 time=0.2 ms
64 bytes from 10.0.18.70: icmp_seq=1 ttl=255 time=0.1 ms
64 bytes from 10.0.18.70: icmp_seq=2 ttl=255 time=0.1 ms
--- newton ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.1/0.1/0.2 ms
[tinker:root]:(~)#
Newton here is the NFS backup server.
[tinker:root]:(~)# cd
[tinker:root]:(~)# mkdir /backup
[tinker:root]:(~)# portmap
[tinker:root]:(~)# mount -t nfs newton:/export/backup /backup
[tinker:root]:(~)# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram 11895 9027 2868 76% /
/dev/hda 58496 58496 0 100% /cdrom
newton:/export/backup
34770528 25523968 8898848 75% /backup
[tinker:root]:(~)#
/dev/sda is the new new drive in this example and /dev/sdb (i.e. /dev/sdb2
root (/) partition of Mandrake 9.1) is de drive/partition which has your
current Linux installation. /dev/sdc is my data disk, /dev/sdb3 is my /home.
Next we copy the raw partition image of /dev/sdb2 through gzip onto the NFS
Server newton :
[tinker:root]:(~)# fdisk -l
Disk /dev/sda: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2231 17920476 83 Linux
Disk /dev/sdb: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 33 265041 82 Linux swap
/dev/sdb2 * 34 1078 8393962+ 83 Linux
/dev/sdb3 1079 2231 9261472+ 83 Linux
Disk /dev/sdc: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 * 1 2231 17920476 83 Linux
[tinker:root]:(~)# dd if=/dev/sdb2 bs=20M | gzip -c > /backup/resize2fs/dd-sdb2.gz
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
We might as well have executed this command :
dd if=/dev/sdb2 of=/dev/sda2 bs=40M
But i always like to have a copy of my data outside the machine on some
remote server :) Next we get the destination disk clean. The following command
will do that for you:
[tinker:root]:(~)# dd if=/dev/zero of=/dev/sda bs=40M count=1
1+0 records in
1+0 records out
[tinker:root]:(~)#
This is very handy, cause it will wipe enough info from the entire drive,
that even Windows XP will forget it was even installed on the same
drive before. So the old serial-number on the label of your Windows-XP cdrom
can be used again. So it seems by zero-ing the first 40Mb of your disk
the hardware history database which windows XP builds up is erazed too.
However this is a wild guess, and not backed up by some real evidence.
So don't flame me if the above disk cleaning command stops working suitable
enough :)
Next we are going to create the new needed partitions on /dev/sda (the new
disk) :
[tinker:root]:(~)# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 2231.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sda: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2231, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2231, default 2231): +512M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap)
Command (m for help): p
Disk /dev/sda: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 63 506016 82 Linux swap
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (64-2231, default 64):
Using default value 64
Last cylinder or +size or +sizeM or +sizeK (64-2231, default 2231):
Using default value 2231
Command (m for help): a
Partition number (1-4): 2
Command (m for help): p
Disk /dev/sda: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 63 506016 82 Linux swap
/dev/sda2 * 64 2231 17414460 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
[tinker:root]:(~)#
Next dd the backup image of /dev/sdb2 onto disk sda i.e. /dev/sda2 :
[tinker:root]:(~)# cd /backup/resize2fs
[tinker:root]:(/backup/resize2fs)# ll
total 2098192
-rw-rw-r-- 1 root root 2147483647 Jul 28 01:57 dd-sdb2.gz
-rw-rw-r-- 1 root root 867 Jul 28 01:35 fdisk.jackson
[tinker:root]:(/backup/resize2fs)# mkswap /dev/sda1
Setting up swapspace version 1, size = 518156 kB
[tinker:root]:(/backup/resize2fs)# gzip -dc dd-sdb2.gz | dd of=/dev/sda2 bs=20M
[tinker:root]:(/backup/resize2fs)# cd
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
[tinker:root]:(~)# mount /dev/sda2 /mnt
[tinker:root]:(~)# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram 11895 9418 2477 80% /
/dev/hda 58496 58496 0 100% /cdrom
newton:/export/backup
34770528 27622176 6800640 81% /backup
/dev/sda2 8262068 3890324 3952048 50% /mnt
[tinker:root]:(~)# umount /mnt
[tinker:root]:(~)#
Next we need to force a fsck on /dev/sda2 for resize2fs to work. Apparently
it needs a fresh fsck.ext3 which stores some fsck fresh info onto /dev/sda2:
[tinker:root]:(~)# fsck.ext3 -y -f /dev/sda2
e2fsck 1.33 (21-Apr-2003)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda2: 224268/1050400 files (2.5% non-contiguous), 1005557/2098490 blocks
[tinker:root]:(~)#
[tinker:root]:(~)# resize2fs /dev/sda2
resize2fs 1.33 (21-Apr-2003)
The filesystem on /dev/sda2 is now 4353615 blocks long.
[tinker:root]:(~)#
[tinker:root]:(~)# mount /dev/sda2 /mnt
[tinker:root]:(~)# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ram 11895 9401 2494 80% /
/dev/hda 58496 58496 0 100% /cdrom
newton:/export/backup
34770528 25524000 8898848 75% /backup
/dev/sda2 17144604 3890336 12557692 24% /mnt
[tinker:root]:(~)#
Ok so now we use the complete partition size for /dev/sda2 .
Next edit /mnt/etc/fstab (adjust the used partition names) and
/mnt/etc/lilo.conf (again adjust the used partition names) after which we
activate lilo again:
[tinker:root]:(~)# cd /mnt
[tinker:root]:(/mnt)# /mnt/sbin/lilo -r /mnt
Added linux *
Added linux-custom
Added failsafe
Added floppy
[tinker:root]:(/mnt)# cd
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
[tinker:root]:(~)# sync
[tinker:root]:(~)# umount /mnt
[tinker:root]:(~)# umount /backup
[tinker:root]:(~)# umount /cdrom
[tinker:root]:(~)# shutdown -r now
The distro we moved to the new disk in this example is Mandrake 9.1.
CrashRecoveryKit v2.4.21 and v2.4.21-ntfs which are based on RedHat 9 can also
be used on Mandrake 9.1.
Robert M. Stockmann stock@stokkie.net
Last changed Mon Jul 28 18:45:37 CEST 2003