shkitch
By:
shkitch

How to extract an existing root filesystem into a droplet?

October 1, 2014 1.7k views

Hello,

I have an existing (physical) linux server that I'd like to migrate (virtualize) into a droplet. Since the server contains lots of services (mail, webmail, etc) I'd like to make this migration process as easy/fast as possible. Or in other words: I don't want to migrate service-by-service.

When moving from one physical server to another, I used to do it this way:

  • boot both servers with SystemRescueCD
  • make a targz archive of the whole root filesystem on the source server
  • make filesystems on the destination server
  • transfer the archive from source to destination server, extract it there
  • make some adjustments on the destination server (/etc/fstab, /boot/grub/menu.lst, /etc/udev/rules.d/70-persistent-net.rules, and the like) to reflect the new hardware
  • reboot the destination server while keeping my fingers crossed ;-)

Can something similar be done with Droplets, too? I'm guessing that just extracting the rootfs archive on a working Droplet spells disaster, right?

Bottom line: what is the suggested/preferred way to do this?

1 comment
  • Ok,

    I'll just answer this for myself.

    • I ssh'd into the droplet and made a /rootfs directory. There be all the important filez.

    • I targz'd the (stock) droplet root filesystem (without the kernel mountpoints such as /dev, /proc, /sys) and stored the targz archive under /rootfs/stock-droplet.tgz

    • then, I extracted /rootfs/stock-droplet.tgz archive to /rootfs/stock-droplet. You'll see why.

    • I made a targz archive of the source server filesystem, transferred it to the droplet (to /rootfs/source-server.tgz), and extracted it to /rootfs/source-server. You'll see why.

    • then, I booted the droplet with the recovery kernel. Instructions on how to do this are here: https://www.digitalocean.com/community/tutorials/how-to-recover-from-file-system-corruption-using-fsck-and-a-recovery-iso

    • "mkdir /target"

    • I mounted the droplet's root filesystem from the recovery kernel (initramfs) under /target. Instructions on how to do this are given in the link above, too. Note that the extracting in the previos steps is mandatory because the recovery initramfs image doesn't have neither tar nor gzip!

    • then, I removed pretty much everything from the targets's root filesystem (rm -rf /target/{usr,lib*,bin,sbin,etc} ...), leaving only th stuff in /target/boot, some empty mountpoints such as /target/{tmp,run,dev,proc,sys}, and of course /target/root and /target/rootfs

    • I copied the important stuff from the source server's root filesystem to the target root filesystem (e.g. "/target/rootfs/source-server/bin/cp -av /rootfs/source-server/{bin,sbin,usr,var,lib*} /target")

    • I copied a few configuration files back from the stock droplet's root filesystem to the new droplet's root filesystem ("/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/networking/interfaces /target/etc/networking", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/fstab /target/etc", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/udev/rules.d/* /target/etc/udev/rules.d" )

    • umount /target, reboot

    • rejoice!

    ... hope this works for somebody else, too.

    by Justin Ellingwood
    Linux includes a filesystem checking utility called fsck that can be used to recover your system in cases of corruption. In this guide, we will discuss how to attempt to recover your filesystem if there are filesystem issues by using the fsck kernel and a recovery ISO.
2 Answers

This question was answered by @shkitch:

Ok,

I'll just answer this for myself.

  • I ssh'd into the droplet and made a /rootfs directory. There be all the important filez.

  • I targz'd the (stock) droplet root filesystem (without the kernel mountpoints such as /dev, /proc, /sys) and stored the targz archive under /rootfs/stock-droplet.tgz

  • then, I extracted /rootfs/stock-droplet.tgz archive to /rootfs/stock-droplet. You'll see why.

  • I made a targz archive of the source server filesystem, transferred it to the droplet (to /rootfs/source-server.tgz), and extracted it to /rootfs/source-server. You'll see why.

  • then, I booted the droplet with the recovery kernel. Instructions on how to do this are here: https://www.digitalocean.com/community/tutorials/how-to-recover-from-file-system-corruption-using-fsck-and-a-recovery-iso

  • "mkdir /target"

  • I mounted the droplet's root filesystem from the recovery kernel (initramfs) under /target. Instructions on how to do this are given in the link above, too. Note that the extracting in the previos steps is mandatory because the recovery initramfs image doesn't have neither tar nor gzip!

  • then, I removed pretty much everything from the targets's root filesystem (rm -rf /target/{usr,lib*,bin,sbin,etc} ...), leaving only th stuff in /target/boot, some empty mountpoints such as /target/{tmp,run,dev,proc,sys}, and of course /target/root and /target/rootfs

  • I copied the important stuff from the source server's root filesystem to the target root filesystem (e.g. "/target/rootfs/source-server/bin/cp -av /rootfs/source-server/{bin,sbin,usr,var,lib*} /target")

  • I copied a few configuration files back from the stock droplet's root filesystem to the new droplet's root filesystem ("/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/networking/interfaces /target/etc/networking", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/fstab /target/etc", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/udev/rules.d/* /target/etc/udev/rules.d" )

  • umount /target, reboot

  • rejoice!

... hope this works for somebody else, too.

You can see the comment here.

by Justin Ellingwood
Linux includes a filesystem checking utility called fsck that can be used to recover your system in cases of corruption. In this guide, we will discuss how to attempt to recover your filesystem if there are filesystem issues by using the fsck kernel and a recovery ISO.

This question was answered by @shkitch:

Ok,

I'll just answer this for myself.

  • I ssh'd into the droplet and made a /rootfs directory. There be all the important filez.

  • I targz'd the (stock) droplet root filesystem (without the kernel mountpoints such as /dev, /proc, /sys) and stored the targz archive under /rootfs/stock-droplet.tgz

  • then, I extracted /rootfs/stock-droplet.tgz archive to /rootfs/stock-droplet. You'll see why.

  • I made a targz archive of the source server filesystem, transferred it to the droplet (to /rootfs/source-server.tgz), and extracted it to /rootfs/source-server. You'll see why.

  • then, I booted the droplet with the recovery kernel. Instructions on how to do this are here: https://www.digitalocean.com/community/tutorials/how-to-recover-from-file-system-corruption-using-fsck-and-a-recovery-iso

  • "mkdir /target"

  • I mounted the droplet's root filesystem from the recovery kernel (initramfs) under /target. Instructions on how to do this are given in the link above, too. Note that the extracting in the previos steps is mandatory because the recovery initramfs image doesn't have neither tar nor gzip!

  • then, I removed pretty much everything from the targets's root filesystem (rm -rf /target/{usr,lib*,bin,sbin,etc} ...), leaving only th stuff in /target/boot, some empty mountpoints such as /target/{tmp,run,dev,proc,sys}, and of course /target/root and /target/rootfs

  • I copied the important stuff from the source server's root filesystem to the target root filesystem (e.g. "/target/rootfs/source-server/bin/cp -av /rootfs/source-server/{bin,sbin,usr,var,lib*} /target")

  • I copied a few configuration files back from the stock droplet's root filesystem to the new droplet's root filesystem ("/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/networking/interfaces /target/etc/networking", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/fstab /target/etc", "/target/rootfs/source-server/bin/cp -av /target/rootfs/stock-droplet/etc/udev/rules.d/* /target/etc/udev/rules.d" )

  • umount /target, reboot

  • rejoice!

... hope this works for somebody else, too.

View the original comment

by Justin Ellingwood
Linux includes a filesystem checking utility called fsck that can be used to recover your system in cases of corruption. In this guide, we will discuss how to attempt to recover your filesystem if there are filesystem issues by using the fsck kernel and a recovery ISO.
Have another answer? Share your knowledge.