|
root / services / hammerhead / root-fs / start.sh
start.sh Bash 45 lines 1.3 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/zsh
# root-fs — ensure / is mounted read-write
#
# Hammerhead supports both ZFS-rooted and UFS-rooted systems.
#
#   ZFS root:  the kernel mounts / read-write at boot via the bootloader.
#              We defensively assert readonly=off on the active dataset
#              so an admin override (booted snapshot, recovery) is cleared
#              before later tiers write to /.
#
#   UFS root:  the kernel mounts / read-only first; this oneshot remounts
#              read-write so /var, /tmp, etc. can be written. This matches
#              the historical SMF system/filesystem/root method.
#
# We dispatch on the fstype reported in /etc/mnttab.

set -e
set -u

ROOT_FSTYPE="$(awk '$2 == "/" { print $3 }' /etc/mnttab)"

case "$ROOT_FSTYPE" in
    zfs)
        ROOT_DS="$(/sbin/zfs list -H -o name / 2>/dev/null || true)"
        if [[ -z "$ROOT_DS" ]]; then
            print -u2 "root-fs: could not determine root dataset; skipping readonly"
            exit 0
        fi
        /sbin/zfs set readonly=off "$ROOT_DS"
        ;;
    ufs)
        /usr/sbin/mount -F ufs -o remount,rw /
        ;;
    "")
        print -u2 "root-fs: could not determine root fstype from /etc/mnttab"
        exit 1
        ;;
    *)
        print -u2 "root-fs: unrecognized root fstype '$ROOT_FSTYPE'"
        exit 1
        ;;
esac

exit 0