summaryrefslogtreecommitdiff
path: root/meta-phosphor/recipes-phosphor/initrdscripts
AgeCommit message (Collapse)AuthorFilesLines
2021-08-11meta-phosphor: prep for new override syntaxPatrick Williams2-5/+5
Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: I588025b614416c43aa2d053765ab53bacf890cb5
2021-07-21mmc-init: Add factory reset based on rwresetIsaac Kurth2-0/+14
To enable factory resets, the mmc-init.sh script checks on reboot if the environment variable rwreset is set to "true". If it is, the rw parts of the file system that users may have modified are reformatted to remove all user changes and rwreset is set to "false". Tested: Add a file to /var and use fw_setenv to set rwreset to true. Reboot the machine and verify that the added file is gone and rwreset is set to false. Signed-off-by: Isaac Kurth <isaac.kurth@ibm.com> Change-Id: I2d8b4f4eaf8ff6df092893760aaae9db2ce3917b
2021-05-03phosphor-mmc-init: Determine EFI partition presence via exit codeAndrew Jeffery1-2/+1
Testing if $magic is empty is an indirect test of whether the grep succeeded. Instead, just use the grep exit code. Change-Id: I3eba40e8b54863ab9a1a4436f1419b69c5bea8e1 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
2021-04-30phosphor-mmc-init: exec switch_root(8) rather than chroot(1)Andrew Jeffery1-1/+1
It was found that perf(1) had some issues with recording and analysing data on Rainier systems: ``` root@rainier:~# perf probe --add mem_serial_in root@rainier:~# perf record -e probe:mem_serial_in -aR sleep 1 [ perf record: Woken up 1 times to write data ] assertion failed at util/namespaces.c:257 No kallsyms or vmlinux with build-id e4e9c7cff1deb3bf32958039c696f094dc76cf5c was found [ perf record: Captured and wrote 0.377 MB perf.data (25 samples) ] root@rainier:~# perf script -v build id event received for [kernel.kallsyms]: e4e9c7cff1deb3bf32958039c696f094dc76cf5c broken or missing trace data incompatible file format (rerun with -v to learn more) ``` Starting with the failed assertion in the recording, we find the relevant code is the following WARN_ON_ONCE(): ``` void nsinfo__mountns_exit(struct nscookie *nc) { ... if (nc->oldcwd) { WARN_ON_ONCE(chdir(nc->oldcwd)); zfree(&nc->oldcwd); } ``` A strace of `perf record` demonstrates the relevant syscall sequence, where /home/root is the working directory at the time when `perf record` is invoked. ``` openat(AT_FDCWD, "/proc/self/ns/mnt", O_RDONLY|O_LARGEFILE) = 12 openat(AT_FDCWD, "/proc/142/ns/mnt", O_RDONLY|O_LARGEFILE) = 13 setns(13, CLONE_NEWNS) = 0 statx(AT_FDCWD, "/mnt/rofs/bin/udevadm", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|0x1000, stx_attributes=0, stx_mode=S_IFREG|0755, stx_size=978616, ...}) = 0 openat(AT_FDCWD, "/mnt/rofs/bin/udevadm", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 14 setns(12, CLONE_NEWNS) = 0 chdir("/home/root") = -1 ENOENT (No such file or directory) ``` From the path of the binary, PID 142 is executing in an unanticipated environment. Its path is representative of the state of the filesystem prior to the initramfs handing over to /sbin/init in the real root, suggesting an issue with the initramfs' /init implementation. In /init we find a bunch of setup to discover and mount the root device. At the end of the script we prepare for the real root by exec'ing chroot. From `man 2 chroot`[0]: ``` DESCRIPTION chroot() changes the root directory of the calling process to that speci‐ fied in path. This directory will be used for pathnames beginning with /. The root directory is inherited by all children of the calling process. ``` Specifically, this outlines that chroot(2) affects the state of the calling *process* and not the state of mount namespace in use by the process. Further, a call to `setns(..., CLONE_NEWNS)` explicitly replaces the mount namespace for the *process*, and as such destroys any chroot state that might have been associated with the process' original mount namespace. As the chroot state is not a property of a mount namespace, switching *back* to the application's original mount namespace does not restore the process' original chroot state. As such, the chdir(2) from the strace output above returns an error, as the get_current_dir_name(3) call that yielded the provided path was issued prior to switching into the target process' mount namespace, and was thus derived in the chroot context. The path is therefore invalid once the original mount namespace is restored via the second setns(2) as the process has (already) lost the chroot context for the original namespace. For perf(1) to work in its current implementation the effective root for PID 1 must remain the absolute path "/" with respect to the kernel's VFS layer. This requires /init to use either pivot_root(1) or switch_root(1). pivot_root(1) is ruled out by its own man-page[1]: ``` NOTES ... The rootfs (initial ramfs) cannot be pivot_root()ed. The recommended method of changing the root filesystem in this case is to delete every‐ thing in rootfs, overmount rootfs with the new root, attach stdin/std‐ out/stderr to the new /dev/console, and exec the new init(1). Helper pro‐ grams for this process exist; see switch_root(8). ... ``` As noted, the recommendation is a description of the switch_root(8) application[2]. The details of why the specific sequence for switch_root(8) is necessary is documented in [3]. Change /init to use switch_root(8) to avoid the nasty interaction of chroot(2) and setns(2). [0] https://man7.org/linux/man-pages/man2/chroot.2.html#DESCRIPTION [1] https://man7.org/linux/man-pages/man2/pivot_root.2.html#NOTES [2] https://man7.org/linux/man-pages/man8/switch_root.8.html [3] https://git.busybox.net/busybox/tree/util-linux/switch_root.c?h=1_32_1#n298 Change-Id: Iac29b53a462b03559d18fe9b600aefcd1951057e Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
2020-09-01mmc-init: Run fsck.ext4 on the rwfs deviceAdriana Kobylak1-1/+4
It's a good practice to run fsck before mounting a device. Call fsck.ext4 -p on the read-write device, this option attempts to fix any error that can be fixed safely without user intervention. No need to check for the return code, if it fails then the mount command will likely fail. It also takes no time to run: mount read-only -> fsck read-write -> mount read-write: [ 4.174115] EXT4-fs (mmcblk0p4): mounted filesystem with ordered data mode. Opts: (null) rwfs: clean, 11/917504 files, 81919/1835008 blocks [ 4.185143] EXT4-fs (mmcblk0p6): mounted filesystem with ordered data mode. Opts: (null) (From meta-phosphor rev: c3d695892ef990f70cb851b5613dee68068471b3) Change-Id: I946791233a06da0c8ee16585d92f64039a845879 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
2020-09-01phosphor-mmc-init: Add fsck.ext4Adriana Kobylak1-0/+1
Add fsck.ext4 to the eMMC initramfs to be able to manually correct ext4 errors, fsck.ext4 already exists in user space. Tested: Verified it was added to the initramfs: / # which fsck.ext4 /sbin/fsck.ext4 / # fsck.ext4 /dev/mmcblk0p2 e2fsck 1.45.6 (20-Mar-2020) boot-a: clean, 12/8192 files, 12464/65536 blocks (From meta-phosphor rev: d6b1a2682168006ad8445b300b2cca1edc6fcbfc) Change-Id: If5931bea4da7485109aff64cba5d37722abd3dc9 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
2020-08-21mmc-init.sh: Wait for mmc deviceAdriana Kobylak1-2/+14
The initramfs was accessing the mmc device before it was probed in some cases, leading to this error message: [ 4.412464] mmcblk0rpmb: mmc0:0001 R1J56L partition 3 128 KiB, chardev (248:0) tail: can't open '/dev/mmcblk0': No such file or directory tail: no files [ 5.471158] mmcblk0: p1 p2 p3 p4 p5 p6 p7 Implement a wait loop of up to 5s to wait for the device, similar to what the kernel would do with rootwait. Tested: Verified the error is not longer seen. Printing the count value as debug, it took one sleep iteration to appear: [ 4.396492] mmcblk0boot1: mmc0:0001 R1J56L partition 2 16.0 MiB 0 [ 4.403500] mmcblk0rpmb: mmc0:0001 R1J56L partition 3 128 KiB, chardev (248:0) [ 4.416176] mmcblk0: p1 p2 p3 p4 p5 p6 p7 1 [ 6.159693] EXT4-fs (mmcblk0p4): mounted filesystem with ordered data mode. Opts: (null) (From meta-phosphor rev: b7dccc1c380431f4cc96e0228fb9975d33df1f88) Change-Id: I625a879882311285dbdeaa2ea271c379366f4b9b Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
2020-07-15obmc-init.sh: Use u-boot env instead of password for emergency consoleAdriana Kobylak1-7/+19
The password prompt doesn't work anymore. Since it relied on the default password, remove the password prompt and just drop into a shell if a new enable-initrd-debug-sh u-boot environment value is set. The security implications are the same since the default password is public and there is a need to have access to u-boot to set the environment value. If the environment value is not set, kernel panic the system. Closes openbmc/openbmc#3649 Tested: Verified kernel panic if environment value was not set, and if it was set the emergency console dropped into a shell and basic linux commands worked: Mounting read-write /dev/mtdblock5 filesystem failed. Please fix and run mount /dev/mtdblock5 run/initramfs/rw -t jffs2 -o rw or perform a factory reset with the clean-rwfs-filesystem option. Try to manually fix. After fixing run exit to continue this script, or reboot -f to retry, or touch /takeover and exit to become PID 1 allowing editing of this script. /bin/sh: can't access tty; job control turned off / # (From meta-phosphor rev: 368550b2d259ac8d08c993b0d695f38aec8992fa) Change-Id: I0431690b3b4facadbe224fc822d6bd06f35b51f5 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
2020-07-15initramfs: Add init script for eMMCAdriana Kobylak2-0/+77
This init script mounts the rootfs based on the root u-boot env variable, mounts the read-write filesystem and sets up the overlay. (From meta-phosphor rev: 86164b2e072cc6cebc9caf1614e2b1fa0e0884a0) Change-Id: If9121048b6223d5391e5f6a8b7d6cd7d22707969 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
2019-09-20meta-phosphor: Remove references to PHOSPHORBASEBrad Bishop1-1/+1
PHOSPHORBASE is only used for pointing at licenses...point at the licenses in oe-core in meta/files/common-licenses instead. to match the defacto convention used in other oe layers like meta-openembedded. (From meta-phosphor rev: a1cee09419cb1467c3d2b7bf996b40089f0d06f4) Change-Id: If136d24638a8022671988cf0a01620e7fffc545f Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
2018-09-06meta-phosphor: Move layer content from common/Brad Bishop5-0/+850
Adopt a more conventional directory hierarchy. meta-phosphor is still a _long_ way from suitable for hosting on yoctoproject.org but things like this don't help. (From meta-phosphor rev: 471cfcefa74b8c7ceb704cb670e6d915cf27c63b) Change-Id: I3f106b2f6cdc6cec734be28a6090800546f362eb Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>