Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image compression #992

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ arch-chroot ${BUILD_PATH} /bin/bash <<EOF
set -e
set -x

# This will prevent frzr bootloader from erroring when installing kernels
# due to the pacman hook being executed at kernel-install time
export FRZR_IMAGE_GENERATION=1

source /manifest

pacman-key --populate
Expand All @@ -94,6 +98,9 @@ sed -i '/CheckSpace/s/^/#/g' /etc/pacman.conf
# update package databases
pacman --noconfirm -Syy

# Avoid mkintcpio being auto-installed while installing the kernel (we want dracut)
pacman -S --noconfirm dracut

# install kernel package
if [ "$KERNEL_PACKAGE_ORIGIN" == "local" ] ; then
pacman --noconfirm -U --overwrite '*' \
Expand Down Expand Up @@ -131,9 +138,12 @@ systemctl --global enable ${USER_SERVICES}
# disable root login
passwd --lock root

# add root to the frzr group
sudo usermod -a -G frzr root

# create user
groupadd -r autologin
useradd -m ${USERNAME} -G autologin,wheel,plugdev
useradd -m ${USERNAME} -G autologin,wheel,plugdev,frzr
echo "${USERNAME}:${USERNAME}" | chpasswd

# set the default editor, so visudo works
Expand All @@ -158,11 +168,15 @@ PrintMotd no # pam does that
Subsystem sftp /usr/lib/ssh/sftp-server
" > /etc/ssh/sshd_config

# Write the fstab file
# WARNING: mounting partitions using LABEL exposes us to a bug where multiple disks cannot have frzr systems and how to solve this still is an open question
echo "
LABEL=frzr_root /var btrfs defaults,subvolid=256,rw,noatime,nodatacow,nofail 0 0
LABEL=frzr_root /home btrfs defaults,subvolid=257,rw,noatime,nodatacow,nofail 0 0
LABEL=frzr_root /frzr_root btrfs defaults,subvolid=5,rw,noatime,nodatacow,x-initrd.mount 0 2
overlay /etc overlay defaults,x-systemd.requires-mounts-for=/frzr_root,x-systemd.requires-mounts-for=/sysroot/frzr_root,x-systemd.rw-only,lowerdir=/sysroot/etc,upperdir=/sysroot/frzr_root/etc,workdir=/sysroot/frzr_root/.etc,index=off,metacopy=off,comment=etcoverlay,x-initrd.mount 0 0
LABEL=frzr_root /frzr_root btrfs defaults,x-initrd.mount,subvolid=5,rw,noatime,nodatacow 0 2
LABEL=frzr_root /home btrfs defaults,x-systemd.rw-only,subvol=/home,rw,noatime,nodatacow,nofail 0 0
overlay /boot overlay defaults,x-systemd.requires-mounts-for=/frzr_root,x-systemd.requires-mounts-for=/sysroot/frzr_root,x-initrd.mount,lowerdir=/sysroot/frzr_root/kernels/boot:/sysroot/frzr_root/device_quirks/${SYSTEM_NAME}-${VERSION}/boot:/sysroot/boot,upperdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/boot_overlay/upperdir,workdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/boot_overlay/workdir,index=off,metacopy=off,xino=off,redirect_dir=off,comment=bootoverlay 0 0
overlay /usr overlay defaults,x-systemd.requires-mounts-for=/frzr_root,x-systemd.requires-mounts-for=/sysroot/frzr_root,x-initrd.mount,lowerdir=/sysroot/frzr_root/kernels/usr:/sysroot/frzr_root/device_quirks/${SYSTEM_NAME}-${VERSION}/usr:/sysroot/usr,upperdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/usr_overlay/upperdir,workdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/usr_overlay/workdir,index=off,metacopy=off,xino=off,redirect_dir=off,comment=usroverlay 0 0
overlay /etc overlay defaults,x-systemd.requires-mounts-for=/frzr_root,x-systemd.requires-mounts-for=/sysroot/frzr_root,x-initrd.mount,x-systemd.rw-only,lowerdir=/sysroot/frzr_root/kernels/etc:/sysroot/frzr_root/device_quirks/${SYSTEM_NAME}-${VERSION}/etc:/sysroot/etc,upperdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/etc_overlay/upperdir,workdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/etc_overlay/workdir,index=off,metacopy=off,xino=off,redirect_dir=off,comment=etcoverlay 0 0
overlay /var overlay defaults,x-systemd.requires-mounts-for=/frzr_root,x-systemd.requires-mounts-for=/sysroot/frzr_root,x-initrd.mount,x-systemd.rw-only,lowerdir=/sysroot/frzr_root/kernels/var:/sysroot/frzr_root/device_quirks/${SYSTEM_NAME}-${VERSION}/var:/sysroot/var,upperdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/var_overlay/upperdir,workdir=/sysroot/frzr_root/deployments_data/${SYSTEM_NAME}-${VERSION}/var_overlay/workdir,index=off,metacopy=off,xino=off,redirect_dir=off,comment=varoverlay 0 0
" > /etc/fstab

