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'

    EOF

    zone=Europe/Moscow

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
    EOF

# 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
    EOF

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
    127.0.0.1       localhost

    192.168.122.1   gw
    192.168.122.9   $guest

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

    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
            address 192.168.122.9/24
            gateway 192.168.122.1

EOF

moar options

            #dns-nameservers 208.67.222.222 208.67.220.220
            #dns-nameservers 62.210.16.6 62.210.16.7
            #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

    echo nameserver 192.168.122.1 > lala/etc/resolv.conf

    echo nameserver 208.67.222.222 > lala/etc/resolv.conf
    echo nameserver 208.67.222.220 >> lala/etc/resolv.conf

ls -lF lala/etc/resolv.conf*

chroot

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 \
            bash-completion

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

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

finally exit the chroot

    updatedb
history -c
    ^D

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