Ubuntu 14.04 : use KVM within a container
Клонировать контейнер
# lxc-clone -o trusty_lxc -n kvm_lxc
# nano /var/lib/lxc/kvm_lxc/rootfs/etc/hosts
127.0.0.1 localhost
127.0.0.1 kvm_lxc
Сохранить.
# nano /var/lib/lxc/kvm_lxc/rootfs/etc/rc.local
mkdir -p /dev/net || true
mknod /dev/net/tun c 10 200
chmod 666 /dev/net/tun
mkdir -p /dev/kvm || true
mknod /dev/kvm c 10 232
exit 0
Сохранить
# nano /var/lib/lxc/kvm_lxc/config
## for openvpn
lxc.cgroup.devices.allow = b 7:* rwm
lxc.cgroup.devices.allow = c 10:200 rwm
lxc.cgroup.devices.allow = c 10:232 rwm
Сохранить.
.
Старт контейнера
# lxc-start -n kvm_lxc -d
# lxc-ls -f
# ssh ubuntu@kvm_lxc
# apt-get update
# apt-get install bridge-utils
# nano /etc/network/interfaces
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 0
Сохранить
# reboot
# lxc-start -n xrdp_lxc -d
# apt-get -y install -y lxc bridge-utils debootstrap libcap-dev cgroup-bin libpam-systemd
Созадать контейнер:
!!!# lxc-create -t ubuntu -n precise_lxc -- -r precise -a amd64
# lxc-create -t ubuntu -n trusty_2lxc -- -r trusty -a amd64
!##
!# The default user is 'ubuntu' with password 'ubuntu'!
!# Use the 'sudo' command to run tasks as root in the container.
!##
Сохранение контейнера trusty_2lxc :
# cd /var/lib/lxc/
Перестаем бояться виртуализации при помощи KVM
sudo apt-get update
sudo apt-get install qemu-kvm libvirt-bin virtinst
# wget http://mirror.yandex.ru/ubuntu-releases/14.04.5/ubuntu-14.04.5-server-amd64.iso
sudo kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
sudo virt-install \
--virt-type=kvm \
--name trusty \
--ram 1024 \
--vcpus=1 \
--os-variant=trusty \
--hvm \
--cdrom=/var/lib/libvirt/boot/ubuntu-14.04.5-server-amd64.iso \
--network network=default,model=virtio \
--graphics vnc \
--disk path=/var/lib/libvirt/images/ubuntu-14.04.5-server-amd64,size=32,bus=virtio
# cd /var/lib/libvirt/images/
# wget https://cloud-images.ubuntu.com/releases/14.04/release/ubuntu-14.04-server-cloudimg-amd64.tar.gz
# tar xvzf ubuntu-14.04-server-cloudimg-amd64.tar.gz
# qemu-img convert -O qcow2 trusty-server-cloudimg-amd64.img trusty.img.orig
# qemu-img create -f qcow2 -b trusty.img.orig trusty.img
# nano user-data
#cloud-config
password: password
chpasswd: { expire: False }
ssh_pwauth: True
# cloud-localds my-seed.img user-data
Now that we have all the required data, let's start our image with KVM, as follows:
$ sudo kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
This should start a virtual machine and route all input
# nano /etc/libvirt/qemu/trusty.xml
kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
# nano /etc/qemu/bridge.conf
# usermod -aG root libvirtd
Клонировать контейнер
# lxc-clone -o trusty_lxc -n kvm_lxc
# nano /var/lib/lxc/kvm_lxc/rootfs/etc/hosts
127.0.0.1 localhost
127.0.0.1 kvm_lxc
Сохранить.
# nano /var/lib/lxc/kvm_lxc/rootfs/etc/rc.local
mkdir -p /dev/net || true
mknod /dev/net/tun c 10 200
chmod 666 /dev/net/tun
mkdir -p /dev/kvm || true
mknod /dev/kvm c 10 232
exit 0
Сохранить
# nano /var/lib/lxc/kvm_lxc/config
## for openvpn
lxc.cgroup.devices.allow = b 7:* rwm
lxc.cgroup.devices.allow = c 10:200 rwm
lxc.cgroup.devices.allow = c 10:232 rwm
Сохранить.
.
Старт контейнера
# lxc-start -n kvm_lxc -d
# lxc-ls -f
# ssh ubuntu@kvm_lxc
# apt-get update
# apt-get install bridge-utils
# nano /etc/network/interfaces
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 0
Сохранить
# reboot
# lxc-start -n xrdp_lxc -d
# apt-get -y install -y lxc bridge-utils debootstrap libcap-dev cgroup-bin libpam-systemd
Disable the default bridge “lxcbr0“, got created as part of LXC installation.
# nano /etc/default/lxc-net
USE_LXC_BRIDGE="false"
Сохранить.
# nano /etc/lxc/default.conf
lxc.network.type = veth
lxc.network.link = br0 # Replace with your bridge name
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
Сохранить.
# nano /etc/dnsmasq.d/lxc
except-interface=br0
Сохранить.
# reboot
# nano /etc/default/lxc-net
USE_LXC_BRIDGE="false"
Сохранить.
# nano /etc/lxc/default.conf
lxc.network.type = veth
lxc.network.link = br0 # Replace with your bridge name
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
Сохранить.
# nano /etc/dnsmasq.d/lxc
except-interface=br0
Сохранить.
# reboot
Созадать контейнер:
!!!# lxc-create -t ubuntu -n precise_lxc -- -r precise -a amd64
# lxc-create -t ubuntu -n trusty_2lxc -- -r trusty -a amd64
!##
!# The default user is 'ubuntu' with password 'ubuntu'!
!# Use the 'sudo' command to run tasks as root in the container.
!##
Сохранение контейнера trusty_2lxc :
# cd /var/lib/lxc/
# tar -cvzf trusty_2lxc.tar.gz ./trusty_2lxc
W: Failure trying to run: chroot /var/cache/lxc/trusty/partial-amd64 mount -t proc proc /proc
W: See /var/cache/lxc/trusty/partial-amd64/debootstrap/debootstrap.log for details
lxc_container: lxccontainer.c: create_run_template: 1084 container creation template for trusty_2lxc failed
lxc_container: lxc_create.c: main: 274 Error creating container trusty_2lxc
Старт контейнера
# lxc-start -n trusty_2lxc -d
Посмотреть ip
# lxc-ls -f
W: Failure trying to run: chroot /var/cache/lxc/trusty/partial-amd64 mount -t proc proc /proc
W: See /var/cache/lxc/trusty/partial-amd64/debootstrap/debootstrap.log for details
lxc_container: lxccontainer.c: create_run_template: 1084 container creation template for trusty_2lxc failed
lxc_container: lxc_create.c: main: 274 Error creating container trusty_2lxc
Старт контейнера
# lxc-start -n trusty_2lxc -d
Посмотреть ip
# lxc-ls -f
Перестаем бояться виртуализации при помощи KVM
sudo apt-get update
sudo apt-get install qemu-kvm libvirt-bin virtinst
- /var/lib/libvirt/boot/ — ISO-образы для установки гостевых систем;
- /var/lib/libvirt/images/ — образы жестких дисков гостевых систем;
- /var/log/libvirt/ — тут следует искать все логи;
- /etc/libvirt/ — каталог с файлами конфигурации;
# wget http://mirror.yandex.ru/ubuntu-releases/14.04.5/ubuntu-14.04.5-server-amd64.iso
sudo kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
sudo virt-install \
--virt-type=kvm \
--name trusty \
--ram 1024 \
--vcpus=1 \
--os-variant=trusty \
--hvm \
--cdrom=/var/lib/libvirt/boot/ubuntu-14.04.5-server-amd64.iso \
--network network=default,model=virtio \
--graphics vnc \
--disk path=/var/lib/libvirt/images/ubuntu-14.04.5-server-amd64,size=32,bus=virtio
# cd /var/lib/libvirt/images/
# wget https://cloud-images.ubuntu.com/releases/14.04/release/ubuntu-14.04-server-cloudimg-amd64.tar.gz
# tar xvzf ubuntu-14.04-server-cloudimg-amd64.tar.gz
# qemu-img convert -O qcow2 trusty-server-cloudimg-amd64.img trusty.img.orig
# qemu-img create -f qcow2 -b trusty.img.orig trusty.img
# nano user-data
#cloud-config
password: password
chpasswd: { expire: False }
ssh_pwauth: True
# cloud-localds my-seed.img user-data
Now that we have all the required data, let's start our image with KVM, as follows:
$ sudo kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
This should start a virtual machine and route all input
# nano /etc/libvirt/qemu/trusty.xml
kvm -netdev bridge,id=net0,br=br0 \
-net user -m 256 -nographic \
-hda trusty.img -hdb my-seed.img
# nano /etc/qemu/bridge.conf
# usermod -aG root libvirtd
# ls -la /dev | grep kvm
root@kvm_lxc:~# ls -la /dev | grep kvm
crw-rw---- 1 root kvm 10, 232 апр. 5 18:40 kvm
#
ls -la /dev | grep net
Setup Linux Container with LXC on Ubuntu 16.04
Configure bridged networking for KVM on Ubuntu 14.10
Комментариев нет:
Отправить комментарий