joelandman / nyble

nlytiq base linux environment: build diskless/pxe bootable rambooting images for Debian, Ubuntu, CentOS
Apache License 2.0
22 stars 4 forks source link

Readme.md - distro list #9

Open luxzg opened 5 months ago

luxzg commented 5 months ago

Hi there! Stumbled on your project, and I'm about to try it to see if it could help in my case...

Anyway, readme says:

DISTRO : which distribution you will use as the base of your image. Current choices are debian9, debian10, ubuntu18.04, ubuntu20.04, and centos7. Centos8 is in process.

While the code and latest commits have Debian 11 and even 12, and seems 9 was deprecated. I see files for Rocky as well. If true, readme should probably reflect that.

Likewise, any plans for supporting newer Ubuntu, or you've decided to focus on Debian and REHL-based distros? This isn't a deal breaker, just something I am curious about.

Thanks!

luxzg commented 5 months ago

So I don't open another issue... maybe update procedure with a more hand holding ;D

I am doing this on fresh VM Debian 12.5 minimal install, and so far I also needed:

First two are obvious, but debootstrap only threw error when I started the build process. Maybe add it to requirements for Debian builds?

Edit:

+ GOTAR=go1.20.4.linux-amd64.tar.gz
+ tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz
gzip: skipping: <stdin> unrecognized format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
....
....
checking: host Go compiler (at least version 1.17)... not found!
mconfig: could not complete configuration
make[1]: *** [Makefile:30: singularity.complete] Error 1
make[1]: Leaving directory '/home/administrator/nyble/nyble/packages'
make: *** [OS/debian12/config.conf:324: fb_packages] Error 2

I'll take that as Go compiler is also needed

wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin go version

Actually strike that, seems something is interrupting tar/gzip unpacking.. will try manually to debug. I've added piece of error code I found higher up. I tried unzipping manually but same error. Maybe file is corrupt, checking now. Ah damnit, file is 134 bytes, that explains it.

Seems that git didn't copy the file from repo, instead putting some text file in its place. I went to /nyble/packages/singularity and replaced the file manually

wget https://go.dev/dl/go1.20.4.linux-amd64.tar.gz

But same happened with v3.11.4.tar.gz unsure what's that. I'll wget it from the repo just in case.

wget https://github.com/joelandman/nyble/raw/master/packages/singularity/v3.11.4.tar.gz
luxzg commented 5 months ago

I am not sure if I am doing something wrong, but seems that if I use PACKAGES=0 or ONLYCORE=1 (which should set packages to zero), script still goes through installing packages, and my image gets bloated.

I looked through the code, and it seems to me that the packages don't have any if/then (I could be wrong though, I'm not a pro dev or anything).

I keep getting images in range of 1.5-1.7GB while I expect about a third of that. When I run debootstrap and apt install manually to separate chroot, and cpio it all I get about 600-700MB archive.

When I comment out apt/install blocks I don't need in your script, and modify debootstrap and first apt install lines to match what I manually did in separate chroot, and run the make, I get about 1.5G.

I will try to adjust script to skip the packages and its make, to see what happens. Since I don't need Nvidia or Mellanox, that alone should be 500+MB less.

Btw I am trying to use your script to make a really minimal image of Debian 12, if I succeed, I will try to fork the project on GitHub and make changes on my fork, so the work is preserved.

Btw, sorry for messy issue, I didn't want to spam you with 5 separate issues, when half of it could be my own fault, as I learn the ropes... If you get some time to point me to any "secrets", I'd be most thankful. Cheers!

luxzg commented 5 months ago

Sorry closed by mistake 🙈

joelandman commented 5 months ago

Apologies on the delay in response. To try to answer the distro questions, yes, I plan to add Ubuntu 22.04 and when it comes out 24.04. Rocky 9 should work, Rocky 8 will be added. Centos generally will be deprecated. Debian 12 is working.

joelandman commented 5 months ago

On the other points, yes, documentation has lagged. Background project for me, unrelated to my normal workloads.

Feel free to fork, and if you wish, feel free to send in PRs.

luxzg commented 5 months ago

Ok thanks, I'll try to find my way around, if I succeed in building satisfying image, I'll try to make a new type of OS profile and try to make it a PR. I'm not a dev but I hope I'll manage 🙈

luxzg commented 5 months ago

I think I have found why PACKAGES option isn't working as expected.

Inside config.conf near the very end there's block fb_packages: which contains line cd packages ; $(MAKE) all. I believe this should be something like:

