diff --git a/README b/README.md similarity index 53% rename from README rename to README.md index 83b3817..530bc8d 100644 --- a/README +++ b/README.md @@ -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 diff --git a/buildiso.sh b/buildiso.sh index b8fdd8e..b488098 100755 --- a/buildiso.sh +++ b/buildiso.sh @@ -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}, .," \ diff --git a/config b/config index 511e950..19708f7 100644 --- a/config +++ b/config @@ -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 diff --git a/config-16.04.1 b/config-20.04.1 similarity index 96% rename from config-16.04.1 rename to config-20.04.1 index fb06059..88cfb6d 100644 --- a/config-16.04.1 +++ b/config-20.04.1 @@ -1,7 +1,7 @@ # -*- sh -*- # output image -VERSION="16.04.1" +VERSION="20.04.1" OUTPUT="nilmbuntu-${VERSION}.iso" # original ISO diff --git a/customize.sh b/customize.sh index 07d632c..350e469 100755 --- a/customize.sh +++ b/customize.sh @@ -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 diff --git a/enter.sh b/enter.sh index 8af17de..9f5c6f7 100755 --- a/enter.sh +++ b/enter.sh @@ -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" diff --git a/customize-inner.sh b/files/customize-inner.sh similarity index 68% rename from customize-inner.sh rename to files/customize-inner.sh index d3853b8..cb7616e 100644 --- a/customize-inner.sh +++ b/files/customize-inner.sh @@ -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 </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 + diff --git a/files/fallback_dns.conf b/files/fallback_dns.conf new file mode 100644 index 0000000..157eb5d --- /dev/null +++ b/files/fallback_dns.conf @@ -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 diff --git a/nilmbuntu.png b/files/nilmbuntu.png similarity index 100% rename from nilmbuntu.png rename to files/nilmbuntu.png diff --git a/preseed.cfg b/files/preseed.cfg similarity index 100% rename from preseed.cfg rename to files/preseed.cfg diff --git a/splash.png b/files/splash.png similarity index 100% rename from splash.png rename to files/splash.png diff --git a/run.sh b/run.sh index 54729e4..620794c 100755 --- a/run.sh +++ b/run.sh @@ -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"