Adriana Kobylak | 86164b2 | 2020-06-03 16:22:42 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Get the value of the root env variable found in /proc/cmdline |
| 4 | get_root() { |
| 5 | local root="$(cat /proc/cmdline)" |
| 6 | root="${root##* root=PARTLABEL=}" |
| 7 | root="${root%% *}" |
| 8 | [ "${root}" != "" ] && echo "${root}" |
| 9 | } |
| 10 | |
| 11 | fslist="proc sys dev run" |
| 12 | rodir=/mnt/rofs |
| 13 | cd / |
| 14 | mkdir -p $fslist |
| 15 | mount dev dev -tdevtmpfs |
| 16 | mount sys sys -tsysfs |
| 17 | mount proc proc -tproc |
| 18 | mount tmpfs run -t tmpfs -o mode=755,nodev |
| 19 | |
| 20 | # Move the secondary GPT to the end of the device if needed. Look for the GPT |
| 21 | # header signature "EFI PART" located 512 bytes from the end of the device. |
| 22 | magic=$(tail -c 512 /dev/mmcblk0 | hexdump -C -n 8 | grep "EFI PART") |
| 23 | if test -z "${magic}"; then |
| 24 | sgdisk -e /dev/mmcblk0 |
| 25 | partprobe |
| 26 | fi |
| 27 | |
| 28 | # There eMMC GPT labels for the rootfs are rofs-a and rofs-b, and the label for |
| 29 | # the read-write partition is rwfs. Run udev to make the partition labels show |
| 30 | # up. Mounting by label allows for partition numbers to change if needed. |
| 31 | udevd --daemon |
| 32 | udevadm trigger --type=devices --action=add |
| 33 | udevadm settle --timeout=10 |
| 34 | |
| 35 | mkdir -p $rodir |
| 36 | if ! mount /dev/disk/by-partlabel/"$(get_root)" $rodir -t ext4 -o ro; then |
| 37 | /bin/sh |
| 38 | fi |
| 39 | if ! mount /dev/disk/by-partlabel/rwfs $rodir/var -t ext4 -o rw; then |
| 40 | /bin/sh |
| 41 | fi |
| 42 | |
| 43 | rm -rf $rodir/var/persist/etc-work/ |
| 44 | mkdir -p $rodir/var/persist/etc $rodir/var/persist/etc-work $rodir/var/persist/home/root |
| 45 | mount overlay $rodir/etc -t overlay -o lowerdir=$rodir/etc,upperdir=$rodir/var/persist/etc,workdir=$rodir/var/persist/etc-work |
| 46 | |
| 47 | for f in $fslist; do |
| 48 | mount --move $f $rodir/$f |
| 49 | done |
| 50 | |
| 51 | exec chroot $rodir /sbin/init |