This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | manuals:vps:kvm [2023/07/31 14:56] – Update for vpsAdminOS, remove old/incompatible distros Aither | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using KVM on vpsFree.cz | ||
+ | VPS are [[information: | ||
+ | which is shared between all VPS. In case you need your own kernel or if you'd like to use a different | ||
+ | operating system, you can create your own virtual machines inside the VPS using QEMU/KVM. | ||
+ | ===== Configuration ===== | ||
+ | |||
+ | Go to the details of your VPS in vpsAdmin and turn on the following features: | ||
+ | |||
+ | * TUN/TAP – enables the creation of virtual interfaces, | ||
+ | * KVM – enables KVM (for hardware support of virtualization). | ||
+ | |||
+ | ===== libvirt ===== | ||
+ | Virtual machines can be managed using [[https:// | ||
+ | with [[https:// | ||
+ | |||
+ | ===== KVM on Alpine Linux ===== | ||
+ | |||
+ | Install the required packages (ip6tables is optional): | ||
+ | |||
+ | <code shell> | ||
+ | apk update | ||
+ | apk add qemu-system-x86_64 qemu-openrc qemu-img bridge iptables ip6tables | ||
+ | </ | ||
+ | |||
+ | Configure the bridge for Qemu/KVM virtual machines – create the /// | ||
+ | |||
+ | <code shell> | ||
+ | auto br0 | ||
+ | iface br0 inet static | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Since OpenVZ rewrites the /// | ||
+ | |||
+ | Give the user in the //qemu// group permissions to manage the newly-created bridge: | ||
+ | |||
+ | <code shell> | ||
+ | echo "allow br0" > / | ||
+ | chown root:qemu / | ||
+ | chmod 0640 / | ||
+ | </ | ||
+ | |||
+ | Configure the IP masquerade so that the Qemu/KVM virtual machines have access to the public Internet. | ||
+ | |||
+ | If you have configured iptables, all you need to add is this rule: | ||
+ | |||
+ | < | ||
+ | iptables -t nat -A POSTROUTING -s 172.17.1.0/ | ||
+ | </ | ||
+ | |||
+ | If not, you can follow our paragraph on [[# | ||
+ | |||
+ | |||
+ | ==== Creating and Running a Virtual Machine ==== | ||
+ | |||
+ | This manual presupposes that you will be using [[https:// | ||
+ | |||
+ | Creating a new virtual machine consists only of preparing an image disk, creating a symlink for the init script and modifying a simple configuration script. Let’s say that the new virtual machine is called “myvirt.” | ||
+ | |||
+ | Prepare a raw image for myvirt with the required size: | ||
+ | |||
+ | <code shell> | ||
+ | mkdir -p / | ||
+ | qemu-img create -f raw / | ||
+ | chown qemu:qemu / | ||
+ | chmod 0600 / | ||
+ | </ | ||
+ | |||
+ | Copy the default configuration file / | ||
+ | |||
+ | <code shell> | ||
+ | cd /etc/conf.d | ||
+ | cp qemu qemu.jarvis | ||
+ | vi qemu.jarvis | ||
+ | </ | ||
+ | |||
+ | Most importantly, | ||
+ | |||
+ | <code shell> | ||
+ | disk1_file="/ | ||
+ | disk1_format=" | ||
+ | </ | ||
+ | |||
+ | You will probably also need to add the installation CD of a distribution that you have already downloaded: | ||
+ | |||
+ | <code shell> | ||
+ | cdrom0_file="/ | ||
+ | </ | ||
+ | |||
+ | Create a symlink for the init script and run myvirt. | ||
+ | |||
+ | <code shell> | ||
+ | cd /etc/init.d | ||
+ | ln -s qemu qemu.myvirt | ||
+ | |||
+ | rc-service qemu.myvirt start | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Configuring iptables ==== | ||
+ | |||
+ | If you aren’t using any tool to generate iptables rules (like e.g. [[https:// | ||
+ | |||
+ | Download the modified rule template with the added masquerade for our bridge to / | ||
+ | |||
+ | <code shell> | ||
+ | rmdir / | ||
+ | wget -O / | ||
+ | </ | ||
+ | |||
+ | Modify the / | ||
+ | |||
+ | <code shell> | ||
+ | # / | ||
+ | |||
+ | IPTABLES_SAVE="/ | ||
+ | # | ||
+ | SAVE_ON_STOP=" | ||
+ | IPFORWARD=" | ||
+ | </ | ||
+ | |||
+ | …and the / | ||
+ | |||
+ | <code shell> | ||
+ | # / | ||
+ | |||
+ | IP6TABLES_SAVE="/ | ||
+ | SAVE_RESTORE_OPTIONS=" | ||
+ | SAVE_ON_STOP=" | ||
+ | IPFORWARD=" | ||
+ | </ | ||
+ | |||
+ | Run iptables and ip6tables and add them to the runlevel boot: | ||
+ | |||
+ | <code shell> | ||
+ | rc-service iptables start | ||
+ | rc-service ip6tables start | ||
+ | rc-update add iptables boot | ||
+ | rc-update add ip6tables boot | ||
+ | </ | ||
+ | |||
+ | ==== Contacts ==== | ||
+ | |||
+ | * [[jakub@jirutka.cz|Jakub Jirůtka]] (on [[irc:// |