hello!
as ovh announced new servers (i wrote about), i now want to move the gentoo installation as easily as possible. i hope this will help you save some work. however, i can not guarantee that the destination system works perfectly, run tests! the things i do during this task are not dangerous for your source server, except if you copy things in the wrong direction.
in the following examples 91.121.100.111 is the new and 91.121.100.222 is the old server.
first of all, the destination server has to be bootet in rescue mode. after this is done, we can copy the partition layout using sfdisk and netcat. as netcat is not included in the default rescue-sys by ovh, we have to copy it from the existing server;
-
scp /usr/bin/nc root@91.121.100.111:/
so we now have the netcat binary in / of the rescue on the new server. this step has to be re-done after each reboot, as the rescue-fs will be gone. next step is copying the partition scheme from the old to the new server. for this, two steps need to be taken; on the destination server:
-
/nc -l -p9000 | sfdisk -f /dev/sda
this makes netcat listen on port 9000. the data will be redirected to sfdisk, which will write to /dev/sda. on the source server (first stop all things that use your harddrive:
-
swapoff -a
-
mdadm –stop /dev/md?
-
sfdisk -d /dev/sda | nc 91.121.100.111 9000
then wait for 2 seconds and press CTRL-C. the destination server should output something like “writing partition schema”.
afterwards, you can check the partitions on the destination machine. next thing is to make swap partitions and enable them. they will probably not be used, but they also won’t harm;
-
mkswap /dev/sda2
-
mkswap /dev/sdb2
-
swapon /dev/sda2
-
swapon /dev/sdb2
of course you have to use your swap-partitions which are not always sda2 and sdb2
now that we have some swap, we need to create the raid arrays on the destination server the way they were on the source-machine. here, i’ll create two raid1 arrays (md0 and md1)
-
mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sda1 /dev/sdb1
-
mdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sda5 /dev/sdb5
-
mdadm –create /dev/md2 –level=1 –raid-devices=2 /dev/sda6 /dev/sdb6
-
mdadm –create /dev/md3 –level=0 –raid-devices=2 /dev/sda7 /dev/sdb7
-
mkefs /dev/md0
-
mkfs.xfs /dev/md1
-
mkfs.xfs /dev/md2
now your /proc/mdstat should look something like…
-
rescue:~# cat /proc/mdstat
-
Personalities : [linear] [raid0] [raid1] [raid6] [raid5] [raid4] [multipath]
-
md3 : active raid0 sdb7[1] sda7[0]
-
1293987328 blocks 64k chunks
-
-
md1 : active raid1 sdb5[1] sda5[0]
-
6843584 blocks [2/2] [UU]
-
-
md2 : active raid1 sdb6[1] sda6[0]
-
78132032 blocks [2/2] [UU]
-
[=>……………….] resync = 7.3% (5718656/78132032) finish=14.0min speed=86016K/sec
-
-
md0 : active raid1 sdb1[1] sda1[0]
-
104320 blocks [2/2] [UU]
as you can see, linux is still syncing the arrays. this however, does not stop us from doing anything _on_ the partition. now that we have our filesystem and raid-devices set up, we mount them so that we can transfer files later on.
-
rescue:~# mkdir /mnt/dest
-
rescue:~# mount /dev/md1 /mnt/dest/
-
rescue:~# mkdir /mnt/dest/boot
-
rescue:~# mount /dev/md0 /mnt/dest/boot/
if you have more devices that are important for you system, like seperate filesystems for /var, /opt, /tmp or /usr, you need to create and mount them also. as the filesystems are now mounted, we can start copying files.
-
rsync -azH –progress / –exclude /proc –exclude /sys –exclude /dev/ –exclude /var/lock/ –exclude /var/run/ –exclude /misc/ –exclude /crypt/ root@91.121.100.111:/mnt/dest/
please note that it is not safe to copy such files while the operating system is running! if it works, you’re lucky, but chances it won’t aren’t too bad. make sure all relevant fs’es (like /boot) are mounted on your source-server. this command will take some time (started it at 14:55, it ended not before 15:15), my system had around 300′000 files! maybe you want to do this in a screen, so you can detach it. my ssh connection alone took 150k/s transferring the list of all the files :p
after the copying is done, it is very important that the network configuration is customized, so that your new server won’t try to take the ip of your old one. you should also deactivate some services which you haven’t yet copied the data for. you also may want to create folders that were excluded in rsync.
-
nano /mnt/dest/etc/conf.d/net
-
mkdir /mnt/dest/misc
-
mkdir /mnt/dest/proc
-
mkdir /mnt/dest/sys
-
mkdir /mnt/dest/dev
-
mount -t proc none /mnt/dest/proc
-
mount -o bind /dev /mnt/dest/dev
-
chroot /mnt/dest /bin/bash
-
source /etc/profile && env-update
-
rc-update del apache2 default
-
rc-update del vmware default
with these steps done, grub needs to be configured and written to mbr
-
grub
-
root (hd0,0)
-
setup (hd0)
-
# same for the other device, if you use raid1
-
grub
-
root (hd1,0)
-
setup (hd0)
something i didn’t think about the first time:
-
nano /etc/udev/rules.d/70-persistent-net.rules
-
(remove the existing entry as it would cause your (new) nic to be renamed to eth1)
unmount all the drives etc
-
exit
-
umount /mnt/dest/proc /mnt/dest/boot /mnt/dest/dev /mnt/dest
as all the important steps are taken (hopefully), we’ll deactivate the rescue mode on the server, wait a minute and reboot it.
-
reboot
if it all works well, your server is online! you can now move data that you excluded in the rsync-step, move customers etc etc. as of now, i didn’t move the other services, but i don’t think there will be a problem with the server installation.

Trackback URI | Comments RSS
Leave a Reply