Browse Source

Start porting to Ubuntu 20.04.1

tags/nilmbuntu-6
Jim Paris 1 year ago
parent
commit
6c659f213a
12 changed files with 64 additions and 128 deletions
  1. +14
    -19
      README.md
  2. +6
    -12
      buildiso.sh
  3. +1
    -1
      config
  4. +1
    -1
      config-20.04.1
  5. +11
    -8
      customize.sh
  6. +6
    -21
      enter.sh
  7. +20
    -65
      files/customize-inner.sh
  8. +2
    -0
      files/fallback_dns.conf
  9. +0
    -0
      files/nilmbuntu.png
  10. +0
    -0
      files/preseed.cfg
  11. +0
    -0
      files/splash.png
  12. +3
    -1
      run.sh

README → README.md View File

@@ -1,49 +1,44 @@
Nilmbuntu
=========

Tools to customize an Ubuntu Live CD. Many parts of this will end up
being version-specific. The host machine must be running systemd,
since the image is executed inside a systemd-nspawn container.

Set up host machine, which must be running a recent systemd:
Set up host machine:

sudo apt install squashfs-tools xorriso isolinux systemd-container iptables
sudo systemctl start systemd-networkd
sudo apt install squashfs-tools xorriso isolinux systemd-container iptables
sudo systemctl start systemd-networkd

Choose a config:

export BUILD_CONFIG=16.04
export BUILD_CONFIG=20.04.1

Download and extract the original ISO:

./extractiso.sh
./extractiso.sh

Apply customizations, both to the outer ISO and the inner image.
This will also run customizer-inner.sh inside a container:

./customize.sh
./customize.sh

(Optional) Run and enter a shell in the container, for manual customization:

./enter.sh
./enter.sh

Build the new ISO:

./buildiso.sh
./buildiso.sh

Boot the ISO in QEMU with a blank HDD, to test and install:

./run.sh -c
./run.sh -c

Boot QEMU with the same HDD image as above, to test an "installed" system:

./run.sh -d
./run.sh -d

Remove everything but the ISOs:

./cleanup.sh

Notes:

- A more proper way to build a distro from scratch would be something
like one of these, except that they're out of date:

http://www.mythbuntu.org/development/developer-cheatsheet (2010)
https://github.com/squibbylinux/squibby-build (2012)
./cleanup.sh

+ 6
- 12
buildiso.sh View File

@@ -15,27 +15,21 @@ fi
set -x
set -e

INITRD=${FS}/initrd.img
VMLINUZ=$(readlink -f ${FS}/vmlinuz)
VMLINUZ_EFI=${VMLINUZ}.efi.signed
INITRD=${FS}/boot/initrd.img
VMLINUZ=${FS}/boot/vmlinuz

if ! [ "$1" == "justiso" ] ; then


if ! [ -r ${INITRD} -a -r ${VMLINUZ} -a -r ${VMLINUZ_EFI} ] ; then
if ! [ -r ${INITRD} -a -r ${VMLINUZ} ] ; then
set +x
echo "== Missing kernel and/or initrd. Either upgrade or reinstall"
echo "== the kernel inside the image to get the right files."
exit 1
fi

# Recompress initrd if changed
if [ ${INITRD} -nt ${ISO}/casper/initrd.lz ] ; then
sh -c "zcat ${INITRD} | lzma > ${ISO}/casper/initrd.lz"
fi
# Get kernel and signed EFI kernel
# Copy kernel and initrd
cp ${INITRD} ${ISO}/casper/initrd
cp ${VMLINUZ} ${ISO}/casper/vmlinuz
cp ${VMLINUZ_EFI} ${ISO}/casper/vmlinuz.efi

# manifests
chmod +w ${ISO}/casper/filesystem.manifest
@@ -51,7 +45,7 @@ if ! [ "$1" == "justiso" ] ; then
fi

# md5sums
rm -f md5sum.txt
rm -f ${ISO}/md5sum.txt
find ${ISO} -type f -print0 \
| xargs -0 md5sum \
| sed -e "s, ${ISO}, .," \


