Hi,
Topic 3 : basic complete configuration of chroot
Select target where you install chroot :
==== ATTENTION all command or script MUST be executed as root (or admin prefixed by sudo)
Target 1 :
… use bash in chroot to start an X11 interface (even less … just a software)
… this require minimum install, BUT you must manage ALL services needed by yourself and start environment.
… EACH time you add a software, you must complete the services required.
… Namespace is the best envelope … NO network require .. managed and configured by ADM (don’t start network manager to avoid problems) … Ex. interface name can be changed … so ALL works but ADM WebUI can’t be used any more … etc. etc.
Target 2 :
… use systemd … so Ubuntu is started using /sbin/init AS ANY standard environment.
… require a namespace for security (PID, IPC, Mount)
… VERY documented … all services (in good order) are automatically started, systemd log is provide to debug any problem.
… AS for previous … don’t manage network from inside the namespace
… swap device can be removed if a shutdown in namespace is done (shell to recreate it will be provide later)
… for low memory (less 2GB … better is 4 to nnn GB), please increase swap by adding swap file (a shell will be provide for BTRFS support (special method)
=== ATTENTION for running complete system in namespace … systemd require that chroot folder MUST BE a mountpoint
Solution :
use a specific share in ADM (reserved to admin) … but untar require a specific parameter
use ANY folder in any share (include folder in tar) … but you must mount it on itself to create a mountpoint.
[EDIT] add owner to root:root of target directory (just in code hereafter) NO recursively just base folder.
# example using a share folder created in ADM
chown root:root /share/CHROOT_BASE_FOLDER
cd /share/CHROOT_BASE_FOLDER
tar -xz --strip-components=1 -f /share/development/xxxx/2404_LTS_arm64.tgz
### --strip-components=1 permit to put all Ubuntu root directly in share as root (bypass folder name in tar
NEXT STEP : install all part to complete chroot.
SPECIAL in case of foreign architecture (chroot create in x86_64 for arm64 for ex.)
### exec debootstrap second-stage for FOREIGN arch.
chroot /share/CHROOT_BASE_FOLDER /debootstrap/debootstrap --second-stage
## COPY require network file
## network (please redo it if any change in ADM network
cp /etc/hosts /etc/resolv.conf /share/CHROOT_BASE_FOLDER/etc/
Create the APT (package manager for Ubuntu) file sources in new format (or old sources.list if you prefer) … using new format require to rename or remove /etc/apt/sources.list to avoid conflicts.
example for ARM64 … file to create /etc/apt/sourves.list.d/ubuntu.sources
# cat ubuntu.sources
Types: deb deb-src
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble noble-updates noble-backports noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb deb-src
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
… deb is enough if you don’t compile or create new software … so just remove dec-src un Types: line
example for x86_64
# cat ubuntu.sources
Types: deb deb-src
URIs: http://fr.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb deb-src
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
… same for deb-src and select a country near you (even fr works for all)
Last create a shell script to mount mandatory file system in namespace / chroot
cd /share/CHROOT_BASE_FOLDER
create an empty file to check if you run in chroot
touch u2404
create executable file (or copy hereafter) file as root folder (/ in chroot /share/CHROOT_BASE_FOLDER in ADM) like this
# cat start_up.sh
#!/bin/sh
test_in(){
if [ -e /u2404 ] ; then
echo "you are in the chroot ... continue"
else
echo "please enter in the chroot before start stop"
exit 1
fi
}
case "$1" in
mount)
test_in
mount -t devtmpfs udev /dev
if [ ! -e /dev/pts ] ; then
mkdir /dev/pts
fi
mount -t devpts devpts /dev/pts
# udevadm trigger
mount -t proc proc /proc
mount -t sysfs sys /sys
# mount -t tmpfs none /run/shm
;;
umount)
test_in
# umount /run/shm
umount /sys
umount /dev/pts
umount /dev
umount /proc
;;
*)
echo "Usage : $0 mount|umount"
;;
esac
don’t forgot to do :
chmod +x start_up.sh (executable)
LAST initial step :
[EDIT] create empty link to avoid conflict with entware or others.
… it’s time to test the chroot and update Ubuntu to last upgrade.
Now we have just to start chroot and use Ubuntu package manager, also just configure TimeZone and have correct langage set;
- enter in chroot
… as root or admin + sudo in ADM
chroot /share/CHROOT_BASE_FOLDER /bin/bash
… ignore LANG warning for now
… you are in chroot so PATH is NOT the ADM one directly /
… mount necessary folder IN CHROOT to run
/start_up.sh mount
… verify :
mount
… generate LANG for avoid warning
locale-gen “en_US.UTF-8”
… set time_zone … select continent then town near you
dpkg-reconfigure tzdata
… for me in France I select Europe then Paris
… create LINK for conflict due to the environment
ln -sf /tmp /opt/tmp
mkdir -p /opt/share
ln -sf /usr/share/terminfo /opt/share/terminfo
… upgrade Ubuntu
… get source for software
apt-get update
… if you see a list of repository and NO error at end … IT’S OK
… upgrade
apt-get -y dist-upgrade
… at end you are up to date … and ready for next step INSTALL SOFTWARE NEED by X11 Applications
Continued in the next topic
… eventually quit chroot after unmounting system folder and save it (tar)
/start_up.sh umount
exit
HOW do a save of Ubuntu chroot with winning space …
… when you use apt, a list of package and some package are loaded locally … this used large space (increase with added software)
… it’s possible to solve this by cleaning APT cache and list (ignore warning due to sub_folder)
… here command as root in ADM
rm -f /share/CHROOT_BASE_FOLDER/var/cache/apt/archives/*
rm -f /share/CHROOT_BASE_FOLDER/var/cache/apt/.bin
rm -f /share/CHROOT_BASE_FOLDER/var/lib/apt/lists/
ALL this list and package will by reloaded after an apt-get update later
Philippe.