6 changed files with 144 additions and 9 deletions
@ -1,3 +1,28 @@ |
|||
FROM ubuntu:bionic |
|||
ADD ./run.sh /tmp/run.sh |
|||
RUN bash /tmp/run.sh && rm /tmp/run.sh |
|||
FROM ubuntu:bionic as builder |
|||
|
|||
ENV DEBIAN_FRONTEND=noninteractive |
|||
|
|||
|
|||
RUN apt update && \ |
|||
apt install -y \ |
|||
libguestfs-tools \ |
|||
bash \ |
|||
libosinfo-bin \ |
|||
libvirt-bin \ |
|||
libvirt-clients \ |
|||
qemu-user \ |
|||
qemu-utils \ |
|||
sudo \ |
|||
virtinst |
|||
|
|||
RUN useradd -m user |
|||
|
|||
RUN qemu-img create -f qcow2 /image.qcow2 100G |
|||
|
|||
ADD . /home/user/ |
|||
|
|||
RUN chown user:user /*.qcow2 && chown user:user /home/user/* && chmod a+rwX /home/user/* |
|||
|
|||
RUN sudo --login -u user /home/user/install.sh |
|||
|
|||
ENTRYPOINT /bin/bash |
|||
|
@ -1,4 +1,4 @@ |
|||
default: build |
|||
|
|||
build: |
|||
docker build . |
|||
docker build -t sneak/docker-linux-vm . |
|||
|
@ -0,0 +1,21 @@ |
|||
#!/bin/bash |
|||
|
|||
function install_os() { |
|||
osinfo-query os |
|||
virsh list |
|||
virt-install --virt-type qemu --name linux \ |
|||
--ram 4096 \ |
|||
--disk path=/image.qcow2 \ |
|||
--vcpus 4 \ |
|||
--os-type linux \ |
|||
--os-variant ubuntu18.04 \ |
|||
--initrd-inject=preseed.cfg \ |
|||
--initrd-inject=postinst.sh \ |
|||
--graphics none \ |
|||
--location 'http://us.archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/' \ |
|||
--extra-args 'console=ttyS0,115200n8 serial' |
|||
virsh list |
|||
virsh console linux |
|||
} |
|||
|
|||
install_os |
@ -0,0 +1,28 @@ |
|||
#!/bin/sh |
|||
|
|||
# This script is run by debian installer using preseed/late_command |
|||
# directive, see preseed.cfg |
|||
|
|||
# Setup console, remove timeout on boot. |
|||
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"/g; s/TIMEOUT=5/TIMEOUT=0/g' /etc/default/grub |
|||
update-grub |
|||
|
|||
# Members of `sudo` group are not asked for password. |
|||
sed -i 's/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL:ALL) NOPASSWD:ALL/g' /etc/sudoers |
|||
|
|||
# Empty message of the day. |
|||
echo -n > /etc/motd |
|||
|
|||
# Install collectd and config. |
|||
#apt-get install -y collectd-core |
|||
#cp /tmp/postinst/collectd.conf /etc/collectd/ |
|||
|
|||
export DEBIAN_FRONTEND=noninteractive |
|||
apt install -y vim |
|||
|
|||
# Set domain name in hosts file |
|||
sed -i 's/127.0.1.1\t\([a-z]*\).*/127.0.1.1\tvm\t\1/' /etc/hosts |
|||
|
|||
# Avoid using DHCP-server provided domain name. |
|||
#sed -i 's/#supersede.*/supersede domain-name "dp-net.com";/' /etc/dhcp/dhclient.conf |
|||
|
@ -0,0 +1,66 @@ |
|||
# Preconfiguration file for jessie. |
|||
# For more details see https://www.debian.org/releases/jessie/example-preseed.txt |
|||
d-i debian-installer/locale string en_US |
|||
d-i keyboard-configuration/xkb-keymap select us |
|||
|
|||
# Choose an network interface that has link if possible. |
|||
d-i netcfg/choose_interface select auto |
|||
|
|||
# Disable that annoying WEP key dialog. |
|||
d-i netcfg/wireless_wep string |
|||
|
|||
# Mirror settings. |
|||
d-i mirror/country string manual |
|||
d-i mirror/http/hostname string archive.ubuntu.com |
|||
d-i mirror/http/directory string /ubuntu |
|||
d-i mirror/http/proxy string |
|||
|
|||
# Root account setup. You can set password in plain-text or pre-encrypted. |
|||
d-i passwd/root-login boolean false |
|||
#d-i passwd/root-password password 98e1c23d2a5a2 |
|||
#d-i passwd/root-password-again password 98e1c23d2a5a2 |
|||
#d-i passwd/root-password-crypted password $6$1LCVFshS/kbYVg$M1QS1ZJ3.E7NkAD8sqkqhqExA2HWQ5/iDE.l23Xbr89Z7hTg/jUuBMyrYzANLmRybYcH8Smcy.yGDKMAX3okd0 |
|||
|
|||
# User account setup. |
|||
#d-i passwd/make-user boolean false |
|||
d-i passwd/user-fullname string user |
|||
d-i passwd/username string user |
|||
d-i passwd/user-password password password |
|||
d-i passwd/user-password-again password password |
|||
#d-i passwd/user-password-crypted password $6$dU9we2Mm$Btq1Tk1WkFx3/8YsXWbZr13m56uv0PabJKxk5teKAImLLQhtniOURXuOVLmbiBl0O3iS6xQBctNIc9Dn5b3vR. |
|||
# Password login is disabled. |
|||
d-i passwd/user-password-crypted password ! |
|||
|
|||
# Controls whether or not the hardware clock is set to UTC. |
|||
d-i clock-setup/utc boolean true |
|||
# See the contents of /usr/share/zoneinfo/ for valid values. |
|||
d-i time/zone string UTC |
|||
# Controls whether to use NTP to set the clock during the install. |
|||
d-i clock-setup/ntp boolean true |
|||
|
|||
# Simple non-LVM, all files in one partition. |
|||
# For more examples see https://www.debian.org/releases/jessie/example-preseed.txt |
|||
d-i partman-auto/method string regular |
|||
d-i partman-auto/choose_recipe select atomic |
|||
d-i partman-partitioning/confirm_write_new_label boolean true |
|||
d-i partman/choose_partition select finish |
|||
d-i partman/confirm boolean true |
|||
d-i partman/confirm_nooverwrite boolean true |
|||
|
|||
# Do not install recommended packages by default. |
|||
d-i base-installer/install-recommends boolean false |
|||
tasksel tasksel/first multiselect |
|||
# Individual additional packages to install. acpid and acpi-support-base are required to make virsh shutdown to work. |
|||
# ACPI packages are needed for `virsh shutdown <domain>` to work. |
|||
d-i pkgsel/include string openssh-server ca-certificates acpid acpi-support-base |
|||
popularity-contest popularity-contest/participate boolean false |
|||
|
|||
# Boot loader installation. |
|||
d-i grub-installer/only_debian boolean true |
|||
d-i grub-installer/bootdev string /dev/vda |
|||
|
|||
# Run postinst.sh in /target just before the install finishes. |
|||
d-i preseed/late_command string cp postinst.sh postinst.tar.gz /target/tmp/ && chmod 755 /target/tmp/postinst.sh && in-target /tmp/postinst.sh |
|||
|
|||
# Avoid that last message about the install being complete. |
|||
d-i finish-install/reboot_in_progress note |
@ -1,5 +0,0 @@ |
|||
#!/bin/bash |
|||
|
|||
export DEBIAN_FRONTEND=noninteractive |
|||
apt update |
|||
apt install -y qemu-user |
Reference in new issue