+ 1
- 1
config View File

@@ -1,7 +1,7 @@
#!/bin/bash

if [ -z "$BUILD_CONFIG" ] ; then
export BUILD_CONFIG=16.04.1
export BUILD_CONFIG=20.04.1
echo "No BUILD_CONFIG set -- assuming $BUILD_CONFIG"
fi



config-16.04.1 → config-20.04.1 View File

@@ -1,7 +1,7 @@
# -*- sh -*-

# output image
VERSION="16.04.1"
VERSION="20.04.1"
OUTPUT="nilmbuntu-${VERSION}.iso"

# original ISO

+ 11
- 8
customize.sh View File

@@ -15,18 +15,19 @@ echo "NILMbuntu $VERSION" > ${ISO}/.disk/info

# Set up preseed file by appending preseed.cfg to the Xubuntu
# default one
cat ${ISO}/preseed/xubuntu.seed preseed.cfg > ${ISO}/preseed/nilmbuntu.seed
cat ${ISO}/preseed/xubuntu.seed files/preseed.cfg > ${ISO}/preseed/nilmbuntu.seed

# Set up isolinux how we want by editing its config
TRY="Boot ^NILMbuntu ${VERSION}"
cp splash.png ${ISO}/isolinux/splash.png
cp files/splash.png ${ISO}/isolinux/splash.png
perl -n -i \
-e '$n=1 if /^label/; $n=2 if /^label live-install/; next if $n==2;' \
-e "s/menu label.*(Try|NILM).*/menu label $TRY/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmbuntu.seed,g;" \
-e "s/menu label.*Try Xubuntu without installing/menu label $TRY/g;" \
-e "s,presee/.*[.]seed,preseed/nilmbuntu.seed,g;" \
-e "s/ quiet splash//g;" \
-e "print;" \
${ISO}/isolinux/txt.cfg
perl -n -i -e "s/menu margin .*/menu margin 2/" ${ISO}/isolinux/menu.cfg
sed -i -s -e "s/^ui gfxboot/# ui gfxboot/g;" ${ISO}/isolinux/isolinux.cfg

# Set up grub similarly
@@ -34,18 +35,20 @@ TRY="Boot NILMbuntu ${VERSION}"
perl -n -i \
-e "next if /menuentry \"Install/../^}$/;" \
-e "next if /menuentry \"OEM install/../^}$/;" \
-e "s/menuentry \"(Try|NILM).*\" \{/menuentry \"${TRY}\" {/g;" \
-e "s/Try Xubuntu without installing/${TRY}/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmbuntu.seed,g;" \
-e "s/ quiet splash//g;" \
-e "print;" \
${ISO}/boot/grub/{grub,loopback}.cfg

sudo cp files/nilmbuntu.png ${FS}/usr/share/xfce4/backdrops/nilmbuntu.png
sudo cp files/customize-inner.sh ${FS}/root/customize-inner.sh
sudo install -D -m 0644 files/fallback_dns.conf ${FS}/etc/systemd/resolved.conf.d/fallback_dns.conf
sudo chmod +x ${FS}/root/customize-inner.sh

if ! [ "$1" == "skip" ] ; then

# Run the customize-inner.sh script inside the chroot
sudo cp nilmbuntu.png ${FS}/usr/share/xfce4/backdrops/nilmbuntu.png
sudo cp customize-inner.sh ${FS}/root/customize-inner.sh
sudo chmod +x ${FS}/root/customize-inner.sh
./enter.sh "cd /root ; ./customize-inner.sh"

fi

+ 6
- 21
enter.sh View File

@@ -26,10 +26,10 @@ setup_networking() {

# However, the current systemd-networkd from Debian is broken and
# won't enable masquerading -- so do it manually
IFACE=$(ip -4 route list default | head -1 | awk '{print $5}')
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -D POSTROUTING -o $IFACE -j MASQUERADE >/dev/null || true
iptables -t nat -A POSTROUTING -o $IFACE -j MASQUERADE
# IFACE=$(ip -4 route list default | head -1 | awk '{print $5}')
# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -D POSTROUTING -o $IFACE -j MASQUERADE >/dev/null || true
# iptables -t nat -A POSTROUTING -o $IFACE -j MASQUERADE
}

