Linode Library Home
Linode Library RSS Feed
Home :: Migration
Print View View Source

Migrating a Server to Your Linode

Published: by

You can migrate an existing server to your Linode from another hosting provider or a local machine. This is a great option if you're moving to Linode from another hosting provider or if you've built a custom server on your local machine. You can even migrate virtualized servers created with products like VirtualBox or VMware. This guide shows you how to prepare the Linode to receive the files, copy the files from the existing server to the Linode, and then make the disk images bootable.

Note

These instructions assume that you'll be working with a live server. If you can boot into an alternate environment, such as a live CD, you should do so. However, most hosting providers do not offer a bootable recovery or maintenance environment.

Contents

Preparing the Linode

First you'll need to prepare the Linode to receive the files from the existing server. Create disk images to store the files on the existing server and a configuration profile to boot the Linode from the existing server's disk images. Then start the Linode in rescue mode.

Creating Disk Images

Create two disk images: one for the files on your existing server, and another for a swap disk. That way, the import from the existing server will be bootable. Here's how to create the disk images:

Note

We assume that your existing server has a single root partition. If you have multiple partitions set up, you'll need to add extra disk images to accommodate each partition.

  1. Log in to the Linode Manager.
  2. Click the Linodes tab. A list of your virtual private servers appears.
  3. Select a Linode. The Linode's dashboard appears.
  4. Create a disk image to hold the files from the existing server. Select Create a new Disk Image. The webpage shown below appears.
Creating a disk image
  1. Enter a descriptive name for the disk image in the Label field.
  2. Enter a size for the disk image in the Size field. You should make the disk image large enough to hold the contents of your current server's root partition.
  3. Click Save Changes to create the disk image. The Linode's dashboard appears. You can monitor the disk image creation process by watching the Host Job Queue.
  4. Now create a swap disk for your existing server. Select Create a new Disk Image. The webpage shown below appears.
Creating a disk image
  1. Enter a name for the swap disk in the Label field.
  2. From the Type menu, select swap.
  3. Enter 256 in the Size field.
  4. Click Save Changes to create the swap disk image.

You have successfully created the disk images.

Creating a Configuration Profile

You'll need a configuration profile to boot your existing server after you upload the files. Here's how to create the configuration profile:

  1. In the Linode Manager, select the Linode's dashboard.
  2. Select Create a new Configuration Profile. The webpage shown below appears.
Creating a configuration profile
  1. Enter a name for the configuration profile in the Label field.
  2. Optional: Enter notes for the configuration profile in the Notes field.

Note

Make sure that you select the correct kernel for your existing server. There are 32-bit and 64-bit versions available. The 64-bit version has x86_64 in the name.

  1. Set /dev/xvda to the primary disk image you created for the existing server.
  2. Set /dev/xvdb to the swap image you created for the existing server.
  3. Click Save Changes.

You have successfully created the configuration profile.

Booting into Rescue Mode

Before you initiate the transfer, you need to start the Linode in rescue mode. Here's how:

  1. Boot your Linode into Rescue Mode. For instructions, see Booting into Rescue Mode. Be sure to set the primary disk image to /dev/xvda and the swap image to /dev/xvdb.

  2. After the Linode has booted, connect to it via LISH. For instructions, see Connecting to a Linode Running in rescue mode.

  3. Start SSH. For instructions, see Start SSH.

  4. Mount the blank primary disk image by entering the following command:

    mount -o barrier=0 /dev/xvda
    

Your Linode is now ready to receive the files from your existing server.

Copying the Files

You've created disk images on the Linode to receive the files from the existing server, and you've created configuration profiles to boot into rescue mode and from the new disk images. Now it's time to transfer files from the existing server to the Linode.

Stopping Services

At this point, you should stop as many services as possible on the existing server. This includes web server daemons (Apache and nginx), database servers (PostgreSQL and MySQL), and any other non-critical services. To stop a service, enter the following command, replacing apache2 with the name of the service you want to stop:

sudo service apache2 stop

Initiating the Transfer

Now it's time to copy the files from your existing server to your Linode. Here's how:

  1. Connect to your existing server via SSH and log in as root.

  2. Enter the following command to initiate the copy, replacing 123.45.67.890 with your Linode's IP address. (For instructions on finding your Linode's IP address, see Finding the IP Address.)

    rsync --exclude="/sys/*" --exclude="/proc/*" -aHSKDvz -e ssh / root@123.45.67.890:/media/xvda/
    

Note