echo "
Expand Down Expand Up @@ -195,30 +209,45 @@ pacman -Q > /manifest

# preserve installed package database
mkdir -p /usr/var/lib/pacman
cp -r /var/lib/pacman/local /usr/var/lib/pacman/
cp -a /var/lib/pacman/local /usr/var/lib/pacman/

# move kernel image and initrd to a defualt location if "linux" is not used
if [ ${KERNEL_PACKAGE} != 'linux' ] ; then
mv /boot/vmlinuz-${KERNEL_PACKAGE} /boot/vmlinuz-linux
mv /boot/initramfs-${KERNEL_PACKAGE}.img /boot/initramfs-linux.img
mv /boot/initramfs-${KERNEL_PACKAGE}-fallback.img /boot/initramfs-linux-fallback.img
# Remove the fallback: it is never used and takes up space
if [ -e "/boot/initramfs-${KERNEL_PACKAGE}-fallback.img" ]; then
rm "/boot/initramfs-${KERNEL_PACKAGE}-fallback.img"
fi

# Since frzr pre-v1.0.0 has an hardcoded cp of /boot/vmlinuz-linux and /boot/initramfs-linux.img
# create two empty files so that the cp command won't fail: these will be replaced by a migration hook.
#
# Note: The following is kept for compatibility with older frzr
# This can safely be removed when the compatibility with
# frzr pre-v1.0.0 will be dropped
if [ "${KERNEL_PACKAGE}" = "linux" ]; then
echo "Kernel is named 'linux' nothing to do."
else
touch /boot/vmlinuz-linux
touch /boot/initramfs-linux.img
fi

# clean up/remove unnecessary files
# Keep every file in /var except for logs (populated by GitHub CI)
# the pacman database: it was backed up to another location and
# will be restored by an unlock hook
rm -rf \
/own_pkgs \
/extra_pkgs \
/extra_certs \
/home \
/var \
/var/log \
/var/lib/pacman/local \

rm -rf ${FILES_TO_DELETE}

# create necessary directories
mkdir -p /home
mkdir -p /var
mkdir -p /frzr_root
mkdir -p /efi
mkdir -p /var/log
EOF

#defrag the image
Expand Down Expand Up @@ -254,10 +283,19 @@ rm -rf ${BUILD_IMG}

IMG_FILENAME="${SYSTEM_NAME}-${VERSION}.img.tar.xz"
if [ -z "${NO_COMPRESS}" ]; then
tar -c -I'xz -8 -T4' -f ${IMG_FILENAME} ${SYSTEM_NAME}-${VERSION}.img
rm ${SYSTEM_NAME}-${VERSION}.img

