feat(image): switch to btrfs for patos-state
This commit is contained in:
parent
b3ad9f9962
commit
3374541b3a
4 changed files with 102 additions and 155 deletions
|
@ -9,96 +9,22 @@ mkdir rootfs
|
|||
cp -prP $rootfs/* rootfs/
|
||||
find rootfs/ -type d -exec chmod 755 {} \;
|
||||
|
||||
# set default target to basic
|
||||
mkdir rootfs/usr/lib/systemd/system/basic.target.wants
|
||||
ln -sf basic.target rootfs/usr/lib/systemd/system/default.target
|
||||
# set default target to multi-user
|
||||
ln -sf multi-user.target rootfs/usr/lib/systemd/system/default.target
|
||||
|
||||
# mount patos state
|
||||
cat <<EOF > rootfs/usr/lib/systemd/system/var.mount
|
||||
[Unit]
|
||||
Description=Mount for /var
|
||||
Before=local-fs.target
|
||||
|
||||
[Mount]
|
||||
What=/dev/disk/by-label/patos-state
|
||||
Where=/var
|
||||
Type=ext2
|
||||
Options=defaults
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
EOF
|
||||
ln -sf ../var.mount rootfs/usr/lib/systemd/system/basic.target.wants/var.mount
|
||||
ln -sf ../var.mount rootfs/usr/lib/systemd/system/sysinit.target.wants/var.mount
|
||||
|
||||
# enable dbus
|
||||
ln -sf ../dbus.service rootfs/usr/lib/systemd/system/basic.target.wants/dbus.service
|
||||
ln -sf ../dbus.service rootfs/usr/lib/systemd/system/multi-user.target.wants/dbus.service
|
||||
ln -sf ../dbus.socket rootfs/usr/lib/systemd/system/sockets.target.wants/dbus.socket
|
||||
|
||||
# enable systemd-networkd
|
||||
ln -sf ../systemd-networkd.service rootfs/usr/lib/systemd/system/sysinit.target.wants/systemd-networkd.service
|
||||
|
||||
# generate a temporary machine id
|
||||
$systemd/usr/bin/systemd-machine-id-setup --root=rootfs/
|
||||
|
||||
cat <<EOF > rootfs/etc/passwd
|
||||
root::0:0:root:/root:/bin/sh
|
||||
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
||||
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
||||
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
||||
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
||||
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
||||
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
||||
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
||||
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
||||
systemd-coredump:x:151:992::/var/empty:/usr/bin/nologin
|
||||
systemd-network:x:152:152::/var/empty:/usr/bin/nologin
|
||||
systemd-resolve:x:153:153::/var/empty:/usr/bin/nologin
|
||||
systemd-timesync:x:154:154::/var/empty:/usr/bin/nologin
|
||||
EOF
|
||||
chmod 644 rootfs/etc/passwd
|
||||
|
||||
cat <<EOF > rootfs/etc/group
|
||||
root:x:0:root
|
||||
bin:x:1:root,bin,daemon
|
||||
daemon:x:2:root,bin,daemon
|
||||
sys:x:3:root,bin
|
||||
adm:x:4:root,daemon
|
||||
tty:x:5:
|
||||
disk:x:6:root
|
||||
lp:x:7:daemon
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:root
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
uucp:x:14:
|
||||
log:x:19:root
|
||||
utmp:x:20:
|
||||
locate:x:21:
|
||||
rfkill:x:24:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
http:x:33:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
uuidd:x:68:
|
||||
messagebus:x:81:
|
||||
systemd-journal:x:62:
|
||||
systemd-network:x:152:
|
||||
systemd-resolve:x:153:
|
||||
systemd-timesync:x:154:
|
||||
systemd-oom:x:991:
|
||||
systemd-coredump:x:992:
|
||||
network:x:90:
|
||||
video:x:91:
|
||||
audio:x:92:
|
||||
optical:x:93:
|
||||
floppy:x:94:
|
||||
storage:x:95:
|
||||
scanner:x:96:
|
||||
input:x:97:
|
||||
power:x:98:
|
||||
nobody:x:99:
|
||||
EOF
|
||||
chmod 644 rootfs/etc/group
|
||||
|
||||
# FIXME: remove this later (just to get a shell in the initramfs)
|
||||
cat <<EOF > rootfs/usr/lib/systemd/system/demo.service
|
||||
[Unit]
|
||||
|
@ -120,9 +46,9 @@ SendSIGHUP=yes
|
|||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
ln -sf ../demo.service rootfs/usr/lib/systemd/system/basic.target.wants/demo.service
|
||||
ln -sf ../demo.service rootfs/usr/lib/systemd/system/multi-user.target.wants/demo.service
|
||||
|
||||
|
||||
$systemd/usr/bin/ukify build \
|
||||
|
|
|
@ -25,6 +25,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
|
|||
kmodLibs = pkgs.kmod.lib;
|
||||
kmodBin = pkgs.kmod.out;
|
||||
libbpf = pkgs.libbpf.out;
|
||||
btrfs = pkgs.btrfs-progs.out;
|
||||
|
||||
builder = ./mkrootfs.sh;
|
||||
})
|
||||
|
|
|
@ -6,79 +6,16 @@ pushd $out/root
|
|||
### copy rootfs
|
||||
cp -prP $rootfs/* .
|
||||
find . -type d -exec chmod 755 {} \;
|
||||
mkdir sysroot
|
||||
|
||||
### create directories
|
||||
ln -sf ../usr/lib/systemd/systemd init
|
||||
|
||||
mkdir sysroot
|
||||
|
||||
### Create needed files
|
||||
echo patos > ./etc/hostname
|
||||
|
||||
ln -sf /etc/os-release ./etc/initrd-release
|
||||
|
||||
cat <<EOF > ./etc/passwd
|
||||
root::0:0:root:/root:/bin/sh
|
||||
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
||||
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
||||
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
||||
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
||||
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
||||
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
||||
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
||||
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
||||
systemd-coredump:x:151:992::/var/empty:/usr/bin/nologin
|
||||
systemd-network:x:152:152::/var/empty:/usr/bin/nologin
|
||||
systemd-resolve:x:153:153::/var/empty:/usr/bin/nologin
|
||||
systemd-timesync:x:154:154::/var/empty:/usr/bin/nologin
|
||||
EOF
|
||||
chmod 644 ./etc/passwd
|
||||
|
||||
cat <<EOF > ./etc/group
|
||||
root:x:0:root
|
||||
bin:x:1:root,bin,daemon
|
||||
daemon:x:2:root,bin,daemon
|
||||
sys:x:3:root,bin
|
||||
adm:x:4:root,daemon
|
||||
tty:x:5:
|
||||
disk:x:6:root
|
||||
lp:x:7:daemon
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:root
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
uucp:x:14:
|
||||
log:x:19:root
|
||||
utmp:x:20:
|
||||
locate:x:21:
|
||||
rfkill:x:24:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
http:x:33:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
uuidd:x:68:
|
||||
messagebus:x:81:
|
||||
systemd-journal:x:62:
|
||||
systemd-network:x:152:
|
||||
systemd-resolve:x:153:
|
||||
systemd-timesync:x:154:
|
||||
systemd-oom:x:991:
|
||||
systemd-coredump:x:992:
|
||||
network:x:90:
|
||||
video:x:91:
|
||||
audio:x:92:
|
||||
optical:x:93:
|
||||
floppy:x:94:
|
||||
storage:x:95:
|
||||
scanner:x:96:
|
||||
input:x:97:
|
||||
power:x:98:
|
||||
nobody:x:99:
|
||||
EOF
|
||||
chmod 644 ./etc/group
|
||||
|
||||
# gen initrd
|
||||
find . -print0 | cpio --null --owner=root:root -o --format=newc | xz -9 --check=crc32 > ../initrd.xz
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
set -ex -o pipefail
|
||||
|
||||
mkdir -p $out
|
||||
mkdir -p $out/etc/repart.d $out/dev $out/proc $out/sys $out/tmp $out/root $out/run $out/boot
|
||||
mkdir -p $out/etc/repart.d $out/dev $out/proc $out/sys $out/tmp $out/root $out/run $out/boot $out/mnt
|
||||
ln -sf ../usr/bin $out/bin
|
||||
ln -sf ../usr/bin $out/sbin
|
||||
ln -sf ../usr/lib $out/lib
|
||||
|
@ -20,13 +20,13 @@ rm -f $out/usr/lib/udev/rules.d/90-vconsole.rules
|
|||
|
||||
cat <<EOF > $out/etc/os-release
|
||||
NAME=PatOS
|
||||
PRETTY_NAME=PatOS 0.0.1 (pre-alpha)
|
||||
PRETTY_NAME=PatOS v${version} (Pre-Alpha)
|
||||
IMAGE_ID=patos
|
||||
ID=patos
|
||||
IMAGE_VERSION=0.0.1
|
||||
VERSION=0.0.1
|
||||
VERSION_ID=0.0.1
|
||||
BUILD_ID=0.0.1
|
||||
IMAGE_VERSION=${version}
|
||||
VERSION=${version}
|
||||
VERSION_ID={version}
|
||||
BUILD_ID={version}
|
||||
EOF
|
||||
|
||||
sed -i 's#After=\(.*\)#After=sysroot.mount \1#' $out/usr/lib/systemd/system/systemd-repart.service
|
||||
|
@ -41,12 +41,11 @@ cat <<EOF > $out/etc/repart.d/22-root.conf
|
|||
Type=root
|
||||
EOF
|
||||
|
||||
#FIXME: use btrfs instead on ext2(busybox) but need the btrfs tools in rootfs.
|
||||
cat <<EOF > $out/etc/repart.d/40-var.conf
|
||||
[Partition]
|
||||
Type=var
|
||||
UUID=4d21b016-b534-45c2-a9fb-5c16e091fd2d
|
||||
Format=ext2
|
||||
Format=btrfs
|
||||
Label=patos-state
|
||||
Minimize=off
|
||||
FactoryReset=yes
|
||||
|
@ -54,6 +53,21 @@ SizeMinBytes=1G
|
|||
SplitName=-
|
||||
EOF
|
||||
|
||||
cat <<EOF > $out/usr/lib/systemd/system/var.mount
|
||||
[Unit]
|
||||
Description=Mount for /var
|
||||
Before=local-fs.target
|
||||
|
||||
[Mount]
|
||||
What=/dev/disk/by-label/patos-state
|
||||
Where=/var
|
||||
Type=btrfs
|
||||
Options=defaults
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
### install PatOS glibc
|
||||
cp -P $glibcPatos/lib/*.so* $out/usr/lib/
|
||||
|
||||
|
@ -68,6 +82,10 @@ $out/usr/bin/busybox --list | xargs -I {} ln -sf busybox $out/usr/bin/{}
|
|||
### install dbus broker
|
||||
cp -r $dbusBroker/* $out/
|
||||
|
||||
### install btrfs progs
|
||||
cp -Pr ${btrfs}/bin/* $out/usr/bin/
|
||||
cp -Pr ${btrfs}/lib/* $out/usr/lib/
|
||||
|
||||
### install lib kmod
|
||||
cp -P $kmodLibs/lib/* $out/usr/lib
|
||||
cp -P $kmodBin/bin/* $out/usr/bin
|
||||
|
@ -75,6 +93,71 @@ cp -P $kmodBin/bin/* $out/usr/bin
|
|||
### install libbpf
|
||||
cp -P $libbpf/lib/libbpf* $out/usr/lib
|
||||
|
||||
# remove pkgconfig
|
||||
rm -rf $out/usr/lib/pkgconfig
|
||||
|
||||
cat <<EOF > $out/etc/passwd
|
||||
root::0:0:root:/root:/bin/sh
|
||||
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
||||
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
||||
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
||||
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
||||
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
||||
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
||||
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
||||
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
||||
systemd-coredump:x:151:992::/var/empty:/usr/bin/nologin
|
||||
systemd-network:x:152:152::/var/empty:/usr/bin/nologin
|
||||
systemd-resolve:x:153:153::/var/empty:/usr/bin/nologin
|
||||
systemd-timesync:x:154:154::/var/empty:/usr/bin/nologin
|
||||
EOF
|
||||
chmod 644 $out/etc/passwd
|
||||
|
||||
cat <<EOF > $out/etc/group
|
||||
root:x:0:root
|
||||
bin:x:1:root,bin,daemon
|
||||
daemon:x:2:root,bin,daemon
|
||||
sys:x:3:root,bin
|
||||
adm:x:4:root,daemon
|
||||
tty:x:5:
|
||||
disk:x:6:root
|
||||
lp:x:7:daemon
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:root
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
uucp:x:14:
|
||||
log:x:19:root
|
||||
utmp:x:20:
|
||||
locate:x:21:
|
||||
rfkill:x:24:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
http:x:33:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
uuidd:x:68:
|
||||
messagebus:x:81:
|
||||
systemd-journal:x:62:
|
||||
systemd-network:x:152:
|
||||
systemd-resolve:x:153:
|
||||
systemd-timesync:x:154:
|
||||
systemd-oom:x:991:
|
||||
systemd-coredump:x:992:
|
||||
network:x:90:
|
||||
video:x:91:
|
||||
audio:x:92:
|
||||
optical:x:93:
|
||||
floppy:x:94:
|
||||
storage:x:95:
|
||||
scanner:x:96:
|
||||
input:x:97:
|
||||
power:x:98:
|
||||
nobody:x:99:
|
||||
EOF
|
||||
chmod 644 $out/etc/group
|
||||
|
||||
### Find and install all shared libs
|
||||
find $out -type f -executable -exec ldd {} \; | awk '{print $3}' | grep -v systemd | grep -v glibc | sort -u | xargs cp -t $out/usr/lib
|
||||
find $out -type f -executable -exec chmod 755 {} \;
|
||||
|
|
Loading…
Add table
Reference in a new issue