Skip to content

Commit 8f51ff7

Browse files
committed
[Tink] initramfs boot to console with tmpfs root
Add dracut module for boot to console with root in tmpfs. Generate Tink initramfs image in build which is able to boot to console with just initramfs/vmlinuz image. Signed-off-by: Swee Yee Fonn <swee.yee.fonn@intel.com>
1 parent 74ae06f commit 8f51ff7

File tree

7 files changed

+171
-4
lines changed

7 files changed

+171
-4
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: 19 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: 11%{?dist}
7+
Release: 12%{?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
@@ -146,6 +148,13 @@ Requires: %{name} = %{version}-%{release}
146148
%description systemd-cryptsetup
147149
This package contains dracut module needed to build an initramfs with systemd-cryptsetup enabled.
148150

151+
%package tmpfsroot
152+
Summary: dracut module to support root on tmpfs
153+
Requires: %{name} = %{version}-%{release}
154+
155+
%description tmpfsroot
156+
This package contains dracut module root on tmpfs.
157+
149158
%package virtio
150159
Summary: dracut configuration needed to build an initramfs with virtio guest drivers
151160
Requires: %{name} = %{version}-%{release}
@@ -221,6 +230,10 @@ mkdir -p %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
221230
install -p -m 0755 %{SOURCE4} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
222231
install -p -m 0755 %{SOURCE5} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
223232

233+
mkdir -p %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/
234+
install -p -m 0755 %{SOURCE15} %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/module-setup.sh
235+
install -p -m 0755 %{SOURCE16} %{buildroot}%{dracutlibdir}/modules.d/90tmpfsroot/
236+
224237
touch %{buildroot}%{_var}/opt/%{name}/log/%{name}.log
225238
ln -srv %{buildroot}%{_var}/opt/%{name}/log/%{name}.log %{buildroot}%{_var}/log/
226239

@@ -241,6 +254,7 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
241254
%exclude %{_libdir}/kernel
242255
%exclude %{dracutlibdir}/modules.d/20overlayfs
243256
%exclude %{dracutlibdir}/modules.d/90systemd-cryptsetup
257+
%exclude %{dracutlibdir}/modules.d/90tmpfsroot
244258
%{_libdir}/%{name}/%{name}-init.sh
245259
%{_datadir}/pkgconfig/%{name}.pc
246260
%{dracutlibdir}/%{name}-functions.sh
@@ -309,6 +323,10 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
309323
%dir %{dracutlibdir}/modules.d/90systemd-cryptsetup
310324
%{dracutlibdir}/modules.d/90systemd-cryptsetup/*
311325

326+
%files tmpfsroot
327+
%dir %{dracutlibdir}/modules.d/90tmpfsroot
328+
%{dracutlibdir}/modules.d/90tmpfsroot/*
329+
312330
%files virtio
313331
%defattr(-,root,root,0755)
314332
%{_sysconfdir}/dracut.conf.d/00-virtio.conf

toolkit/imageconfigs/edge-image-tink.json

Lines changed: 5 additions & 2 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,10 +37,13 @@
3737
"FinalizeImageScripts": [
3838
{
3939
"Path": "scripts/cleanup.sh"
40+
},
41+
{
42+
"Path": "scripts/setup-tink-initramfs.sh"
4043
}
4144
],
4245
"KernelCommandLine": {
43-
"ExtraCommandLine": "quiet splash"
46+
"ExtraCommandLine": "root=tmpfs rootflags=size=1G,mode=0755 rd.skipfsck noresume quiet splash"
4447
},
4548
"Hostname": "EdgeMicrovisorToolkitTink",
4649
"DisableRpmDocs": true,

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) Intel Corporation.
4+
# Licensed under the MIT License.
5+
6+
# Failure can be ignored.
7+
set -e
8+
set -x
9+
10+
# regen initramfs for tink
11+
echo "Tink: final regen initramfs"
12+
13+
ramfs=$(find /boot -type f -name initramfs*img -printf '%f\n')
14+
# unzip initramfs
15+
mkdir /tmp/initramfs
16+
cd /tmp/initramfs
17+
echo "Tink: inside $(pwd)"
18+
echo "Tink: unziping initial initramfs for repack"
19+
gunzip -c -k /boot/$ramfs | cpio -idmv --no-absolute-filenames
20+
echo "Tink: free space $(df -h)"
21+
22+
mkdir /tmp/rootfs
23+
cd /tmp/rootfs
24+
echo "Tink: inside $(pwd)"
25+
echo "Tink: free space $(df -h)"
26+
mkdir -p boot dev etc home mnt media proc sys run tmp usr usr/bin usr/sbin usr/lib usr/libexec var
27+
chown root:root boot dev etc home mnt media proc sys run tmp usr usr/bin usr/sbin usr/lib usr/libexec var
28+
chmod 0700 boot
29+
chmod 0755 dev etc home mnt media proc sys run tmp usr usr/bin usr/sbin usr/lib usr/libexec var
30+
echo "Tink: copy initial initramfs for rootfs"
31+
cp -a /tmp/initramfs/dev/* dev/
32+
ln -s usr/bin bin
33+
ln -s usr/sbin sbin
34+
ln -s usr/lib lib
35+
ln -s usr/lib lib64
36+
chown root:root bin sbin lib lib64
37+
chmod 0777 bin sbin lib lib64
38+
echo "Tink: after initramfs copy $(ls -l .)"
39+
echo "Tink: after initramfs copy $(du -h /tmp/rootfs)"
40+
echo "Tink: copying rootfs files"
41+
cp -R -p /usr/sbin/* usr/sbin/
42+
cp -R -p /usr/bin/* usr/bin/
43+
cp -R -p /usr/lib/* usr/lib/
44+
cp -R -p /usr/libexec/* usr/libexec/
45+
cp -R -p /var/lib var/
46+
cp -R -p /etc/* etc/
47+
# override boot device command line
48+
echo "Tink: fstab contents $(cat etc/fstab)"
49+
echo 'Tink: tmpfs / tmpfs defaults,size=1G 0 0' > etc/fstab
50+
#echo "" > etc/fstab
51+
echo "Tink: fstab contents after edit $(cat etc/fstab)"
52+
# simple setup for console
53+
#echo 'LANG=en_US.UTF-8' > etc/locale.conf
54+
#echo 'KEYMAP=us' > etc/vconsole.conf
55+
#echo 'FONT=lat9w-16' >> etc/vconsole.conf
56+
echo "Tink: console setup $(cat etc/locale.conf etc/vconsole.conf)"
57+
mkdir -p usr/share/terminfo/v
58+
cp -R -p /usr/share/terminfo/v/vt100 usr/share/terminfo/v/
59+
cp -R -p /usr/share/terminfo/v/vt220 usr/share/terminfo/v/
60+
mkdir -p usr/share/keymaps
61+
cp -R -p /usr/share/keymaps/include usr/share/keymaps/
62+
mkdir -p usr/share/keymaps/i386/include
63+
cp -R -p /usr/share/keymaps/i386/include/* usr/share/keymaps/i386/include/
64+
mkdir -p usr/share/keymaps/i386/qwerty
65+
cp -R -p /usr/share/keymaps/i386/qwerty/us.map.gz usr/share/keymaps/i386/qwerty/
66+
mkdir -p usr/share/consolefonts
67+
cp -R -p /usr/share/consolefonts/lat9w-16* usr/share/consolefonts/
68+
mkdir -p usr/share/dbus-1
69+
cp -R -p /usr/share/dbus-1/system.conf usr/share/dbus-1/
70+
echo "Tink: after copy $(du -h /tmp/rootfs)"
71+
echo "Tink: free space $(df -h)"
72+
tar cf - -C . . | gzip -9 > /rootfs.tar.gz
73+
cd -
74+
echo "Tink: rootfs size: $(ls -l /rootfs.tar.gz)"
75+
rm -rf /tmp/rootfs
76+
77+
cd /tmp/initramfs
78+
echo "Tink: inside $(pwd)"
79+
echo "Tink: after copy $(du -h /tmp/initramfs)"
80+
echo "Tink: check cmdline.d $(ls etc/cmdline.d)"
81+
echo "Tink: check cmdline.d contents $(cat etc/cmdline.d/95root-dev.conf)"
82+
#echo 'root=tmpfs rootfstype=tmpfs' > etc/cmdline.d/95root-dev.conf
83+
#echo 'root= rootfstype=auto' > etc/cmdline.d/95root-dev.conf
84+
echo 'root=tmpfs rootflags=size=1G,mode=0755' > etc/cmdline.d/95root-dev.conf
85+
echo "Tink: check cmdline.d contents after edit $(cat etc/cmdline.d/95root-dev.conf)"
86+
echo "Tink: before rm devexist* $(ls -al var/lib/dracut/hooks/initqueue/finished/)"
87+
rm -f var/lib/dracut/hooks/initqueue/finished/devexists*
88+
echo "Tink: after rm devexist* $(ls -al var/lib/dracut/hooks/initqueue/finished/)"
89+
echo "Tink: before rm wants $(ls -al etc/systemd/system/initrd.target.wants/)"
90+
rm -rf etc/systemd/system/initrd.target.wants/dev-disk-b*
91+
echo "Tink: after rm wants $(ls etc/systemd/system/initrd.target.wants/)"
92+
echo "Tink: before rm disk service $(ls -al etc/systemd/system/dev-disk-b*)"
93+
rm -rf etc/systemd/system/dev-disk-b*
94+
echo "Tink: after rm disk service $(ls -al etc/systemd/system/)"
95+
echo "$(find . -iname dev-disk*)"
96+
# copy tar required for uncompressing rootfs archive
97+
echo "Tink: before copy tar $(find . -iname tar)"
98+
cp /usr/bin/tar usr/bin
99+
echo "Tink: after copy tar $(find . -iname tar)"
100+
mv /rootfs.tar.gz /tmp/initramfs/
101+
find . | cpio -o -H newc | gzip > /boot/$ramfs
102+
cd -
103+
104+
echo "Tink: $(ls -l /boot/$ramfs)"
105+
rm -rf /tmp/initramfs

0 commit comments

Comments
 (0)