sha256sum ${SYSTEM_NAME}-${VERSION}.img.tar.xz > sha256sum.txt
# This can be used only when installing from the refactored frzr
# Maximizes the github building space and makes the build faster
#
# Remember to remove the "btrfs send -f ${SYSTEM_NAME}-${VERSION}.img ${SNAP_PATH}" line
# alongside with this commend when implemented.
#
# btrfs send ${SNAP_PATH} | xz -e -9 --memory=95% -T0 > ${IMG_FILENAME}
#
# When implementing this remember to change $IMG_FILENAME extension to .img.xz
tar -c -I'xz -9e --verbose -T4' -f ${IMG_FILENAME} ${SYSTEM_NAME}-${VERSION}.img
rm -f ${SYSTEM_NAME}-${VERSION}.img

sha256sum "$IMG_FILENAME" > sha256sum.txt
cat sha256sum.txt

# Move the image to the output directory, if one was specified.
Expand Down
3 changes: 0 additions & 3 deletions manifest
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export PACKAGE_OVERRIDES="\
# Check on the AUR webpage if you are unsure
export AUR_PACKAGES="\
asusctl \
aw87559-firmware \
ayaneo-platform-dkms-git \
ayn-platform-dkms-git \
bcm20702a1-firmware \
Expand All @@ -212,7 +211,6 @@ export AUR_PACKAGES="\
hhfc-git \
inputplumber-bin \
legendary \
lib32-gamescope-plus \
libretro-dosbox-pure-git \
libretro-opera-git \
libretro-prosystem-git \
Expand Down Expand Up @@ -265,7 +263,6 @@ export USER_SERVICES="\
"

export FILES_TO_DELETE="\
/boot/initramfs-linux-fallback.img \
/usr/share/SFML \
/usr/share/doc \
/usr/share/gtk-doc \
Expand Down
5 changes: 5 additions & 0 deletions pkgs/build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ set -x

sudo chown -R build:build /workdir/pkgs

# ChimeraOS now uses dracut and excludes mkinitcpio due to pacman hooks causing problems
# Ensure package conflicting with mkinitcpio can be built
sudo pacman -S --noconfirm dracut
sudo pacman -R --noconfirm mkinitcpio

PIKAUR_CMD="PKGDEST=/workdir/pkgs pikaur --noconfirm --build-gpgdir /etc/pacman.d/gnupg -S -P /workdir/${1}/PKGBUILD"
PIKAUR_RUN=(bash -c "${PIKAUR_CMD}")
"${PIKAUR_RUN[@]}"
Expand Down
4 changes: 4 additions & 0 deletions pkgs/chimeraos-dracut-cfg/00-chimeraos.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
early_microcode="yes"
compress="xz -9e --check=crc32 -v"

omit_dracutmodules+=" squash "
4 changes: 4 additions & 0 deletions pkgs/chimeraos-dracut-cfg/10-chimeraos_use-fstab.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_dracutmodules+=" rootfs-block "

