system setup

ls -lF lala/etc/hostname # no exist
    echo $guest > lala/etc/hostname

To make Perl packages happy, you need to tweak bash.bashrc, not profile

    cp -pi lala/etc/bash.bashrc lala/etc/bash.bashrc.dist
    cat >> lala/etc/bash.bashrc <<-EOF

source /usr/share/bash-completion/bash_completion

    export LANGUAGE="en_US:en"
    export LC_ALL="C.UTF-8"
    export LC_COLLATE="C.UTF-8"
    export LANG="C.UTF-8"

    alias ll='ls --group-directories-first --color=auto -alh'
    alias ls='ls --group-directories-first --color=auto'
    alias cp='cp -i'
    alias mv='mv -i'
    alias rm='rm -i'



ls -lF lala/etc/localtime
    ln -sf ../usr/share/zoneinfo/$zone lala/etc/localtime

cat lala/etc/timezone
    echo $zone > lala/etc/timezone # override

point to the closest mirror

    cat lala/etc/apt/sources.list
# ubuntu
    cat > lala/etc/apt/sources.list <<-EOF
    deb $mirror $guest main restricted universe multiverse
    deb $mirror $guest-updates main restricted universe multiverse
    deb $mirror $guest-security main restricted universe multiverse
    #deb $mirror $guest-backports main restricted universe multiverse

# debian
    cat > lala/etc/apt/sources.list <<-EOF
    deb $mirror $guest main contrib non-free
    deb $mirror $guest-updates main contrib non-free
    # $guest-backports

eventually setup a package proxy

    vi lala/etc/apt/apt.conf.d/02proxy

    Acquire::http { Proxy "http://x.x.x.x:3142"; };

network setup

    mv lala/etc/hosts lala/etc/hosts.dist
    cat > lala/etc/hosts <<-EOF       localhost   gw   $guest

    ::1             localhost ip6-localhost ip6-loopback
    ff02::1         ip6-allnodes
    ff02::2         ip6-allrouters

    rmdir lala/etc/network/interfaces.d/
    cat > lala/etc/network/interfaces <<-EOF # override
    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet static


moar options

            #dns-search DOMAIN.TLD

we use our own stub-resolver

cat lala/etc/resolv.conf
    mv lala/etc/resolv.conf lala/etc/resolv.conf.dist

# kvm
    echo nameserver > lala/etc/resolv.conf

# dedibox
echo > lala/etc/resolv.conf
echo >> lala/etc/resolv.conf

# opendns
    echo nameserver > lala/etc/resolv.conf
    echo nameserver >> lala/etc/resolv.conf

ls -lF lala/etc/resolv.conf*


now let’s proceed with the insider stuff

    mount -o bind /dev/pts lala/dev/pts
    mount -o bind /proc lala/proc # rsyslog:systemd-tmpfiles
    chroot lala/ bash

    perl -e exit

console requires a password unless you tweak getty like hell – disabling it instead

    passwd -d root
    #usermod -p '*' root

tune the guest userland serial console

    systemctl get-default
    systemctl set-default multi-user

# kvm-only
    #systemctl enable serial-getty@ttyS0.service

No NTP is required, this is a guest system

dpkg -l | grep ntp # not installed
    systemctl list-unit-files | grep ntp # not present

    # ubuntu
    systemctl disable systemd-timesyncd

also disable the stub-on-steroids

# not in use anymore
dpkg -l | grep resolv
    systemctl list-unit-files | grep resolv

systemctl disable systemd-resolved 

perform a system upgrade before making a template out of it

    export DEBIAN_FRONTEND=noninteractive
    apt update
    apt dist-upgrade
apt autoremove --purge

you might also want those additional packages

    apt install \
            ifupdown \
            net-tools \
            man-db \
            manpages \
            openssh-server \
            openssh-client \
            mlocate \
            wget \
            elvis-tiny \

ls -lF /usr/share/bash-completion/bash_completion

    #bsd-mailx would install postfix of exim
    #ls -lF /etc/postfix/
    #ls -lF /etc/exim4/

finally exit the chroot

history -c

we’re done!

rm -f lala/root/.bash_history
    umount -R lala/
    rmdir lala/
    du -sh $guest.btrfs
# 948M    jammy.btrfs w/ lzo
# 990M    bullseye.btrfs