Automaatne Debiani install KVM jaoks

Allikas: Kuutõrvaja
# mkdir -p /srv/chroot/test
# debootstrap wheezy /srv/chroot/test

Gentoo automaatseks paigalduseks on olemas selline käsk nagu debootstrap.

debootstrap --include=busybox,ca-certificates,file, \
initramfs-tools,less,linux-image-2.6-  amd64,\
locales,openssl,perl,rsync,vim squeeze $DST http://ftp.ee.debian.org/debian

Loome kettale sobiva viilaka, näiteks LVM peale:

# lvcreate -L 5G -n vm-110-disk-1 --addtag pve-vm-110 ve1

Tekitame sellele ext3 failisüsteemi:

# mkfs.ext3 -v -m 2 -b 4096 -E stride=32,stripe-width=64,resize=20G /dev/vda

Moundime selle /mnt/kvm harusse ja käivitame alloleva skripti

#!/bin/bash

DST="/mnt/kvm"
DSTIP="192.168.1.2"
DSTGW="192.268.1.1"
DSTDOMAIN="test.edu.ee"

export http_proxy=http://vigri.eenet.ee:8888
debootstrap --exclude=nano,dmidecode,tasksel,tasksel-data --include=busybox,ca-certificates,file,initramfs-tools,less,linux-image-2.6-amd64,\
locales,openssl,perl,rsync,vim squeeze $DST http://ftp.ee.debian.org/debian

echo "/etc/kernel-img.conf"
cat > $DST/etc/kernel-img.conf <<-EOF
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = no
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
EOF

echo "/etc/resolv.conf"
cat > $DST/etc/resolv.conf <<-EOF
search eenet.ee
nameserver 193.40.112.3
nameserver 193.40.0.12
EOF

echo "/etc/network/iptables"
cat > $DST/etc/network/iptables <<-EOF
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 1/sec -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --rsource 
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 180 --hitcount 4 --name DEFAULT --rsource -j DROP 
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT 
COMMIT
EOF

echo "/etc/network/interfaces"
cat > $DST/etc/network/interfaces <<-EOF
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto lo
iface lo inet loopback
pre-up /sbin/iptables-restore < /etc/network/iptables

auto eth0
iface eth0 inet static
	address $DSTIP
	netmask 255.255.255.0
	gateway $DSTGW
EOF

echo "/etc/hostname"
echo $DSTHOSTNAME > $DST/etc/hostname

echo "/etc/locale.gen"
cat > $DST/etc/locale.gen <<-EOF
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
en_US.UTF-8 UTF-8
et_EE ISO-8859-1
et_EE.ISO-8859-15 ISO-8859-15
et_EE.UTF-8 UTF-8
EOF

echo "/etc/fstab"
cat > $DST/etc/fstab <<-EOF
# /etc/fstab: static file system information.
#
# <file system>	<mount point>	<type>	<options>	<dump>	<pass>
proc		/proc		proc	defaults	0	0
/dev/vda	/		ext3	defaults	0	1
EOF

rm $DST/etc/udev/rules.d/70-persistent-net.rules

chroot $DST apt-get update
chroot $DST locale-gen
chroot $DST passwd -d root

echo "Done!"

KVMi konfiguratsioon /etc/qemu-server/ kaustas nimega 110.conf võiks välja näha järgnev:

name: test.edu.ee
vlan0: virtio=00:16:3E:00:70:3B
virtio0: ve1:vm-110-disk-1
cores: 1
ostype: l26
memory: 1024
sockets: 1
onboot: 1
freeze: 0
cpuunits: 1000
acpi: 1
kvm: 1
args: -kernel /boot/vmlinuz-2.6.32-5-amd64 -initrd /boot/initrd.img-2.6.32-5-amd64 -append 'root=/dev/vda ro'

Nagu näha siis kasutame bootimiseks KVM hosti enda kernelit. Selline lahendus muudab mõnevõrra lihtsamaks nii virtuaalsete masinte tekitamist kui haldamist

KVM masina startimiseks:

# qm create 110

PS: Antud skripti on võimalik lisaks Debianile käivitada ka gentoo peal, vajalik on eelnevalt paigaldada pakett: dev-util/debootstrap

# emerge dev-util/debootstrap