# Use the fstab file in the initramfs
use_fstab="yes"
1 change: 1 addition & 0 deletions pkgs/chimeraos-dracut-cfg/20-chimeraos_plymouth.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omit_dracutmodules+=" plymouth "
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_dracutmodules+=" overlayfs "
add_dracutmodules+=" btrfs "
add_drivers+=" nvme vfat "
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omit_dracutmodules+=" systemd-pcrphase systemd-cryptsetup crypt tpm2-tss "
1 change: 1 addition & 0 deletions pkgs/chimeraos-dracut-cfg/50-chimeraos_exclude-mdraid.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omit_dracutmodules+=" mdraid "
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
omit_dracutmodules+=" cifs "
omit_dracutmodules+=" nfs "
omit_dracutmodules+=" network "
omit_dracutmodules+=" network-manager "
omit_dracutmodules+=" connman "
omit_dracutmodules+=" network-legacy "
omit_dracutmodules+=" network-wicked "
10 changes: 10 additions & 0 deletions pkgs/chimeraos-dracut-cfg/60-dracut-remove.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Trigger]
Type = Path
Operation = Remove
Target = usr/lib/modules/*/pkgbase

[Action]
Description = Removing linux initcpios...
When = PreTransaction
Exec = /usr/local/bin/dracut-remove.sh
NeedsTargets
1 change: 1 addition & 0 deletions pkgs/chimeraos-dracut-cfg/70-chimeraos_exclude-nvdimm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omit_dracutmodules+=" nvdimm "
3 changes: 3 additions & 0 deletions pkgs/chimeraos-dracut-cfg/80-chimeraos_exclude-qemu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
omit_dracutmodules+=" qemu "
omit_dracutmodules+=" qemu-net "
omit_dracutmodules+=" virtiofs "
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omit_dracutmodules+=" bluetooth "
12 changes: 12 additions & 0 deletions pkgs/chimeraos-dracut-cfg/90-dracut-install.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase

[Action]
Description = Updating linux initcpios (with dracut!)...
When = PostTransaction
Exec = /usr/local/bin/dracut-install.sh
Depends = dracut
NeedsTargets
74 changes: 74 additions & 0 deletions pkgs/chimeraos-dracut-cfg/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Maintainer: Denis Benato <[email protected]>

pkgname=chimeraos-dracut-cfg
pkgver=0.0.1
pkgrel=1
pkgdesc="Dracut-specific configuration for chimeraos"
arch=('any')
url="https://github.com/ChimeraOS/chimeraos"
license=('MIT')
depends=(
'dracut' # regenerate the initramfs
#'plymouth' # support for boot animations
'btrfs-progs' # btrfs hook
'binutils' # allow usage of --strip
)
source=(
"dracut-install.sh"
"dracut-remove.sh"
"00-chimeraos.conf"
"10-chimeraos_use-fstab.conf"
"20-chimeraos_plymouth.conf"
"30-chimeraos_include-filesystems.conf"
"40-chimeraos_exclude-encryption.conf"
"50-chimeraos_exclude-mdraid.conf"
"60-chimeraos_exclude-networking.conf"
"70-chimeraos_exclude-nvdimm.conf"
"80-chimeraos_exclude-qemu.conf"
"90-chimeraos_exclude-bluetooth.conf"
"60-dracut-remove.hook"
"90-dracut-install.hook"
)
sha256sums=(
'827d59e8fda5c16b3fc45eb89ce7cd5be6c40d35dd8fe9a8d5ea825a63d3a089' # dracut-install.sh
'daefb58a0bf6df48cceaf4f7a898c17ca1f24e18cd7981b19f5f2034499592ed' # dracut-remove.sh
'1f356cc895156064cec63f589ea49acc59a4faab94b7ebe99dc904893da85907' # 00-chimeraos.conf
'7886062a7293d2e6bd6e975c4a8aaae63342af366479db8adf1b75860081cf53' # 10-chimeraos_use-fstab.conf
'103cf3322954202c3f0f740cd9079546d059f919c8b1b07ac703ec6f94cf17fb' # 20-chimeraos_plymouth.conf
'676b4a216cd3787882edf2e5bdaebce4577a11dbae176f81bab1c1b72917fc09' # 30-chimeraos_include-filesystems.conf
'8b4247161bb9158bf382517bb061360c184315e71fea244420d8db99d2730129' # 40-chimeraos_exclude-encryption.conf
'84cccef9706590795b37b4d949c0a34e6ee7ba34ee7ff01a8c808a2fe3ff7f89' # 50-chimeraos_exclude-mdraid.conf
'e1f9caf3878e65ca28951642ad02c1b167eacba777b4ccc893f6b8702a6d474e' # 60-chimeraos_exclude-networking.conf
'5822aa5a698577937820ab2565a203492b6af81434bf1423664ef68bba8c1617' # 70-chimeraos_exclude-nvdimm.conf
'b126149ca9f79bb1deb7ec640f4452dd61f4214558f954b7bc9196c5e9ca6ef0' # 80-chimeraos_exclude-qemu.conf
'e983493fe3e7d9395dd8d1c8949150144c8d4318ff17ff2aca004235734c8299' # 90-chimeraos_exclude-bluetooth.conf
'41c996bf7ef90e6a81690c4a06cbef89167882a036699834fe22637a1a184982' # 60-dracut-remove.hook
'df94baaf97d110f65f1443dd7063fe0e8ec1f73b5baf142c6ff08c260e571fcb' # 90-dracut-install.hook
)

package() {
mkdir -p "$pkgdir/etc/dracut.conf.d/"
mkdir -p "$pkgdir/usr/local/bin/"
mkdir -p "$pkgdir/usr/share/libalpm/hooks"

install -m 755 "$srcdir/dracut-install.sh" "$pkgdir/usr/local/bin"
install -m 755 "$srcdir/dracut-remove.sh" "$pkgdir/usr/local/bin"

install -m 644 "$srcdir/60-dracut-remove.hook" "$pkgdir/usr/share/libalpm/hooks"
install -m 644 "$srcdir/90-dracut-install.hook" "$pkgdir/usr/share/libalpm/hooks"

install -m 644 "$srcdir/00-chimeraos.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/10-chimeraos_use-fstab.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/20-chimeraos_plymouth.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/30-chimeraos_include-filesystems.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/40-chimeraos_exclude-encryption.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/50-chimeraos_exclude-mdraid.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/60-chimeraos_exclude-networking.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/70-chimeraos_exclude-nvdimm.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/80-chimeraos_exclude-qemu.conf" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/90-chimeraos_exclude-bluetooth.conf" "$pkgdir/etc/dracut.conf.d"

install -m 644 "$srcdir/60-dracut-remove.hook" "$pkgdir/etc/dracut.conf.d"
install -m 644 "$srcdir/90-dracut-install.hook" "$pkgdir/etc/dracut.conf.d"
}

15 changes: 15 additions & 0 deletions pkgs/chimeraos-dracut-cfg/dracut-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

args=('--force' '--strip' '--aggressive-strip' '--reproducible')

while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
kver="${line#'usr/lib/modules/'}"
kver="${kver%'/pkgbase'}"

install -Dm0644 "/${line%'/pkgbase'}/vmlinuz" "/boot/vmlinuz-${pkgbase}"
dracut --no-hostonly --no-hostonly-cmdline "${args[@]}" "/boot/initramfs-${pkgbase}.img" --kver "$kver"
#dracut --no-hostonly "${args[@]}" "/boot/initramfs-${pkgbase}-fallback.img" --kver "$kver"
fi
done
10 changes: 10 additions & 0 deletions pkgs/chimeraos-dracut-cfg/dracut-remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
rm -f "/boot/vmlinuz-${pkgbase}"
rm -f "/boot/initramfs-${pkgbase}.img"
#rm -f "/boot/initramfs-${pkgbase}-fallback.img"
fi
done
18 changes: 18 additions & 0 deletions pkgs/chimeraos-fake-mkinitcpio/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pkgname=chimeraos-fake-mkinitcpio
pkgver=39.2
pkgrel=2
pkgdesc="A stub implementation of mkinitcpio that does nothing except providing the executable that does nothing"
arch=('any')
url='https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio'
license=('GPL-2.0-only')
depends=()
provides=('initramfs')
conflicts=('mkinitcpio')
source=('mkinitcpio')
b2sums=('4b40ab2908ab1ad57e72e22f6f74f4d22d3bb09a42d64956a64c48cf0dadb645da4c4e3edb31fa3068c909a1f03c0fa9fd534cb7159d6d56526d5dbb3104b9b0')

package() {
mkdir -p "$pkgdir/usr/bin"
install -m 755 "$srcdir/mkinitcpio" "$pkgdir/usr/bin"
}

6 changes: 6 additions & 0 deletions pkgs/chimeraos-fake-mkinitcpio/mkinitcpio
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# The pre-refactor frzr will call the target image mkinitcpio.
# We want to avoid generating an error, yet we want this tool to do nothing as
# device-quirks is now installed in a deployment migration.
echo "[WARNING] Fake mkinitcpio called."
24 changes: 0 additions & 24 deletions rootfs/etc/initcpio/hooks/frzr-etc

This file was deleted.

Loading