added Ubuntu
This commit is contained in:
parent
d1cf93e2ed
commit
29eecb0ac8
53
tools/docker/ubuntu/Dockerfile
Normal file
53
tools/docker/ubuntu/Dockerfile
Normal file
|
@ -0,0 +1,53 @@
|
|||
FROM ubuntu:16.04 as ubuntu-blockchain
|
||||
LABEL maintainer="Kris Henriksen"
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
RUN apt update && \
|
||||
apt --yes --no-install-recommends install \
|
||||
linux-image-virtual \
|
||||
grub2 \
|
||||
systemd \
|
||||
initramfs-tools \
|
||||
net-tools \
|
||||
iputils-ping \
|
||||
&& \
|
||||
chsh -s /bin/bash && \
|
||||
echo "root:root" | chpasswd && \
|
||||
mkdir -p /etc/systemd/system/serial-getty@ttyS0.service.d/ && \
|
||||
systemctl enable serial-getty@ttyS0.service && \
|
||||
rm /lib/systemd/system/getty.target.wants/getty-static.service && \
|
||||
rm /etc/issue && \
|
||||
chmod -x /etc/update-motd.d/* && \
|
||||
systemctl disable apt-daily-upgrade.timer && \
|
||||
systemctl mask apt-daily-upgrade.service && \
|
||||
systemctl disable apt-daily.timer && \
|
||||
systemctl mask apt-daily.service && \
|
||||
systemctl disable systemd-timesyncd.service && \
|
||||
systemctl mask systemd-timesyncd.service && \
|
||||
systemctl disable motd-news.timer && \
|
||||
systemctl mask motd-news.timer && \
|
||||
echo "tmpfs /tmp tmpfs nodev,nosuid 0 0" >> /etc/fstab
|
||||
|
||||
COPY getty-noclear.conf getty-override.conf /etc/systemd/system/getty@tty1.service.d/
|
||||
COPY getty-autologin-serial.conf /etc/systemd/system/serial-getty@ttyS0.service.d/
|
||||
COPY logind.conf /etc/systemd/
|
||||
COPY boot-9p /etc/initramfs-tools/scripts/
|
||||
COPY grub /etc/default/
|
||||
|
||||
COPY networking.sh /root/
|
||||
|
||||
# this needs to be commented out in order to boot from hdd
|
||||
RUN printf '%s\n' 9p 9pnet 9pnet_virtio virtio virtio_ring virtio_pci | tee -a /etc/initramfs-tools/modules && \
|
||||
echo 'BOOT=boot-9p' | tee -a /etc/initramfs-tools/initramfs.conf && \
|
||||
update-initramfs -u
|
||||
|
||||
# ReducingDiskFootprint
|
||||
RUN apt-get remove --purge perl && \
|
||||
apt-get autoremove --purge
|
||||
RUN apt-get --yes clean && \
|
||||
rm -r /var/lib/apt/lists/* && \
|
||||
rm -r /usr/share/doc/* && \
|
||||
rm -r /usr/share/man/* && \
|
||||
rm -r /usr/share/locale/?? && \
|
||||
rm /var/log/*.log /var/log/lastlog /var/log/wtmp /var/log/apt/*.log
|
5
tools/docker/ubuntu/README.md
Normal file
5
tools/docker/ubuntu/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
You can build a Linux image for use with v86:
|
||||
|
||||
1. Run `./build-container.sh` to build the Docker container and v86 images (requires dockerd)
|
||||
2. Run `./build-state.js` to build a state image in order to skip the boot process
|
||||
3. Optionally, compress the `ubuntu-state-base.bin` file using zstd (v86 automatically detects the zstd magic and decompresses on the fly)
|
33
tools/docker/ubuntu/boot-9p
Normal file
33
tools/docker/ubuntu/boot-9p
Normal file
|
@ -0,0 +1,33 @@
|
|||
# 9p filesystem mounting -*- shell-script -*-
|
||||
|
||||
mountroot()
|
||||
{
|
||||
wait_for_udev 10
|
||||
|
||||
if [ ${readonly} = y ]; then
|
||||
roflag="-o ro"
|
||||
else
|
||||
roflag="-o rw"
|
||||
fi
|
||||
|
||||
#echo "Running: mount -t 9p -o cache=mmap ${ROOT} ${rootmnt}"
|
||||
#mount -t 9p -o cache=mmap ${ROOT} ${rootmnt}
|
||||
echo "Running: mount -t 9p -o cache=fscache ${ROOT} ${rootmnt}"
|
||||
mount -t 9p -o cache=fscache ${ROOT} ${rootmnt}
|
||||
echo "mount finished with code $?"
|
||||
}
|
||||
|
||||
mount_top()
|
||||
{
|
||||
echo top
|
||||
}
|
||||
|
||||
mount_premount()
|
||||
{
|
||||
echo premount
|
||||
}
|
||||
|
||||
mount_bottom()
|
||||
{
|
||||
echo bottom
|
||||
}
|
24
tools/docker/ubuntu/build-container.sh
Executable file
24
tools/docker/ubuntu/build-container.sh
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -veu
|
||||
|
||||
IMAGES="$(dirname "$0")"/../../../images
|
||||
OUT_ROOTFS_TAR="$IMAGES"/ubuntu-9p-rootfs.tar
|
||||
OUT_ROOTFS_FLAT="$IMAGES"/ubuntu-9p-rootfs-flat
|
||||
OUT_FSJSON="$IMAGES"/ubuntu-base-fs.json
|
||||
CONTAINER_NAME=ubuntu-full
|
||||
IMAGE_NAME=i386/ubuntu-full
|
||||
|
||||
mkdir -p "$IMAGES"
|
||||
docker build . --platform linux/386 --rm --tag "$IMAGE_NAME"
|
||||
docker rm "$CONTAINER_NAME" || true
|
||||
docker create --platform linux/386 -t -i --name "$CONTAINER_NAME" "$IMAGE_NAME" bash
|
||||
|
||||
docker export "$CONTAINER_NAME" > "$OUT_ROOTFS_TAR"
|
||||
|
||||
"$(dirname "$0")"/../../../tools/fs2json.py --out "$OUT_FSJSON" "$OUT_ROOTFS_TAR"
|
||||
|
||||
# Note: Not deleting old files here
|
||||
mkdir -p "$OUT_ROOTFS_FLAT"
|
||||
"$(dirname "$0")"/../../../tools/copy-to-sha256.py "$OUT_ROOTFS_TAR" "$OUT_ROOTFS_FLAT"
|
||||
|
||||
echo "$OUT_ROOTFS_TAR", "$OUT_ROOTFS_FLAT" and "$OUT_FSJSON" created.
|
104
tools/docker/ubuntu/build-state.js
Executable file
104
tools/docker/ubuntu/build-state.js
Executable file
|
@ -0,0 +1,104 @@
|
|||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
var fs = require("fs");
|
||||
var V86 = require("./../../../build/libv86.js").V86;
|
||||
|
||||
const V86_ROOT = path.join(__dirname, "../../..");
|
||||
|
||||
var OUTPUT_FILE = path.join(V86_ROOT, "images/ubuntu-state-base.bin");
|
||||
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.on("data", handle_key);
|
||||
|
||||
var emulator = new V86({
|
||||
bios: { url: path.join(V86_ROOT, "/bios/seabios.bin") },
|
||||
autostart: true,
|
||||
disable_speaker: true,
|
||||
memory_size: 128 * 1024 * 1024,
|
||||
vga_memory_size: 0,
|
||||
bzimage_initrd_from_filesystem: true,
|
||||
cmdline: [
|
||||
'rw',
|
||||
'init=/bin/systemd',
|
||||
'root=host9p',
|
||||
'rootfstype=9p',
|
||||
'rootflags=trans=virtio,cache=loose',
|
||||
'console=ttyS0,115200',
|
||||
'tsc=reliable',
|
||||
'mitigations=off',
|
||||
'spectre_v2=off',
|
||||
'pti=off',
|
||||
'random.trust_cpu=on',
|
||||
'maxcpus=0',
|
||||
'selinux=0',
|
||||
'audit=0',
|
||||
'nowatchdog',
|
||||
'mem=128M'
|
||||
].join(' '),
|
||||
filesystem: {
|
||||
basefs: {
|
||||
url: path.join(V86_ROOT, "/images/ubuntu-base-fs.json"),
|
||||
},
|
||||
baseurl: path.join(V86_ROOT, "/images/ubuntu-9p-rootfs-flat/"),
|
||||
},
|
||||
screen_dummy: true,
|
||||
network_relay_url: "<UNUSED>"
|
||||
});
|
||||
|
||||
console.log("Now booting, please stand by ...");
|
||||
|
||||
var boot_start = Date.now();
|
||||
var serial_text = "";
|
||||
let booted = false;
|
||||
|
||||
emulator.add_listener("serial0-output-char", function(c)
|
||||
{
|
||||
process.stdout.write(c);
|
||||
|
||||
serial_text += c;
|
||||
|
||||
if(!booted && serial_text.endsWith("root@localhost:~# "))
|
||||
{
|
||||
console.error("\nBooted in %d", (Date.now() - boot_start) / 1000);
|
||||
booted = true;
|
||||
|
||||
// sync and drop caches: Makes it safer to change the filesystem as fewer files are rendered
|
||||
emulator.serial0_send("sync;echo 3 >/proc/sys/vm/drop_caches\n");
|
||||
|
||||
setTimeout(async function ()
|
||||
{
|
||||
const s = await emulator.save_state();
|
||||
|
||||
fs.writeFile(OUTPUT_FILE, new Uint8Array(s), function(e)
|
||||
{
|
||||
if(e) throw e;
|
||||
console.error("Saved as " + OUTPUT_FILE);
|
||||
stop();
|
||||
});
|
||||
}, 10 * 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function handle_key(c)
|
||||
{
|
||||
if(c === "\u0003")
|
||||
{
|
||||
// ctrl c
|
||||
stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
emulator.serial0_send(c);
|
||||
}
|
||||
}
|
||||
|
||||
function stop()
|
||||
{
|
||||
emulator.stop();
|
||||
process.stdin.pause();
|
||||
}
|
11
tools/docker/ubuntu/build.sh
Executable file
11
tools/docker/ubuntu/build.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
./build-container.sh
|
||||
./build-state.js
|
||||
|
||||
# compress blockstate
|
||||
zstd --ultra -22 -f ../../../images/images/ubuntu-state-base.bin
|
||||
|
||||
# compress 9p filesystem
|
||||
#zstd --ultra -22 -r -f ../../../images/ubuntu-9p-rootfs-flat/
|
||||
#rm -rf ../../../images/ubuntu-9p-rootfs-flat/*.bin
|
3
tools/docker/ubuntu/getty-autologin-serial.conf
Normal file
3
tools/docker/ubuntu/getty-autologin-serial.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=-/sbin/agetty --autologin root --noissue --noclear -s %I 115200,38400,9600 vt102
|
2
tools/docker/ubuntu/getty-noclear.conf
Normal file
2
tools/docker/ubuntu/getty-noclear.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Service]
|
||||
TTYVTDisallocate=no
|
3
tools/docker/ubuntu/getty-override.conf
Normal file
3
tools/docker/ubuntu/getty-override.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=-/sbin/agetty --autologin root --noissue --noclear %I 38400 $TERM
|
9
tools/docker/ubuntu/grub
Normal file
9
tools/docker/ubuntu/grub
Normal file
|
@ -0,0 +1,9 @@
|
|||
GRUB_DEFAULT=0
|
||||
GRUB_HIDDEN_TIMEOUT=0
|
||||
GRUB_HIDDEN_TIMEOUT_QUIET=true
|
||||
GRUB_TIMEOUT=10
|
||||
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash console=ttyS0,115000 ipv6.disable=1"
|
||||
GRUB_CMDLINE_LINUX="ipv6.disable=1"
|
||||
GRUB_TERMINAL=console
|
||||
GRUB_DISABLE_RECOVERY="true"
|
37
tools/docker/ubuntu/logind.conf
Normal file
37
tools/docker/ubuntu/logind.conf
Normal file
|
@ -0,0 +1,37 @@
|
|||
# This file is part of systemd.
|
||||
#
|
||||
# systemd is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Entries in this file show the compile time defaults.
|
||||
# You can change settings by editing this file.
|
||||
# Defaults can be restored by simply deleting this file.
|
||||
#
|
||||
# See logind.conf(5) for details.
|
||||
|
||||
[Login]
|
||||
NAutoVTs=0
|
||||
ReserveVT=0
|
||||
#KillUserProcesses=no
|
||||
#KillOnlyUsers=
|
||||
#KillExcludeUsers=root
|
||||
#InhibitDelayMaxSec=5
|
||||
#HandlePowerKey=poweroff
|
||||
#HandleSuspendKey=suspend
|
||||
#HandleHibernateKey=hibernate
|
||||
#HandleLidSwitch=suspend
|
||||
#HandleLidSwitchDocked=ignore
|
||||
#PowerKeyIgnoreInhibited=no
|
||||
#SuspendKeyIgnoreInhibited=no
|
||||
#HibernateKeyIgnoreInhibited=no
|
||||
#LidSwitchIgnoreInhibited=yes
|
||||
#HoldoffTimeoutSec=30s
|
||||
#IdleAction=ignore
|
||||
#IdleActionSec=30min
|
||||
#RuntimeDirectorySize=10%
|
||||
#RemoveIPC=yes
|
||||
#InhibitorsMax=8192
|
||||
#SessionsMax=8192
|
||||
#UserTasksMax=33%
|
4
tools/docker/ubuntu/networking.sh
Normal file
4
tools/docker/ubuntu/networking.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
rmmod ne2k-pci && modprobe ne2k-pci
|
||||
ifconfig enp0s5 192.168.1.5 netmask 255.255.255.0 up
|
||||
route add default gw 192.168.1.1
|
||||
echo "nameserver 8.8.8.8" > /etc/resolv.conf
|
Loading…
Reference in a new issue