Linux/Xen/Building Xen DomU images: Difference between revisions

From Guungle
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Debian==
==CentOS==


==Ubuntu==
===[[Linux/Xen/DomU/CentOS/CentOS 7|CentOS 7]]===


===Ubuntu 13.10===
==Debian==


Start this process on a existing Ubuntu system. Does not have to be a 13.10 system. You will need to have debootstrap installed and may need to update debootstrap so it has the correct script for 13.10.
==Devuan==


Create a empty image file and format it with ext3.
===[[Linux/Xen/DomU/Devuan/Devuan Jessie|Devuan Jessie]]===
===[[Linux/Xen/DomU/Devuan/Devuan ASCII|Devuan ASCII]]===
===[[Linux/Xen/DomU/Devuan/Devuan Beowulf|Devuan Beowulf]]===


dd if=/dev/zero of=ubuntu_saucy.img bs=1M count=1 seek=1024
==Ubuntu==
mkfs.ext3 ubuntu_saucy.img
 
Create a directory to mount the image on. Using '/mnt/img' for this example.
 
mkdir /mnt/img
mount -oloop ubuntu_saucy.img /mnt/img
 
Start the debootstrap process.
 
debootstrap saucy /mnt/img/
 
Once that completes, copy your existing /etc/apt/sources.list to the new image so we can run updates.
 
cp /etc/apt/sources.list /mnt/img/etc/apt/
 
Mount the necessary system files so that we can enter the new root filesystem with chroot.
 
mount --bind /dev /mnt/img/dev
mount --bind /dev/pts /mnt/img/dev/pts
mount -t proc proc /mnt/img/proc
mount -t sysfs sys /mnt/img/sys
chroot /mnt/img
 
Run updates and install a language pack.
 
apt-get update
apt-get install language-pack-en-base
apt-get upgrade
 
Configure the system timezone.
 
dpkg-reconfigure tzdata
 
Install the kernel image and install SSH server.
apt-get install linux-image
apt-get install openssh-server
 
To use the Xen console 'xm console (domU)' you need to setup a tty on /dev/hvc0. Create the file '/etc/init/hvc0.conf' with this content.
 
<syntaxhighlight lang="bash">
# This service maintains a getty on hvc0 from the point the system is
# started until it is shut down again.
 
start on stopped rc RUNLEVEL=[2345] and (
            not-container or
            container CONTAINER=lxc or
            container CONTAINER=lxc-libvirt)
stop on runlevel [!2345]
 
respawn
exec /sbin/getty -8 38400 hvc0
</syntaxhighlight>
 
The default udev rules for 13.10 ignore Xen generated MAC addresses so you won't get a '/etc/udev/rules.d/70-persistent-net.rules' This causes your network interfaces not to come up.
 
Edit '/lib/udev/rules.d/75-persistent-net-generator.rules' and comment these lines. Here's the changes in patch/diff format.
 
<syntaxhighlight lang="diff">
@@ -21,7 +21,7 @@ KERNEL!="eth*|ath*|wlan*[0-9]|msh*|ra*|s
                                        GOTO="persistent_net_generator_end"
 
# ignore Xen virtual interfaces
-SUBSYSTEMS=="xen",                    GOTO="persistent_net_generator_end"
+#SUBSYSTEMS=="xen",                    GOTO="persistent_net_generator_end"
 
# ignore UML virtual interfaces
DRIVERS=="uml-netdev",                GOTO="persistent_net_generator_end"
@@ -75,7 +75,7 @@ ENV{MATCHADDR}=="00:0c:29:*|00:50:56:*|0
ENV{MATCHADDR}=="00:15:5d:*",          ENV{MATCHADDR}=""
ENV{MATCHADDR}=="52:54:00:*|54:52:00:*", ENV{MATCHADDR}=""
ENV{MATCHADDR}=="08:00:27:*",          ENV{MATCHADDR}=""
-ENV{MATCHADDR}=="00:16:3e:*",          ENV{MATCHADDR}=""
+#ENV{MATCHADDR}=="00:16:3e:*",        ENV{MATCHADDR}=""
 
# ignore Windows Azure Hyper-V virtual interfaces
ENV{MATCHADDR}=="00:03:ff:*", ENV{MATCHADDR}=""
</syntaxhighlight>
 
Configure your '/etc/network/interfaces' for DHCP
 
<syntaxhighlight lang="bash">
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
 
auto eth0
iface eth0 inet dhcp
</syntaxhighlight>
 
Configure a basic fstab
 
<syntaxhighlight lang="bash">
# Begin /etc/fstab
# <file system> <mount-point>  <type>  <options>                      <dump> <pass>
/dev/sda1          /            ext3      defaults,errors=remount-ro    0    0
proc              /proc        proc      defaults                      0    0
 
# End /etc/fstab
</syntaxhighlight>
 
====SSH host keys fix====
 
Since this image will get cloned and used to create new virtual machines we don't want to re-use the same keys for every virtual machine. Ubuntu won't regenerate SSH host keys if you delete them from /etc/ssh. So we need a script to check the host keys and regenerate them if needed.
 
 
 
====Firewall====
 
<syntaxhighlight lang="bash">
apt-get install iptables
apt-get install ufw
 
ufw allow OpenSSH
ufw enable
</syntaxhighlight>
 
====Final Cleanup====


Remove /etc/udev/rules.d/70-persistent-net.rules so that network comes up clean when the image is booted for the first time.
===[[Linux/Xen/DomU/Ubuntu/Ubuntu 13.10|Ubuntu 13.10]]===


Remove SSH host keys so that new ones get generated on first boot.
===[[Linux/Xen/DomU/Ubuntu/Ubuntu 14.04 LTS|Ubuntu 14.04 LTS]]===


<syntaxhighlight lang="bash">
===[[Linux/Xen/DomU/Ubuntu/Ubuntu 18.04 LTS|Ubuntu 18.04 LTS]]===
rm /etc/udev/rules.d/70-persistent-net.rules
rm /etc/ssh/ssh_host_*
</syntaxhighlight>

Latest revision as of 13:15, 4 July 2020