- Create a system user ‘uml’ with home directory /home/uml/
- Add systemd unit file for uml under /etc/systemd/system/uml@.service
# Systemd unit file for an UML instance
[Unit]
Description=User Mode Linux
[Service]
Type=simple
WorkingDirectory=/home/uml/
Environment=HOME=/home/uml TEMP=/dev/shm/ UMID=fedora23-%i IID=%i
ExecPreStart=/home/uml/cloud.sh
ExecStart=/home/uml/linux mem=1280M umid=${UMID} eth0=tuntap,,,192.168.10.${IID} ubd0=${UMID}/Fedora23-Root.cow,images/Fedora-Cloud-Base-23-20151030.x86_64.raw ubd1=${UMID}/cloud-config.iso root=/dev/ubda1 ds=nocloud LANG=de_DE.utf8 plymouth.enable=0 stderr=1 con=pts
ExecStop=/usr/bin/uml_mconsole ${UMID} halt
ExecRestart=/usr/bin/uml_mconsole ${UMID} reboot
User=uml
SyslogIdentifier=uml
[Install]
WantedBy=multi-user.target
- Add a cloud.sh file under /home/uml/cloud.sh
#!/bin/sh
CLOUD_CONFIG_DIR=/home/uml/$UMID
mkdir -p $CLOUD_CONFIG_DIR
cd $CLOUD_CONFIG_DIR
cat << EOF > $CLOUD_CONFIG_DIR/user-data
#cloud-config
ssh_authorized_keys:
- ssh-rsa << your key goes here >>
EOF
cat << EOF > $CLOUD_CONFIG_DIR/meta-data
instance-id: iid-uml-$IID
local-hostname: umlhost-$IID
network-interfaces: |
iface eth0 inet static
address 192.168.10.$(($IID * 2))
network 192.168.10.0
netmask 255.255.255.0
broadcast 192.168.10.255
gateway 192.168.10.$(($IID * 2 - 1))
# dns-nameservers 192.168.2.1
EOF
genisoimage -output $CLOUD_CONFIG_DIR/cloud-config.iso -volid cidata -joliet -rock $CLOUD_CONFIG_DIR/user-data $CLOUD_CONFIG_DIR/meta-data