-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
init.sh.in
55 lines (44 loc) · 1.54 KB
/
init.sh.in
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
45
46
47
48
49
50
51
52
53
54
55
#!/rescue/sh
set -e
PATH="/rescue"
if [ "$(ps -o command 1 | tail -n 1 | ( read -r c o; echo "${o}" ))" = "-s" ]; then
echo "==> Running in single-user mode"
SINGLE_USER="true"
fi
echo "==> Remount rootfs as read-write"
mount -u -w /
makedir=${makedir:-"/cdrom"}
echo "==> Make mountpoints /cdrom"
mkdir -p "${makedir}"
echo "Waiting for GhostBSD media to initialize"
while : ; do
[ -e "/dev/iso9660/GHOSTBSD" ] && echo "found /dev/iso9660/GHOSTBSD" && sleep 2 && break
sleep 2
done
echo "==> Mount cdrom"
mount_cd9660 /dev/iso9660/@VOLUME@ /cdrom
if [ "$SINGLE_USER" = "true" ]; then
echo "Starting interactive shell in temporary rootfs ..."
exit 0
fi
# Ensure the system has more than enough memory for memdisk
requiredmem=4294967296
realmem=$(sysctl -n hw.realmem)
memdisk_size=$((("${realmem}"*75/100)/1024/1024/1024))
echo "Required memory ${requiredmem} for memdisk"
echo "Detected memory ${realmem} for memdisk"
if [ "$realmem" -lt "$requiredmem" ] ; then
SINGLE_USER="true"
echo "GhostBSD requires 4GB of memory for memdisk, and operation!"
echo "Type exit, and press enter after entering the rescue shell to power off."
exit 1
fi
echo "==> Mount swap-based memdisk"
mdconfig -a -t swap -s ${memdisk_size}g -u 1 >/dev/null 2>/dev/null
zpool create livecd /dev/md1 >/dev/null 2>/dev/null
zfs set compression=zstd-9 livecd
zfs set primarycache=none livecd
echo "==> Replicate system image to swap-based memdisk"
dd if=/cdrom/data/system.img status=progress bs=1M | zfs recv -F livecd
kenv init_shell="/rescue/sh"
exit 0