kill_container() {
@@ -102,18 +102,9 @@ set -e
setup_networking
start_container

run "resolvconf --disable-updates"
run "echo 'nameserver 8.8.8.8' > /run/resolvconf/resolv.conf"
run "echo '127.0.0.1 localhost' > /etc/hosts"
run "cat /etc/hosts.nilm >>/etc/hosts 2>/dev/null || true"
run "hostnamectl --transient set-hostname nilmbuntu"

#run "dbus-uuidgen > /var/lib/dbus/machine-id"
#run "dpkg-divert --local --rename --add /sbin/initctl"
#run "ln -sf /bin/true /sbin/initctl"
#run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
#run "ln -sf /bin/true /usr/sbin/update-grub"

set +e
if [ -z "$1" ] ; then
run "exec bash"
@@ -126,7 +117,8 @@ echo "Cleaning up..."
# Manually clean up some things that show up after booting an image
# and installing packages. This doesn't get everything, but what's
# left should be fine.
run "apt-get clean"
run "apt clean"
run "dpkg --clear-avail"
run "> /etc/machine-id"
run "rm -f /core /boot/grub/grubenv"
run "rm -f /var/lib/systemd/random-seed"
@@ -134,13 +126,6 @@ run "rm -f /var/lib/ubuntu-drivers-common/last_gfx_boot"
run "rm -f /var/lib/NetworkManager/*"
run "rm -f /root/.bash_history"

#run "rm /sbin/initctl"
#run "dpkg-divert --rename --remove /sbin/initctl"
#run "rm /usr/sbin/update-grub"
#run "dpkg-divert --rename --remove /usr/sbin/update-grub"
#run "rm /var/lib/dbus/machine-id"
#run "> /etc/resolv.conf"

kill_container

echo "Done"


customize-inner.sh → files/customize-inner.sh View File

@@ -44,7 +44,7 @@ for VER in $(ls --sort=version /lib/modules/) ; do
apt -y --purge remove "linux-.*$VER"
fi
done
apt -y --reinstall install linux-{,signed-}image-${LATEST_KERNEL}
apt -y --reinstall install linux-image-${LATEST_KERNEL}

# Disable upgrade popups
sed -i -s -e 's/Prompt=.*/Prompt=never/g' \
@@ -60,34 +60,16 @@ apt -y install postfix
# Required packages
apt -y install \
python3 \
python2.7 \
python2.7-dev \
python-setuptools \
python-pip \
cython \
python3-pip \
git \
build-essential \
python-cherrypy3 \
python-decorator \
python-simplejson \
python-requests \
python-dateutil \
python-tz \
python-progressbar \
python-psutil \
python-numpy \
python-nose \
python-coverage \
apache2 \
libapache2-mod-wsgi \
python-scipy \
python-daemon
libapache2-mod-wsgi

# Install other useful stuff
apt -y install \
adb \
avrdude \
chromium-browser \
curl \
debconf-utils \
devscripts \
@@ -96,14 +78,12 @@ apt -y install \
emacs \
emacs-goodies-el \
esptool \
firefox \
flashrom \
gcc-arm-none-eabi \
gcc-avr \
gdb-arm-none-eabi \
gddrescue \
gnuplot \
help2man \
ipython \
ipython3 \
libnewlib-arm-none-eabi \
libreoffice \
libstdc++-arm-none-eabi-newlib \
@@ -111,7 +91,6 @@ apt -y install \
mailutils \
moreutils \
mutt \
network-manager-openvpn-gnome \
octave \
octave-missing-functions \
octave-signal \
@@ -119,11 +98,8 @@ apt -y install \
openssh-server \
openssl \
openvpn \
python-matplotlib \
screen \
sigrok \
silversearcher-ag \
subversion \
tcpdump \
zip

@@ -149,43 +125,16 @@ apt -y install xmlstarlet
xmlstarlet ed -L -u "//property[@name='image-path']/@value" -v "$BG" $XML
xmlstarlet ed -L -u "//property[@name='image-style']/@value" -v "3" $XML

# Configure Firefox with our default homepage (now irrelevant since
# it won't be the default browser)
HOMEPAGE="http://www.wattsworth.net/"
cat >/etc/firefox/syspref.js <<EOF
pref("browser.startup.homepage", "${HOMEPAGE}");
pref("extensions.ubufox@ubuntu.com.custom_homepage", "${HOMEPAGE}");
pref("browser.startup.homepage_override.mstone", "ignore");
EOF
# Get Chrome
wget -O chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i chrome.deb

# Set up Chromium as default browser
update-alternatives --set x-www-browser /usr/bin/chromium-browser
update-alternatives --set gnome-www-browser /usr/bin/chromium-browser
mkdir -p /etc/skel/.config/xfce4
cat >/etc/skel/.config/xfce4/helpers.rc <<"EOF"
WebBrowser=chromium-browser
EOF
mkdir -p /etc/skel/.local/share/xfce4/helpers
cat >/etc/skel/.local/share/xfce4/helpers/chromium-browser.desktop <<"EOF"
[Desktop Entry]
Version=1.0
Name=Chromium Web Browser
X-XFCE-Category=WebBrowser
X-XFCE-Commands=chromium-browser
X-XFCE-CommandsWithParameter=chromium-browser "%s"
Exec=chromium-browser %U
Type=X-XFCE-Helper
Icon=chromium-browser
MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
EOF

# Make Chromium a little nicer:
# Make Chrome a little nicer:
# - No first run
mkdir -p /etc/skel/.config/chromium/Default
touch '/etc/skel/.config/chromium/First Run'
mkdir -p /etc/skel/.config/google-chrome/Default
touch '/etc/skel/.config/google-chrome/First Run'
# - Set up some default bookmarks on the bookmark bar
cat >/etc/skel/.config/chromium/Default/Bookmarks <<"EOF"
cat >/etc/skel/.config/google-chrome/Default/Bookmarks <<"EOF"
{ "version": 1, "roots": {
"other": { "id": "2", "name": "Other bookmarks", "type": "folder",
"children": [ ] },
@@ -195,7 +144,7 @@ cat >/etc/skel/.config/chromium/Default/Bookmarks <<"EOF"
"children": [ {
"id": "6", "type": "url",
"name": "Wattsworth",
"url": "http://www.wattsworth.net/"
"url": "https://www.wattsworth.net/"
}, {
"id": "7", "type": "url",
"name": "Standalone NILM",
@@ -217,5 +166,11 @@ fi
/etc/cron.daily/mlocate
/etc/cron.daily/dlocate

# Make sure initramfs was regenerated with casper changes
# Make sure initramfs was regenerated with casper changes.
# Manipulate some config files to avoid host stuff leaking through.
echo 'RESUME=none' > /etc/initramfs-tools/conf.d/resume
mv /etc/crypttab /etc/crypttab-old
update-initramfs -u
rm /etc/initramfs-tools/conf.d/resume
mv /etc/crypttab-old /etc/crypttab


+ 2
- 0
files/fallback_dns.conf View File

@@ -0,0 +1,2 @@
[Resolve]
FallbackDNS=1.1.1.1 9.9.9.10 8.8.8.8 2606:4700:4700::1111 2620:fe::10 2001:4860:4860::8888

nilmbuntu.png → files/nilmbuntu.png View File


preseed.cfg → files/preseed.cfg View File


splash.png → files/splash.png View File


+ 3
- 1
run.sh View File

@@ -47,10 +47,12 @@ set -x

cfg=""

cfg+=" -nodefaults"
cfg+=" -drive file=${DISK},media=disk,format=raw,if=virtio"
cfg+=" -enable-kvm"
cfg+=" -m 2048"
cfg+=" -usbdevice tablet"
cfg+=" -usb"
cfg+=" -device usb-tablet"

cfg+=" -vga vmware"
#cfg+=" -vnc :0"


Loading…
Cancel
Save