summaryrefslogtreecommitdiff
path: root/init
blob: 01774c652ab82ab4c409eb7c3fbe77afbdd61336 (plain)
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
56
57
58
59
60
61
62
#!/bin/busybox sh

ROOT=/dev/disk/by-label/rootfs
HOME=/dev/disk/by-uuid/092fdc4a-4356-47d9-9272-9a5f58e33bbf

prep_dev()
{
    for opt in `cat /proc/cmdline`; do
      name=$(echo $opt | cut -d'=' -f 1)
      if [ $name == "root" ] || [ $name == "crypt_part" ]; then
        type=$(echo $opt | cut -d'=' -f 2)
        id=$(echo $opt | cut -d'=' -f 3)
        if [ $type == LABEL ]; then
          prefix="/dev/disk/by-label";
        elif [ $type == UUID ]; then
          prefix="/dev/disk/by-uuid"
        fi
        mkdir -p $prefix
        full="$prefix/$id"
        if [ ! -e $full ]; then
          ln -s $(findfs "$type=$id") $full
        fi
      fi
    done
}

rescue_shell()
{
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

cryptsetup_do()
{
  echo "cryptsetup $1 $2"
  cryptsetup -T 3 luksOpen $1 $2
}

mount_root()
{
  echo "mount root $1"
  mount $1 /newroot
}

mkdir -p /dev /proc /sys /newroot /etc
touch /etc/mtab

mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys

prep_dev
cryptsetup_do $HOME home
mount_root $ROOT || rescue_shell

umount /dev
umount /proc
umount /sys

exec switch_root /newroot /sbin/init