Question

How to extract an existing root filesystem into a droplet?

Posted October 1, 2014 4.1k 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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
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.

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

Submit an Answer