chromeos-init-systemd: Allow overriding OEM device.

This is useful if you want to share the same persistant disk between two
VMs for configuration or misc storage. Also, if you want to use another
location for storing OEM data (like an encrypted folder using dm-crypt).

BUG=b/209419163
TEST=systemd mounts /usr/share/oem to the specified device, otherwise
falls back to /dev/sda8.
RELEASE_NOTE=none

Change-Id: I838fcfe031df3ed81e885fc5b50d26867a3f3d36
Reviewed-on: https://cos-review.googlesource.com/c/cos/overlays/board-overlays/+/27241
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Roy Yang <royyang@google.com>
diff --git a/project-lakitu/chromeos-base/chromeos-init-systemd/chromeos-init-systemd-0.0.1-r27.ebuild b/project-lakitu/chromeos-base/chromeos-init-systemd/chromeos-init-systemd-0.0.1-r28.ebuild
similarity index 100%
rename from project-lakitu/chromeos-base/chromeos-init-systemd/chromeos-init-systemd-0.0.1-r27.ebuild
rename to project-lakitu/chromeos-base/chromeos-init-systemd/chromeos-init-systemd-0.0.1-r28.ebuild
diff --git a/project-lakitu/chromeos-base/chromeos-init-systemd/files/chromeos-mount-generator b/project-lakitu/chromeos-base/chromeos-init-systemd/files/chromeos-mount-generator
index 46f8176..64e7082 100755
--- a/project-lakitu/chromeos-base/chromeos-init-systemd/files/chromeos-mount-generator
+++ b/project-lakitu/chromeos-base/chromeos-init-systemd/files/chromeos-mount-generator
@@ -40,6 +40,14 @@
 #     /dev/disk/by-id/google-persistent-disk-0) will be formatted if need be and
 #     mounted at /var/log.
 #
+# cos.oem_dev=[path]
+#   This command line arguments indicates the block device that should be used
+#   for /usr/share/oem.
+#
+#  [path]:
+#    If empty, COS will use the default location as the 8th partition on the
+#    disk.
+#
 # When editing this file, keep in mind that we can't use heredocs here because
 # using heredocs creates a tempfile. A tmpfs isn't mounted at /tmp this early in
 # the boot process, causing /tmp to be read-only.
@@ -53,6 +61,7 @@
 STATEFUL_DEV=""
 MKFS_STATEFUL=""
 LOGS_DEV=""
+OEM_DEV=""
 
 # Parses arguments from the kernel command line and stores values in flag
 # variables.
@@ -72,6 +81,9 @@
       cos.logs_dev=*)
         LOGS_DEV="${arg#cos.logs_dev=}"
         ;;
+      cos.oem_dev=*)
+        OEM_DEV="${arg#cos.oem_dev=}"
+        ;;
       *)
         ;;
     esac
@@ -104,19 +116,22 @@
   local -r enable_dir="$4"
   local -r disk="$(basename ${dev})"
   local exec_opt="noexec"
-  # After sealing the OEM partition, it will be available through
-  # /dev/dm-[0-9]* instead of /dev/sda8
-  dev_holder_count=$(ls /sys/class/block/${disk}/holders | wc -l)
-  if [[ ${dev_holder_count} -gt 1 ]]; then
-    return
-  fi
+  if [[ -n "${OEM_DEV}" ]]; then
+    dev="${OEM_DEV}"
+  else
+    # After sealing the OEM partition, it will be available through
+    # /dev/dm-[0-9]* instead of /dev/sda8
+    dev_holder_count=$(ls /sys/class/block/${disk}/holders | wc -l)
+    if [[ ${dev_holder_count} -gt 1 ]]; then
+      return
+    fi
 
-  local dev_holder="$(basename /sys/class/block/${disk}/holders/*)"
-  if [[ ${dev_holder} != "*" ]]; then
-    dev="/dev/${dev_holder}"
-    exec_opt="exec"
+    local dev_holder="$(basename /sys/class/block/${disk}/holders/*)"
+    if [[ ${dev_holder} != "*" ]]; then
+      dev="/dev/${dev_holder}"
+      exec_opt="exec"
+    fi
   fi
-
   echo "
 [Unit]
 Before=local-fs.target