ifeq ($(PACKAGES),1)
        cd packages ; $(MAKE) all
endif

For now I have just commented the line instead adding "if" to see if my image ends up smaller.

luxzg commented 5 months ago

Just to confirm, I have successfully made much smaller image after commending out that line.

So the if/endif should check for PACKAGES variable, and if set to 1 should proceed with packages/Make and if set to 0 should continue without packages. That would also fix the ONLYCORE option which didn't work for the same reason. I tried on Debian 12 image (configs), but I see that all the other configs look the same.

Quick info about my image:

I will be working more on this at a later date, it was just important for me to know it is doable and usable, and it is - THANK YOU!

The following is a really short how-to. Please anyone trying this out, be aware this is only proof of concept, and is NOT a finished script.

Prerequisite - Debian 12 VM, minimal install, no GUI required, just networking, 20GB disk (I used 200GB but in reality VHD never passed 30GB even with multiple retries and all), and 32GB virtual RAM assigned (required because image is built inside RAM).

My examples are with the user administrator and using its home/administrator directory for everything.

After setting up OS of the building environment, make sure to install tools and update OS, then clone this repo:

apt update
apt upgrade
apt install make
apt install debootstrap
apt install git
apt autoremove
mkdir /home/administrator/nyble
cd /home/administrator/nyble/
git clone https://github.com/joelandman/nyble

Next you need to modify the configs and scripts. First one is Debian base config:

nano /home/administrator/nyble/nyble/OS/debian12/base.conf

Delete everything from line osinst_base: ramdisk_build_1 to line # missing: pxz linux-tools and instead put this block of code:

osinst_base: ramdisk_build_1
        # base
        debootstrap --arch amd64 --variant=minbase \
                --include=ca-certificates,apt,apt-transport-https \
                bookworm \
                ${TARGET} \
                ${BASE_OS}
# --keyring OS/${DISTRO}/debian-archive-keyring.gpg

        # core
        export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y \
                update

        export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y \
                install --no-install-suggests --no-install-recommends -y xserver-xorg-core

        export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y \
                install --no-install-suggests --no-install-recommends -y openbox

        export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y \
                install --no-install-suggests --no-install-recommends -y chromium

        export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y \
                install resolvconf cron ifupdown openssh-server sudo locales \
                initramfs-tools gawk gzip zip unzip pigz mdadm pbzip2 zstd \
                rsync less lsb-release scrot x11vnc unzip iproute2 nano xinit \
                binutils curl wget bash coreutils lbzip2

# missing: pxz linux-tools

Inside same file comment out everything starting with export DEBIAN_FRONTEND ... apt-get -y install but keep all the existing echo and touch commands that go before/after these apt lines. Here's one commented block as an example:

osinst_fs: osinst_base osinst_bind
        # core environment: file systems
        echo "+++ in fs "
#       export DEBIAN_FRONTEND=noninteractive ; chroot ${TARGET} apt-get -y  \
#       --fix-missing install xfsprogs xfsdump e2fsprogs     \
#       nfs-kernel-server nfs-ganesha nfswatch fuse libaio-dev

        touch osinst_fs

Keep in mind that apt-get commands are multiline, so you need to read the code and comment out all the lines that are part of that command.

There's total of 9 blocks to comment out, and one is already commented originally:

Next file to edit is:

nano /home/administrator/nyble/nyble/OS/debian12/config.conf

