Nethence Newdoc Olddoc Lab Your IP BBDock  

Warning: those guides are mostly obsolete, please have a look at the new documentation.


Migrating and re-building Linux systems (P2V) with cpio
On the source server
On the source server, check out the mount points and finely select only the needed folders from the root directory,
df -h
cd /
ls -1
Proceed with the system live backup,
unalias ls
folders=`ls -1 | egrep -v '^mnt_srvinstall|^net|^proc|^sys'`
time find $folders -depth | grep -v lost+found | cpio -o > /mnt_srvinstall/$srvname.rootdir.cpio
unset folders
Write down the number of blocks that have been copied.
On the destination server
Create the virtual machine with same hardware attributes, but disable the network at power on. Start the emtpy VM, load the SystemRescueCD image and enable networking for this run.
Once SystemRescueCD has started on the destination server, eventually access it remotely,
passwd root
You can now connect remotely as root.
Then look for available disks,
fdisk -l
Create partitions on the system disk (at least / and a swap partition and eventually a first one for /boot),
cfdisk /dev/sda
Create /dev/sda1 for /
Create /dev/sda2 for swap
Make /dev/sda2 type swap
Make /dev/sda1 bootable
Format the partitions and swap,
mke2fs -I 128 /dev/sda1
mkfs.ext3 /dev/sda2
mkswap /dev/sda3
Note. not using ext4 because of an error when initramfs is trying to load ext, see troubleshooting.
Note. using inode size 128 otherwise we get a error at grub-install, see troubleshooting.
Mount the filesystems,
mount /dev/sda2 /mnt/
mkdir -p /mnt/boot/
mount /dev/sda1 /mnt/boot/
Restore the archive on the new server,
mkdir -p /mnt_srvinstall/
mount -t nfs4 srvinstall:/var/ftp /mnt_srvinstall/
cd /mnt/
time cpio -id < /mnt_srvinstall/$srvname.rootdir.cpio
Check that the number of blocks corresponds.
Create the folders that have been excluded,
mkdir -p net/ proc/ sys/
Check the time on the lost+found folder -- it should be the new one the local file system and not the one from the cpio archive (this has been taken care of at archive's creation stage anyway),
find . -type d | grep lost+found
ls -ld ./lost+found
Enter the freaking chroot,
mount -o bind /proc /mnt/proc
mount -o bind /dev /mnt/dev
chroot /mnt/ /bin/bash
Reinstall GRUB (fstab and initrd can be fixed afterwards),
grub-install /dev/sda
Edit the fstab,
cd /etc/
cp fstab fstab.beforep2v
vi fstab
proc /proc proc defaults 0 0
/dev/sda1 /boot ext2 defaults 1 2
/dev/sda2 / ext3 defaults 1 1
/dev/sda3 none swap sw 0 0
/dev/cdrom /media/cdrom0 udf,iso9660 user,noauto 0 0
#srvinstall:/var/ftp /mnt_srvinstall nfs4 defaults 0 0
note. also the cdrom device has been tuned.
get rid of the old mtab TODO CHECK CREATED,
mv mtab mtab.beforep2v
Rebuild the initramfs,
mkdir -p ~/.trash/
ls -l /boot/vmlinuz*
mv -f /boot/initrd* ~/.trash/
update-initramfs -c -k 2.6.26-2-686
Note. no need to re-update grub after that.
Fix the (old) GRUB configuration,
cd /boot/grub/
cp menu.lst menu.lst.beforep2v
vi menu.lst
Remove the old kernels from the list
Fix the kernel and initrd path (remove /boot)
Fix the rootdir path (switch to /dev/sda2)
for example as a result,
title Debian GNU/Linux, kernel 2.6.26-2-686
root (hd0,0)
kernel /vmlinuz-2.6.26-2-686 root=/dev/sda2 ro
initrd /initrd.img-2.6.26-2-686
title Debian GNU/Linux, kernel 2.6.26-2-686 (recovery mode)
root (hd0,0)
kernel /vmlinuz-2.6.26-2-686 root=/dev/sda2 ro single
initrd /initrd.img-2.6.26-2-686
Ready to reboot, but make sure you disable network first,
umount /mnt_srvinstall/
shutdown -r now
An alternate way to re-install grub on the device,
root (hd0,0)
setup (hd0)
If you need to re-install the grub package itself,
#apt-get install --reinstall grub
If you get this error message at grub-install stage,
The file /boot/grub/stage1 not read correctly.
==> use inode size 128 on the boot partition.
At startup even before grub loads the system, if you get this error,
Error 15: File not found
==> fix menu.lst or the menu at boot time to get rid of /boot
At startup at initramfs stage, if you get this error,
mount: mountint /dev/ on /root/dev failed: No such file or directory
==> make sure the root= argument points to the right partition in menu.lst or the grub menu
At startup at initramfs stage, if you get this error,
ext3-fs couldn't mount because of unsupported optional features (240)
==> As a workaround I used ext3 for the root device instead of ext4. I tried to add rootfstype=ext4 to the boot options but that did not work.

(obsolete, see the new doc)