Richard van Dijk's picture

TransIP is hosting my TurnKey Linux VPSs, and they do a very good job. Unfortunately, they chose to no longer offer TurnKey Linux images for easy install on their VPS platform. Also, they don't enable you to upload your own ISO or raw image. This will likely be the same at most other VPS hosters. In this post I'd like to share how you can work around these limitations, and to install TurnKey Linux on such a VPS. This should work on any VPS provider that is using KVM for virtualization (Xen will likely also work).

What it comes down to is that you create a Linux VPS whose boot disk will be overwritten by the raw TurnKey Linux image that you will create on a second temporary VPS.

Strictly speaking, this temporary VPS is not even necessary, but it'll make the process of transferring (streaming) the raw image go a lot faster and more reliable. And in case of TransIP the temporary VPS will only cost you €5 extra if you cancel it within a month. Here are the steps:

  1. create a new Linux VPS and install Debian 8 on it (single partition, without Desktop Environment)
  2. reboot
  3. while in the Grub boot menu, press 'e' to edit the boot parameters
  4. add ' S' or ' Single' to the end of the line that starts with 'linux /boot/vmlinuz...'
  5. press Ctrl-x to boot with your modified boot line
  6. single user mode will be started, enter your root password to log in
  7. (if necessary) turn on networking by entering: dhclient eth0
  8. apt-get install netcat
  9. killall dhclient
  10. mount -o ro,remount /
    • the root filesystem has been remounted readonly
  11. netcat -l -p 4000 | dd bs=16M of=/dev/vda
    • netcat listens for TCP connections on port 4000, piping any incoming data to dd, which will write everything (in chunks of 16 MiByte) to the boot disk of your VPS!
    • Note: /dev/vda is my boot device, it could also be /dev/hda or /dev/sda for example, check fdisk -l to be sure

Now we need to get a raw TurnKey Linux image, and stream it to our Linux VPS. The example below is for the TKL 14.1 Lamp image, but you can use any image from www.turnkeylinux.org, as long as you use the VMDK direct download link.

  1. create a new Linux VPS (at least 30 GiB big), install Debian 8 on it, and log in as root
  2. apt-get install netcat qemu
  3. wget http://mirror.turnkeylinux.org/turnkeylinux/images/vmdk/turnkey-lamp-14....
    • ​replace the above URL by the VMDK download link of the TKL image you want to install
    • if you use a different image, then change the directory and file names below accordingly
  4. unzip turnkey-lamp-14.1-jessie-amd64-vmdk.zip
  5. cd turnkey-lamp-14.1-jessie-amd64
  6. qemu-img convert -f vmdk turnkey-lamp-14.1-jessie-amd64.vmdk -O raw turnkey-lamp-14.1-jessie-amd64.raw
  7. dd bs=16M if=turnkey-lamp-14.1-jessie-amd64.raw | nc 123.123.123.123 4000
    • ​replace 123.123.123.123 by the IP-adress of the VPS that has netcat listening for connections
  8. ​now wait and don't touch anything, after a (long) while a summary similar to the one below should show:
    • 1280+0 records in
    • 1280+0 records out
    • 21474836480 bytes (21 GB) copied, 224.587 s, 95.6 MB/s
  9. once you have seen this summary, cloning is complete

Return to the console of the target machine (that is the VPS that you first installed, the one that is listening for connections):

  1. press Ctrl-c
  2. stop and start the VPS
  3. enjoy TurnKey Linux!

Chances are that your boot disk is bigger than 20 GiB, in that case you may want to increase the swap size from 512 MiB to 4 GiB, and resize the root partition to use all remaining space. Here's one way to achieve that (assuming that /dev/vda is your boot device and the second partition starts at sector 1001953, check fdisk -l to be sure):

  1. ​fdisk /dev/vda
    • ​in fdisk, enter the following commands:
    • d 2 (meaning: delete partition 2)
    • n p 2 1001953 default (meaning: add new primary partition 2, occupying all remaining space, where I wrote 'default' you should just press enter to accept the default)
    • t 2 8e (meaning: change back the type of partition 2 to 'Linux LVM')
    • w (meaning: write the new partition table to disk)
  2. reboot to make the kernel use the new partition table
  3. pvresize /dev/vda2
  4. lvresize --size 4G turnkey/swap_1
  5. swapoff -a
  6. mkswap /dev/turnkey/swap_1
  7. swapon -a
  8. lvresize -l +100%FREE turnkey/root
  9. resize2fs /dev/turnkey/root

Hope this helps!

-- Richard

Forum: 
Jeremy Davis's picture

I'm sure that this will be helpful for many users.

Also it's interesting to hear that they are no longer providing TurnKey appliances. I'll have to get in touch with them and ask about that. Thanks for the heads up.

Sjoerd's picture

Not so much for getting turnkey on my VPS, but in general an idea to use when the VPS provider isn't providing the image you want or when you want to prepare the whole VPS locally before putting it on your VPS in the cloud :)

Add new comment