Search the file for the line starting with echo "nyble:nyble" and right after it add this block to make a new user open with password open, autologin, and browser autostart:

    # add user open
    chroot ${TARGET} useradd -m open -s '/bin/bash'
    echo "open:open" | chroot ${TARGET} chpasswd
    chroot ${TARGET} usermod -aG adm open
    chroot ${TARGET} usermod -aG sudo open

    # autostart and autologin with user open
    echo "" > ${TARGET}/home/open/.profile
    echo '#Startx Automatically' >> ${TARGET}/home/open/.profile
    echo 'if [ -z "$DISPLAY" ] && [ $(tty) = /dev/tty1 ]; then' >> ${TARGET}/home/open/.profile
    echo "  . startx" >> ${TARGET}/home/open/.profile
    echo "  logout" >> ${TARGET}/home/open/.profile
    echo "fi" >> ${TARGET}/home/open/.profile

    echo '#!/bin/bash' > ${TARGET}/home/open/.xinitrc
    echo "xset -dpms" >> ${TARGET}/home/open/.xinitrc
    echo "xset s off" >> ${TARGET}/home/open/.xinitrc
    echo "xset s noblank" >> ${TARGET}/home/open/.xinitrc
    echo "chromium https://www.bing.com --window-size=1920,1080 --start-fullscreen --kiosk --incognito --no-touch-pinch --noerrdialogs --disable-crash-reporter --disable-session-crashed-bubble --disable-translate --no-first-run --fast --fast-start --disable-infobars --disable-features=TranslateUI --disk-cache-dir=/dev/null --password-store=basic &" >> ${TARGET}/home/open/.xinitrc
    echo "DISPLAY=:0 x11vnc" >> ${TARGET}/home/open/.xinitrc

    mkdir -p ${TARGET}/etc/systemd/system/getty@tty1.service.d/
    echo "[Service]" > ${TARGET}/etc/systemd/system/getty@tty1.service.d/override.conf
    echo "Type=simple" >> ${TARGET}/etc/systemd/system/getty@tty1.service.d/override.conf
    echo "ExecStart=" >> ${TARGET}/etc/systemd/system/getty@tty1.service.d/override.conf
    echo "ExecStart=-/sbin/agetty --autologin open --noclear %I 38400 linux" >> ${TARGET}/etc/systemd/system/getty@tty1.service.d/override.conf

Inside same file look near the end for the line `cd packages ; $(MAKE) all`` and comment it out like so to skip Mellanox, Nvidia, and other packages:

#       cd packages ; $(MAKE) all

Next file to edit is:

nano /home/administrator/nyble/nyble/OS/debian12/tools.hook

Inside this file we just need to comment out the following rows, because we didn't install those tools, and the script will error out unless we comment them out:

...
#copy_exec /sbin/ethtool /sbin
...
#copy_exec /sbin/mount.nfs /sbin
#copy_exec /usr/sbin/showmount /usr/sbin
...
#copy_exec /usr/bin/xz /bin
#copy_exec /usr/bin/ldd /bin
...

Just add # in front of those lines, do not comment out other stuff.

And finally, though it does not have an effect right now... open this config:

nano /home/administrator/nyble/nyble/config/all.conf

And inside it change the line forcing packages to be skipped:

# packages installed or not
PACKAGES?=0

You can save these 4 files for later, if you will need to start from scratch by deleting whole nyble directory and starting from git clone. This is completely optional.

cp /home/administrator/nyble/nyble/OS/debian12/config.conf /home/administrator
cp /home/administrator/nyble/nyble/OS/debian12/base.conf /home/administrator
cp /home/administrator/nyble/nyble/OS/debian12/tools.hook /home/administrator
cp /home/administrator/nyble/nyble/config/all.conf /home/administrator

Now you're ready to build the kiosk. Make sure you're in the right dir and run make for correct OS:

cd /home/administrator/nyble/nyble
make DISTRO=debian12

Note: I intend to later make this a separate "OS" config so people can build something like DISTRO=debian12kiosk but as we're using debian12 files and configs, we're currently running make like above.

When this build was done this was the result:

ls -alh /mnt/root/boot/
...
739M Apr 16 04:23 initramfs-ramboot-6.1.0-20-amd64
...
7.8M Apr 11 17:17 vmlinuz-6.1.0-20-amd64
...

Next I copied these files from /mnt/root/boot/ to my PXE server, added it to the HTTP boot folder (on webserver, folder /boot/6.1.0-20-amd64 in my case), and modified my PXE files. I'm using syslinux on UEFI hardware, so I've edited \Boot\syslinuxuefi64\pxelinux.cfg\default and added the following default block to the menu:

LABEL Debian12Kiosk
    MENU LABEL Boot Debian 12 Kiosk
    MENU DEFAULT
    KERNEL http://my.server.local/boot/6.1.0-20-amd64/vmlinuz-6.1.0-20-amd64 root=ram rootfstype=ramdisk ramdisksize=8 simplenet=1 udev.children-max=1 verbose
    APPEND initrd=http://my.server.local/boot/6.1.0-20-amd64/initramfs-ramboot-6.1.0-20-amd64

Make sure to just use those two files, do NOT append the initrd.img... file as it will break the boot sequence.

Reboot your hardware client, and it should boot Debian "kiosk" image. Note: I just have one little snag right now, after boot it does not run Xorg server, so I had to write "startx" in the prompt to force the X to start. But the browser was immediately there, on correct web page, in the kiosk mode, and everything.

Again, big thanks to @joelandman for these scripts!

P.S. This way I spent 3 days on making it this far, otherwise I'd probably give up after wasting way way more time :-)