Skip to content

Commit 0b34824

Browse files
committed
[Tink] initramfs boot to console with tmpfs root
Add dracut module for boot to console with root in tmpfs. Caddy/fluent-fit services enabled to run at boot. Add script to generate required initramfs/vmlinuz images from EMT tink build rootfs tar.gz archive after build. eg. sudo toolkit/imageconfigs/scripts/generate-tink-initramfs.sh \ -f <emt-tink.tar.gz> -o <output_images_dir> Signed-off-by: Swee Yee Fonn <swee.yee.fonn@intel.com>
1 parent 056418e commit 0b34824

File tree

8 files changed

+245
-5
lines changed

8 files changed

+245
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Copyright (c) Intel Corporation.
3+
# Licensed under the MIT License.
4+
5+
check() {
6+
require_binaries tar || return 1
7+
return 0
8+
}
9+
10+
depends() {
11+
return 0
12+
}
13+
14+
install() {
15+
inst_hook mount 90 "$moddir/tmpfsroot-mount.sh"
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Copyright (c) Intel Corporation.
3+
# Licensed under the MIT License.
4+
5+
info "mount tmpfs for root"
6+
if ! mount -t tmpfs -o size=1G tmpfs $NEWROOT; then
7+
warn "Failed to mount tmpfs on $NEWROOT"
8+
die
9+
fi
10+
11+
cd $NEWROOT
12+
13+
if [[ -f /rootfs.tar.gz ]]; then
14+
info "extract rootfs.tar.gz to $NEWROOT"
15+
tar -xvf /rootfs.tar.gz -C $NEWROOT
16+
else
17+
warn "no rootfs.tar.gz found"
18+
die
19+
fi
20+
21+
info "rootfs on tmpfs complete"

SPECS/dracut/dracut.signatures.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"dracut-102.tar.gz": "601b175cbf4d2ee902bb7bda3af8826ae2ca060c1af880f6da5a833413f4ec70",
1313
"lgpl-2.1.txt": "dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551",
1414
"megaraid.conf": "914824cdbe0c525b71efa05a75e453335b0068beb8bc28bef2a5866d74bf7dd4",
15+
"tmpfsroot-module-setup.sh": "d1e2d512a3769fb70f7726b1899f89950d5bfc2199e8cde5df44adebd740006f",
16+
"tmpfsroot-mount.sh": "884c4c9a17118229dfbb40ec9a4a23d307c12349dbf19adc1a2d8640c2f77fd0",
1517
"module-setup.sh": "8f5a0d3cc393d78bcb523b0d53c578d2767d688f00e84b525355bbb31d753da4",
1618
"overlayfs-mount.sh": "28f47c107a4435c5153bdb5b2f92f20b7a75bf3932216635ee810875c27dd55b"
1719
}
18-
}
20+
}

SPECS/dracut/dracut.spec

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary: dracut to create initramfs
55
Name: dracut
66
Version: 102
7-
Release: 12%{?dist}
7+
Release: 13%{?dist}
88
# The entire source code is GPLv2+
99
# except install/* which is LGPLv2+
1010
License: GPLv2+ AND LGPLv2+
@@ -31,6 +31,8 @@ Source11: 50-noxattr.conf
3131
Source12: 90livenet/azl-liveos-artifacts-download.service
3232
Source13: 90livenet/azl-liveos-artifacts-download.sh
3333
Source14: 90overlayfs/azl-configure-selinux.sh
34+
Source15: 90tmpfsroot/tmpfsroot-module-setup.sh
35+
Source16: 90tmpfsroot/tmpfsroot-mount.sh
3436

3537
# allow-liveos-overlay-no-user-confirmation-prompt.patch has been introduced by
3638
# the Azure Linux team to allow skipping the user confirmation prompt during
@@ -156,6 +158,13 @@ Requires: %{name} = %{version}-%{release}
156158
%description systemd-cryptsetup
157159
This package contains dracut module needed to build an initramfs with systemd-cryptsetup enabled.
158160

