summaryrefslogtreecommitdiffstats
path: root/recipes-sota/ostree-initrd
diff options
context:
space:
mode:
authorAnton Gerasimov <anton@advancedtelematic.com>2016-10-04 14:42:42 +0200
committerAnton Gerasimov <anton@advancedtelematic.com>2016-10-04 14:42:42 +0200
commit7bd3693b986e0a6e59016767ea6f075ba01ab68c (patch)
tree8cf3fc3f8a6a546ca1f734cd56e3d4e8fca58faf /recipes-sota/ostree-initrd
parent844ddcf4496edfdb9b682f712ab1ae1cd16f1f97 (diff)
downloadmeta-updater-7bd3693b986e0a6e59016767ea6f075ba01ab68c.tar.gz
Tuned initrd image and pseudo environment to fix bugs with extended
security attributes. Bug-AGL: SPEC-259 Change-Id: I44499ce3f5f1924aecf63689a93d1f20e779225e Signed-off-by: Anton Gerasimov <anton@advancedtelematic.com>
Diffstat (limited to 'recipes-sota/ostree-initrd')
-rw-r--r--recipes-sota/ostree-initrd/files/init.sh84
-rw-r--r--recipes-sota/ostree-initrd/ostree-initrd.bb19
2 files changed, 103 insertions, 0 deletions
diff --git a/recipes-sota/ostree-initrd/files/init.sh b/recipes-sota/ostree-initrd/files/init.sh
new file mode 100644
index 0000000..5aa99d6
--- /dev/null
+++ b/recipes-sota/ostree-initrd/files/init.sh
@@ -0,0 +1,84 @@
1#!/bin/sh
2
3# global variables
4
5SMACK=n
6DEBUG=n
7
8# -------------------------------------------
9
10log_info() { echo "$0[$$]: $@" >&2; }
11log_error() { echo "$0[$$]: ERROR $@" >&2; }
12
13do_mount_fs() {
14 log_info "mounting FS: $@"
15 [[ -e /proc/filesystems ]] && { grep -q "$1" /proc/filesystems || { log_error "Unknown filesystem"; return 1; } }
16 [[ -d "$2" ]] || mkdir -p "$2"
17 [[ -e /proc/mounts ]] && { grep -q -e "^$1 $2 $1" /proc/mounts && { log_info "$2 ($1) already mounted"; return 0; } }
18 mount -t "$1" "$1" "$2"
19}
20
21bail_out() {
22 log_error "$@"
23 log_info "Rebooting..."
24 #exec reboot -f
25 exec sh
26}
27
28get_ostree_sysroot() {
29 for opt in `cat /proc/cmdline`; do
30 arg=`echo $opt | cut -d'=' -f1`
31 if [ $arg == "ostree_root" ]; then
32 echo $opt | cut -d'=' -f2
33 return
34 fi
35 done
36}
37
38export PATH=/sbin:/usr/sbin:/bin:/usr/bin
39
40log_info "starting initrd script"
41
42do_mount_fs proc /proc
43do_mount_fs sysfs /sys
44do_mount_fs devtmpfs /dev
45do_mount_fs devpts /dev/pts
46do_mount_fs tmpfs /dev/shm
47do_mount_fs tmpfs /tmp
48do_mount_fs tmpfs /run
49
50# check if smack is active (and if so, mount smackfs)
51grep -q smackfs /proc/filesystems && {
52 SMACK=y
53
54 do_mount_fs smackfs /sys/fs/smackfs
55
56 # adjust current label and network label
57 echo System >/proc/self/attr/current
58 echo System >/sys/fs/smackfs/ambient
59}
60
61mkdir -p /sysroot
62ostree_sysroot=$(get_ostree_sysroot)
63
64mount $ostree_sysroot /sysroot || bail_out "Unable to mount $ostree_sysroot as physical sysroot"
65ostree-prepare-root /sysroot
66
67# move mounted devices to new root
68cd /sysroot
69for x in dev proc; do
70 log_info "Moving /$x to new rootfs"
71 mount -o move /$x $x
72done
73
74# switch to new rootfs
75log_info "Switching to new rootfs"
76mkdir -p run/initramfs
77
78pivot_root . run/initramfs || bail_out "pivot_root failed."
79
80log_info "Launching target init"
81
82exec chroot . sh -c 'umount /run/initramfs; exec /sbin/init' \
83 <dev/console >dev/console 2>&1
84
diff --git a/recipes-sota/ostree-initrd/ostree-initrd.bb b/recipes-sota/ostree-initrd/ostree-initrd.bb
new file mode 100644
index 0000000..5c85bee
--- /dev/null
+++ b/recipes-sota/ostree-initrd/ostree-initrd.bb
@@ -0,0 +1,19 @@
1SUMMARY = "Extremely basic live image init script"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4SRC_URI = "file://init.sh"
5
6S = "${WORKDIR}"
7
8do_install() {
9 install -dm 0755 ${D}/etc
10 touch ${D}/etc/initrd-release
11 install -dm 0755 ${D}/dev
12 install -dm 0755 ${D}/sbin
13 install -m 0755 ${WORKDIR}/init.sh ${D}/sbin/init
14}
15
16inherit allarch
17
18FILES_${PN} += " /dev /etc/initrd-release /sbin/init "
19