If you receive a message indicating that the rsync command couldn't be found, you'll need to install it by entering apt-get install rsync on Ubuntu or Debian. If you're using a different distribution, you may need to enter a different command.

The files on your existing server will be copied to your Linode. Depending on the amount of data stored on existing server, the network copy may take a long time. You can monitor the progress from your current server's SSH session.

Configuring the Disk Images

Now the files from your existing server are stored on your Linode. You can't boot from the new disk images yet, however. First, you'll need to do some things to the disk images, like set the IP address to the IP address assigned to your Linode. Be sure to follow all of the instructions in this section before restarting your Linode from the new disk images!

Setting the IP Address

After the network copy is complete and the files from the existing server have been moved in to the disk images, you'll need to update the existing server's IP address with your Linode's IP address. Here's how:

  1. On the Linode, which should still be running in rescue mode, enter the following command to change directories:

    cd /media/xvda
    
  2. Now enter the following command to replace all instances of your old IP address. Be sure to replace all instances of the old IP address with the new IP address. In this example, 98\\.76\\.54\\.32 is the old IP address and 12\\.34\\.56\\.78 is the Linode's IP address:

    find ./ -type f -exec sed -i 's/98\.76\.54\.32/12\.34\.56\.78/' {} \;
    

The entire mounted filesystem will be recursively searched for any instances of your old IP address. Note that this replacement operation can take a while to complete.

Configuring Mount Points

Now you should configure mount points for the new disk images. Here's how:

  1. On the Linode, open the /media/xvda/etc/fstab file for editing by entering the following command:

    nano /media/xvda/etc/fstab
    
  2. Change the mount point for root to /dev/xvda, and the mount and swap to /dev/xvdb, as shown below:

File excerpt:/media/xvda/etc/fstab

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/xvda       /               ext3    errors=remount-ro 0       1
/dev/xvdb       none            swap    sw              0       0
proc            /proc           proc    defaults        0       0

You have successfully configured the mount points for the disk images.

Configuring Device Nodes via Chroot

Verify that /media/xvda/dev is complete by making sure that all of the device node entries listed below are present. If they aren't, you'll need to chroot to the mount point and execute the MAKEDEV command. Here's how:

  1. Chroot to the mount point by entering the following command:

    chroot /media/xvda /bin/bash
    
  2. Enter the following command:

    MAKEDEV /dev
    
  3. If necessary, manually create xvd[a-h] device node entries by entering the following commands:

    cd /dev
    mknod xvda b 202 0
    mknod xvdb b 202 16
    mknod xvdc b 202 32
    mknod xvdd b 202 48
    mknod xvde b 202 64
    mknod xvdf b 202 80
    mknod xvdg b 202 96
    mknod xvdh b 202 112
    
  4. If /dev/hvc0 doesn't exist, enter the following command:

    mknod hvc0 c 229 0
    
  5. Exit chroot by entering the following command:

    exit
    

You have successfully configured device nodes via chroot.

Fixing Persistent Rules

Here's how to fix persistent rules:

  1. If your distribution is using udev (most distributions are these days), enter the following command on the Linode:

    cd /media/xvda/etc/udev/rules.d
    
  2. Open the file that creates the persistent network rules, which is usually 75-persistent-net-generator.rules, by entering the following command:

    nano 75-persistent-net-generator.rules
    
  3. Modify the file to remove eth* from the beginning of the kernel whitelist so that it does not create persistent rules for eth*. In this case we simply removed eth* from the beginning of the kernel whitelist. The relevant section in the file should resemble the following:

    File excerpt:udev network rules

    # device name whitelist
    KERNEL!="ath*|wlan*[0-9]|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
    GOTO="persistent_net_generator_end"
    
  4. Remove any rules that were auto generated by entering the following command:

    rm /media/xvda/etc/udev/rules.d/70-persistent-net.rules
    
  5. Remove the cd rules file by entering the following command:

    rm /media/xvda/etc/udev/rules.d/70-persistent-cd.rules
    

You have successfully fixed persistent rules.

Booting the Linode with the New Disk Images

Now it's time to boot your Linode from the new disk images. All you have to do is select the new configuration profile you created and then restart the Linode. Here's how:

  1. Log in to the Linode Manager.
  2. Click the Linodes tab. A list of your virtual private servers appears.
  3. Select a Linode. The Linode's dashboard appears.
  4. Select the configuration profile you created earlier, as shown below.
Selecting the configuration profile
  1. Click Reboot to restart your Linode with the configuration profile and disk images you just created.

The Linode will start with the disk images you imported.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Matthew Cone on Wednesday, December 26th, 2012 (r3272).