161+
%package tmpfsroot
162+
Summary: dracut module to support root on tmpfs
163+
Requires: %{name} = %{version}-%{release}
164+
165+
%description tmpfsroot
166+
This package contains dracut module root on tmpfs.
167+
159168
%package virtio
160169
Summary: dracut configuration needed to build an initramfs with virtio guest drivers
161170
Requires: %{name} = %{version}-%{release}
@@ -231,6 +240,10 @@ mkdir -p %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
231240
install -p -m 0755 %{SOURCE4} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
232241
install -p -m 0755 %{SOURCE5} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
233242

243+
mkdir -p %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/
244+
install -p -m 0755 %{SOURCE15} %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/module-setup.sh
245+
install -p -m 0755 %{SOURCE16} %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/
246+
234247
touch %{buildroot}%{_var}/opt/%{name}/log/%{name}.log
235248
ln -srv %{buildroot}%{_var}/opt/%{name}/log/%{name}.log %{buildroot}%{_var}/log/
236249

@@ -251,6 +264,7 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
251264
%exclude %{_libdir}/kernel
252265
%exclude %{dracutlibdir}/modules.d/20overlayfs
253266
%exclude %{dracutlibdir}/modules.d/90systemd-cryptsetup
267+
%exclude %{dracutlibdir}/modules.d/90tmpfsroot
254268
%{_libdir}/%{name}/%{name}-init.sh
255269
%{_datadir}/pkgconfig/%{name}.pc
256270
%{dracutlibdir}/%{name}-functions.sh
@@ -319,6 +333,10 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
319333
%dir %{dracutlibdir}/modules.d/90systemd-cryptsetup
320334
%{dracutlibdir}/modules.d/90systemd-cryptsetup/*
321335

336+
%files tmpfsroot
337+
%dir %{dracutlibdir}/modules.d/90tmpfsroot
338+
%{dracutlibdir}/modules.d/90tmpfsroot/*
339+
322340
%files virtio
323341
%defattr(-,root,root,0755)
324342
%{_sysconfdir}/dracut.conf.d/00-virtio.conf
@@ -337,6 +355,9 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
337355
%dir %{_sharedstatedir}/%{name}/overlay
338356

339357
%changelog
358+
* Fri May 16 2025 Swee Yee Fonn <swee.yee.fonn@intel.com> - 102-13
359+
- Add tmpfsroot dracut module
360+
340361
* Thu Apr 28 2025 Ranjan Dutta <ranjan.dutta@intel.com> - 102-12
341362
- merge from Azure Linux tag 3.0.20250423-3.0
342363
- Add fix for systemd-cryptsetup module to be included in initramfs when needed

toolkit/imageconfigs/edge-image-tink.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Artifacts": [
77
{
88
"Name": "edge-readonly-tink",
9-
"Compression": "tar.gz"
9+
"Type": "tar.gz"
1010
}
1111
]
1212
}
@@ -37,13 +37,17 @@
3737
"FinalizeImageScripts": [
3838
{
3939
"Path": "scripts/cleanup.sh"
40+
},
41+
{
42+
"Path": "scripts/setup-tink-image.sh"
4043
}
4144
],
4245
"KernelCommandLine": {
43-
"ExtraCommandLine": "quiet splash"
46+
"ExtraCommandLine": "root=tmpfs rootflags=size=1G,mode=0755 rd.skipfsck noresume quiet splash"
4447
},
45-
"Hostname": "EdgeMicrovisorToolkitTink",
48+
"Hostname": "EMT-tink",
4649
"DisableRpmDocs": true,
50+
"RemoveRpmDb": true,
4751
"Users": [
4852
{
4953
"Name": "root",

toolkit/imageconfigs/packagelists/tink-packages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"packages": [
3+
"dracut-tmpfsroot",
4+
"tar",
35
"fluent-bit",
46
"caddy",
57
"rng-tools",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) Intel Corporation.
4+
# Licensed under the MIT License.
5+
6+
set -e
7+
#set -x
8+
9+
pprefix="Tink"
10+
11+
function generate_images() {
12+
if [[ $# -eq 2 ]]; then
13+
fpath=$(realpath "$1")
14+
if [[ $? -ne 0 || ! -f "$fpath" || ! -s "$fpath" ]]; then
15+
echo "Error: $fpath invalid/zero sized" | tee -a "$LOG_FILE"
16+
exit 255
17+
fi
18+
else
19+
echo "Error: Invalid param to ${FUNCNAME[0]}"
20+
exit 255
21+
fi
22+
local arfname="rootfs"
23+
cp "$1" "/tmp/$arfname.tar.gz"
24+
local outputdir="$2"
25+
26+
tar -xvf "/tmp/$arfname.tar.gz" -C "$outputdir" --strip-components=2 --wildcards ./boot/vmlinuz-*.emt3 ./boot/initramfs-*.emt3.img
27+
gunzip -f "/tmp/$arfname.tar.gz"
28+
tar -vf "/tmp/$arfname.tar" --delete ./tmp ./boot
29+
gzip -f "/tmp/$arfname.tar"
30+
#cp "/tmp/$arfname.tar.gz" "$outputdir"
31+
32+
ramfs=$(find $outputdir -type f -name initramfs*img -printf '%f\n')
33+
echo "pprefix: Original $ramfs $(sync;du -h $outputdir/$ramfs)"
34+
# unzip initramfs
35+
mkdir -p /tmp/initramfs
36+
cd /tmp/initramfs
37+
echo "pprefix: inside $(pwd)"
38+
echo "pprefix: unziping initial initramfs for repack"
39+
gunzip -c -k "$outputdir/$ramfs" | cpio -idmv --no-absolute-filenames
40+
#echo "pprefix: free space $(df -h)"
41+
42+
cp "/tmp/$arfname.tar.gz" /tmp/initramfs/
43+
find . | cpio -o -H newc | gzip > "$outputdir/$ramfs"
44+
cd -
45+
46+
echo "pprefix: $(sync;du -h $outputdir/$ramfs)"
47+
rm -rf /tmp/initramfs
48+
chmod 0666 $outputdir/vmlinuz-*.emt3 $outputdir/initramfs-*.emt3.img
49+
}
50+
51+
# inputs
52+
emtfile=""
53+
odir=""
54+
55+
function parse_arg() {
56+
while [[ $# -gt 0 ]]; do
57+
case $1 in
58+
-h|-\?|--help)
59+
printf "Usage: %s [-h] <-f emt_tar_gz_file> [-o output_dir]\n" "$(basename "${BASH_SOURCE[0]}")"
60+
exit
61+
;;
62+
63+
-f)
64+
emtfile=$(realpath "$2")
65+
if [[ ! -f "$emtfile" || $(tar -tvf "$emtfile" &> /dev/null) ]]; then
66+
echo "Error: $2 invalid tar.gz file"
67+
return 255
68+
fi
69+
echo "Info: input file $emtfile"
70+
shift
71+
;;
72+
73+
-o)
74+
odir=$(realpath "$2")
75+
if [[ ! -d "$odir" ]]; then
76+
echo "Error: $2 invalid output directory"
77+
return 255
78+
fi
79+
echo "Info: output directory $odir"
80+
shift
81+
;;
82+
83+
-?*)
84+
echo "Error: Invalid option: $1"
85+
show_help
86+
return 255
87+
;;
88+
*)
89+
echo "Error: Unknown option: $1"
90+
return 255
91+
;;
92+
esac
93+
shift
94+
done
95+
}
96+
97+
#------------- main processes -------------
98+
trap 'echo "Error $(realpath ${BASH_SOURCE[0]}) line ${LINENO}: $BASH_COMMAND"' ERR
99+
100+
parse_arg "$@" || exit 255
101+
if [[ -z "$odir" ]]; then
102+
odir=$(pwd)
103+
fi
104+
generate_images "$emtfile" "$odir" || exit 255
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) Intel Corporation.
4+
# Licensed under the MIT License.
5+
6+
set -e
7+
set -x
8+
9+
pprefix="Tink"
10+
11+
# services
12+
systemctl disable systemd-homed.service
13+
systemctl enable caddy.service
14+
systemctl enable fluent-bit.service
15+
mkdir -p /etc/fluent-bit
16+
if [ ! -f /etc/fluent-bit/fluent-bit.conf ]; then
17+
touch /etc/fluent-bit/fluent-bit.conf
18+
fi
19+
echo "$pprefix: fstab contents $(cat /etc/fstab)"
20+
echo 'tmpfs / tmpfs defaults,size=1G 0 0' > /etc/fstab
21+
echo "$pprefix: $(du -h /usr/share)"
22+
find /usr/share -type f \
23+
! -path "/usr/share/terminfo/v/vt100" \
24+
! -path "/usr/share/terminfo/v/vt220" \
25+
! -path "/usr/share/keymaps/include/*" \
26+
! -path "/usr/share/keymaps/i386/include/*" \
27+
! -path "/usr/share/keymaps/i386/qwerty/us.map.gz" \
28+
! -path "/usr/share/consolefonts/lat9w-16*" \
29+
! -path "/usr/share/dbus-1/system.conf" \
30+
! -path "/usr/share/caddy/*" \
31+
! -path "/usr/share/pki/*" \
32+
-exec rm -f {} +
33+
echo "$pprefix: reduced $(du -h /usr/share)"
34+
35+
ramfs=$(find /boot -type f -name initramfs*img -printf '%f\n')
36+
# unzip initramfs
37+
mkdir /tmp/initramfs
38+
cd /tmp/initramfs
39+
echo "$pprefix: inside $(pwd)"
40+
echo "$pprefix: unziping initial initramfs for repack"
41+
gunzip -c -k /boot/$ramfs | cpio -idmv --no-absolute-filenames
42+
echo "$pprefix: free space $(df -h)"
43+
44+
cd /tmp/initramfs
45+
echo "$pprefix: inside $(pwd)"
46+
echo "$pprefix: after copy $(du -h /tmp/initramfs)"
47+
echo "$pprefix: check cmdline.d $(ls etc/cmdline.d)"
48+
echo "$pprefix: check cmdline.d contents $(cat etc/cmdline.d/95root-dev.conf)"
49+
echo 'root=tmpfs rootflags=size=1G,mode=0755' > etc/cmdline.d/95root-dev.conf
50+
echo "$pprefix: check cmdline.d contents after edit $(cat etc/cmdline.d/95root-dev.conf)"
51+
echo "$pprefix: before rm devexist* $(ls -al var/lib/dracut/hooks/initqueue/finished/)"
52+
rm -f var/lib/dracut/hooks/initqueue/finished/devexists*
53+
echo "$pprefix: after rm devexist* $(ls -al var/lib/dracut/hooks/initqueue/finished/)"
54+
echo "$pprefix: before rm wants $(ls -al etc/systemd/system/initrd.target.wants/)"
55+
rm -rf etc/systemd/system/initrd.target.wants/dev-disk-b*
56+
echo "$pprefix: after rm wants $(ls etc/systemd/system/initrd.target.wants/)"
57+
echo "$pprefix: before rm disk service $(ls -al etc/systemd/system/dev-disk-b*)"
58+
rm -rf etc/systemd/system/dev-disk-b*
59+
echo "$pprefix: after rm disk service $(ls -al etc/systemd/system/)"
60+
echo "$(find . -iname dev-disk*)"
61+
# copy tar required for uncompressing rootfs archive
62+
echo "$pprefix: before copy tar $(find . -iname tar)"
63+
cp /usr/bin/tar usr/bin
64+
echo "$pprefix: after copy tar $(find . -iname tar)"
65+
#mv /rootfs.tar.gz /tmp/initramfs/
66+
find . | cpio -o -H newc | gzip > /boot/$ramfs
67+
cd -
68+
69+
echo "$pprefix: $(ls -l /boot/$ramfs)"
70+
rm -rf /tmp/initramfs

0 commit comments

Comments
 (0)