-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-initrdfs-init
51 lines (40 loc) · 1.19 KB
/
simple-initrdfs-init
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
#!/bin/busybox-static sh
# Copyright 2015 Sergey Kvachonok
# Licensed under the CC-BY-SA-3.0 license.
# Based in part on https://wiki.gentoo.org/wiki/Custom_Initramfs
# which is:
# Copyright 2001–2015 Gentoo Foundation, Inc.
# Licensed under the CC-BY-SA-3.0 license.
# Install the symlinks to all busybox applets first.
/bin/busybox-static mkdir -p /usr/sbin /usr/bin /sbin
/bin/busybox-static --install -s
rescue_shell() {
echo "Something went wrong. Dropping to a shell."
exec sh
}
cmdline() {
local value
value=" $(cat /proc/cmdline) "
value="${value##* $1=}"
value="${value%% *}"
[ "$value" != "" ] && echo "$value"
}
# Mount the /dev, /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
echo "Waiting for devices..."
sleep 2
echo "Registering BTRFS block devices"
echo "Root partition candidates:" /dev/sd[a-f]2
btrfs-register /dev/sd[a-f]2
# Mount the root filesystem.
mount -t btrfs -o ro $(findfs $(cmdline root)) /mnt/root || rescue_shell
# Clean up.
umount /proc
umount /sys
umount /dev
# Remount /dev.
mount -t devtmpfs none /mnt/root/dev
# Boot the real thing.
exec switch_root /mnt/root /sbin/init