🧘
Debian10 で Xen
Debian12もリリースされた今、2世代前の情報を出す意味があるのか非常に微妙ですが、せっかく手元にメモを残してあったので記載しておきます。
参考
必要パッケージの導入
Debian10の環境で、Xen のインストール、仮想マシンの作成をしてみます。
必要なパッケージをインストールします。
# apt-get install xen-system-amd64
dom0 の設定
dom0 のメモリ容量の自動伸縮を禁止します。
# cp -pi /etc/xen/xl.conf /etc/xen/xl.conf.000
# vi /etc/xen/xl.conf
# diff -u /etc/xen/xl.conf /etc/xen/xl.conf.000
--- /etc/xen/xl.conf 2023-02-10 17:49:21.612357435 -0500
+++ /etc/xen/xl.conf.000 2021-06-14 07:31:09.000000000 -0400
@@ -4,7 +4,6 @@
# free memory to create a domain. "auto" means only balloon if dom0
# starts with all the host's memory.
#autoballoon="auto"
-autoballoon=0
# full path of the lockfile used by xl during domain creation
#lockfile="/var/lock/xl"
dom0 で利用するメモリ容量を設定します。
# cp -pi /etc/default/grub /etc/default/grub.000
# vi /etc/default/grub
# diff -u /etc/default/grub /etc/default/grub.000
--- /etc/default/grub 2023-02-10 17:52:17.293105059 -0500
+++ /etc/default/grub.000 2023-02-10 17:30:41.102194000 -0500
@@ -30,6 +30,3 @@
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
-
-# Xen boot parameters for all Xen boots
-GRUB_CMDLINE_XEN="dom0_mem=1024M,max:1024M"
GRUBメニューの設定を反映します。
# update-grub
Including Xen overrides from /etc/default/grub.d/xen.cfg
WARNING: GRUB_DEFAULT changed to boot into Xen by default!
Edit /etc/default/grub.d/xen.cfg to avoid this warning.
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.19.0-23-amd64
Found initrd image: /boot/initrd.img-4.19.0-23-amd64
Found linux image: /boot/vmlinuz-4.19.0-20-amd64
Found initrd image: /boot/initrd.img-4.19.0-20-amd64
Found linux image: /boot/vmlinuz-4.19.0-23-amd64
Found initrd image: /boot/initrd.img-4.19.0-23-amd64
Found linux image: /boot/vmlinuz-4.19.0-20-amd64
Found initrd image: /boot/initrd.img-4.19.0-20-amd64
Found linux image: /boot/vmlinuz-4.19.0-23-amd64
Found initrd image: /boot/initrd.img-4.19.0-23-amd64
Found linux image: /boot/vmlinuz-4.19.0-20-amd64
Found initrd image: /boot/initrd.img-4.19.0-20-amd64
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
done
OSを再起動します。
# shutdown -r now
確認
dom0 として動いていることを確認します。
# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r----- 25.0
# xl info
host : debian10
release : 4.19.0-23-amd64
version : #1 SMP Debian 4.19.269-1 (2022-12-20)
machine : x86_64
nr_cpus : 1
max_cpu_id : 0
nr_nodes : 1
cores_per_socket : 1
threads_per_core : 1
cpu_mhz : 3200.037
hw_caps : 078bf3ff:f7f83203:2e500800:000003f7:0000000f:209c01ab:00000000:00000000
virt_caps : hvm
total_memory : 4095
free_memory : 3021
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 11
xen_extra : .4
xen_version : 4.11.4
xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset :
xen_commandline : placeholder dom0_mem=1024M,max:1024M
cc_compiler : gcc (Debian 8.3.0-6) 8.3.0
cc_compile_by : pkg-xen-devel
cc_compile_domain : lists.alioth.debian.org
cc_compile_date : Mon Jun 14 14:46:59 UTC 2021
build_id : 632482dd7a76e0803e4b412e5c1227fcea67e937
xend_config_format : 4
dom0 のメモリ容量が設定した値となっていることを確認します。
$ uname -a
Linux debian10 4.19.0-23-amd64 #1 SMP Debian 4.19.269-1 (2022-12-20) x86_64 GNU/Linux
$ free -m
total used free shared buff/cache available
Mem: 917 48 778 1 90 849
Swap: 974 0 974
仮想ブリッジ
ここでは Open vSwitch の 仮想ブリッジ ovsbr0 を利用することにします。
# apt install --no-install-recommends openvswitch-switch
# cp -pi /etc/network/interfaces /etc/network/interfaces.000
# vi /etc/network/interfaces
# grep -v '^#' /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-ovs ovsbr0
iface ovsbr0 inet static
ovs_type OVSBridge
ovs_ports ens3
address 10.2.0.243/24
gateway 10.2.0.1
dns-nameservers 192.168.11.249
allow-ovsbr0 ens3
iface ens3 inet manual
ovs_bridge ovsbr0
ovs_type OVSPort
# systemctl restart networking
# ovs-vsctl show
13f8b8d3-7732-4aba-850d-fa2b5b97593e
Bridge "ovsbr0"
Port "ovsbr0"
Interface "ovsbr0"
type: internal
Port "ens3"
Interface "ens3"
ovs_version: "2.10.7"
# ip a show ovsbr0
5: ovsbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 0a:72:d2:10:df:4e brd ff:ff:ff:ff:ff:ff
inet 10.2.0.243/24 brd 10.2.0.255 scope global ovsbr0
valid_lft forever preferred_lft forever
inet6 fe80::872:d2ff:fe10:df4e/64 scope link
valid_lft forever preferred_lft forever
関連パッケージの導入
# apt-get install xen-tools
使用するブリッジの設定を変更します。
# cp -pi /etc/xen/xl.conf /etc/xen/xl.conf.001
# vi /etc/xen/xl.conf
# diff -u /etc/xen/xl.conf /etc/xen/xl.conf.001
--- /etc/xen/xl.conf 2023-02-10 19:22:13.341212486 -0500
+++ /etc/xen/xl.conf.001 2023-02-10 17:49:21.612357435 -0500
@@ -29,11 +29,9 @@
# default vif script to use if none is specified in the guest config
#vif.default.script="vif-bridge"
-vif.default.script="vif-openvswitch"
# default bridge device to use with vif-bridge hotplug scripts
#vif.default.bridge="xenbr0"
-vif.default.bridge="ovsbr0"
# Reserve a claim of memory when launching a guest. This guarantees immediate
# feedback whether the guest can be launched due to memory exhaustion
利用するネットワークアドレスの情報を設定します。
# cp -pi /etc/xen-tools/xen-tools.conf /etc/xen-tools/xen-tools.conf.000
# vi /etc/xen-tools/xen-tools.conf
# diff -u /etc/xen-tools/xen-tools.conf /etc/xen-tools/xen-tools.conf.000
--- /etc/xen-tools/xen-tools.conf 2023-02-10 19:50:44.064314913 -0500
+++ /etc/xen-tools/xen-tools.conf.000 2019-02-08 19:56:51.000000000 -0500
@@ -159,9 +159,9 @@
# Uncomment and adjust these network settings if you wish to give your
# new instances static IP addresses.
#
-gateway = 10.2.0.1
-netmask = 255.255.255.0
-broadcast = 10.2.0.255
+# gateway = 192.168.1.1
+# netmask = 255.255.255.0
+# broadcast = 192.168.1.255
#
# Uncomment this if you wish the images to use DHCP
#
@@ -174,7 +174,7 @@
# By default, nameserver is not set, and Dom0's /etc/resolv.conf will
# be copied to guest.
#
-nameserver = 192.168.11.249
+# nameserver = 192.168.1.1
#
#
domU の起動
domU のイメージを作成します。しばらく時間がかかります。
# xen-create-image --hostname=test --pygrub --ip 10.2.0.250 --dir /home/user --memory=1G --maxmem=1G --noswap --size=4G --passwd [14/1853]
General Information
--------------------
Hostname : test
Distribution : buster
Mirror : http://deb.debian.org/debian
Partitions : / 4G (ext4)
Image type : sparse
Memory size : 1G
Max mem size : 1G
Bootloader : pygrub
Networking Information
----------------------
IP Address 1 : 10.2.0.250 [MAC: 00:16:3E:DB:C8:13]
Netmask : 255.255.255.0
Broadcast : 10.2.0.255
Gateway : 10.2.0.1
Nameserver : 192.168.11.249
WARNING
-------
Loopback module not loaded and you're using loopback images
Run the following to load the module:
modprobe loop max_loop=255
Creating partition image: /home/user/domains/test/disk.img
Done
Creating ext4 filesystem on /home/user/domains/test/disk.img
Done
Installation method: debootstrap
Done
Running hooks
Done
No role scripts were specified. Skipping
Creating Xen configuration file
Done
No role scripts were specified. Skipping
Setting up root password
New password:
Retype new password:
passwd: password updated successfully
All done
Logfile produced at:
/var/log/xen-tools/test.log
Installation Summary
---------------------
Hostname : test
Distribution : buster
MAC Address : 00:16:3E:DB:C8:13
IP Address(es) : 10.2.0.250
SSH Fingerprint : SHA256:bDbHj6yUMPBWBwXeUHenfOlp85BO43xr1E0fcqLRoLo (DSA)
SSH Fingerprint : SHA256:mydCTe8oyw3ekx0CLQCPOAKS0Re0SZzFk8DBqJO4Cds (ECDSA)
SSH Fingerprint : SHA256:xJ1oV5eEtv7hgDBvnBnvdrQ/bI6QHTzvYKV9dwlRMWg (ED25519)
SSH Fingerprint : SHA256:xpiS5JVzCCfez0yLIEmLNCccgi0ZBuzf10kKQBiEtcc (RSA)
Root Password : N/A
作成された cfg ファイルを確認します。
# cat /etc/xen/test.cfg
#
# Configuration file for the Xen instance test, created
# by xen-tools 4.8 on Fri Feb 10 20:11:18 2023.
#
#
# Kernel + memory size
#
bootloader = 'pygrub'
vcpus = '1'
memory = '1024'
maxmem = '1024'
#
# Disk device(s).
#
root = '/dev/xvda1 ro'
disk = [
'file:/home/user/domains/test/disk.img,xvda1,w',
]
#
# Physical volumes
#
#
# Hostname
#
name = 'test'
#
# Networking
#
vif = [ 'ip=10.2.0.250 ,mac=00:16:3E:DB:C8:13' ]
#
# Behaviour
#
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
domU を起動します。
(コンソールから切断するには “Ctrl + ]”を入力します)
# xl create /etc/xen/apache.cfg -c
# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1022 1 r----- 1042.1
test 1 1024 1 -b---- 21.6
xl shutdown コマンドで domU を停止します。
# xl shutdown test
Shutting down domain 1
# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r----- 1074.3
# xl vm-list
UUID ID name
00000000-0000-0000-0000-000000000000 0 Domain-0
再度起動してみます。
# xl create /etc/xen/test.cfg
Parsing config from /etc/xen/test.cfg
# xl vm-list
UUID ID name
00000000-0000-0000-0000-000000000000 0 Domain-0
cc4b093f-3dac-4571-8438-b14cf42d58ca 2 test
Discussion