diff options
author | Anton Gerasimov <anton@advancedtelematic.com> | 2016-10-04 14:42:42 +0200 |
---|---|---|
committer | Anton Gerasimov <anton@advancedtelematic.com> | 2016-10-04 14:42:42 +0200 |
commit | 7bd3693b986e0a6e59016767ea6f075ba01ab68c (patch) | |
tree | 8cf3fc3f8a6a546ca1f734cd56e3d4e8fca58faf /recipes-sota/ostree-initrd | |
parent | 844ddcf4496edfdb9b682f712ab1ae1cd16f1f97 (diff) | |
download | meta-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.sh | 84 | ||||
-rw-r--r-- | recipes-sota/ostree-initrd/ostree-initrd.bb | 19 |
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 | |||
5 | SMACK=n | ||
6 | DEBUG=n | ||
7 | |||
8 | # ------------------------------------------- | ||
9 | |||
10 | log_info() { echo "$0[$$]: $@" >&2; } | ||
11 | log_error() { echo "$0[$$]: ERROR $@" >&2; } | ||
12 | |||
13 | do_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 | |||
21 | bail_out() { | ||
22 | log_error "$@" | ||
23 | log_info "Rebooting..." | ||
24 | #exec reboot -f | ||
25 | exec sh | ||
26 | } | ||
27 | |||
28 | get_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 | |||
38 | export PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
39 | |||
40 | log_info "starting initrd script" | ||
41 | |||
42 | do_mount_fs proc /proc | ||
43 | do_mount_fs sysfs /sys | ||
44 | do_mount_fs devtmpfs /dev | ||
45 | do_mount_fs devpts /dev/pts | ||
46 | do_mount_fs tmpfs /dev/shm | ||
47 | do_mount_fs tmpfs /tmp | ||
48 | do_mount_fs tmpfs /run | ||
49 | |||
50 | # check if smack is active (and if so, mount smackfs) | ||
51 | grep -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 | |||
61 | mkdir -p /sysroot | ||
62 | ostree_sysroot=$(get_ostree_sysroot) | ||
63 | |||
64 | mount $ostree_sysroot /sysroot || bail_out "Unable to mount $ostree_sysroot as physical sysroot" | ||
65 | ostree-prepare-root /sysroot | ||
66 | |||
67 | # move mounted devices to new root | ||
68 | cd /sysroot | ||
69 | for x in dev proc; do | ||
70 | log_info "Moving /$x to new rootfs" | ||
71 | mount -o move /$x $x | ||
72 | done | ||
73 | |||
74 | # switch to new rootfs | ||
75 | log_info "Switching to new rootfs" | ||
76 | mkdir -p run/initramfs | ||
77 | |||
78 | pivot_root . run/initramfs || bail_out "pivot_root failed." | ||
79 | |||
80 | log_info "Launching target init" | ||
81 | |||
82 | exec 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 @@ | |||
1 | SUMMARY = "Extremely basic live image init script" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
4 | SRC_URI = "file://init.sh" | ||
5 | |||
6 | S = "${WORKDIR}" | ||
7 | |||
8 | do_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 | |||
16 | inherit allarch | ||
17 | |||
18 | FILES_${PN} += " /dev /etc/initrd-release /sbin/init " | ||
19 | |||