archiso 3.04 KB
Newer Older
Simo Leone's avatar
Simo Leone committed
1
2
3
4
5
6
7
8
9
10
11
12
# args: source, mountpoint
_mnt_bind()
{
    msg "::: Binding ${1} to ${2}"
    mkdir -p /real_root${2}
    /bin/mount -o bind ${addon_dir}/${1} /real_root${2}
}

# args: image file
_mnt_squashfs()
{
    msg "::: Adding new union branch: ${1}"
Simo Leone's avatar
Simo Leone committed
13
    /bin/modprobe -q loop >/dev/null 2>&1
Simo Leone's avatar
Simo Leone committed
14
    mkdir -p "/tmpfs/mnt/loop${LOOP_NUM}"
Simo Leone's avatar
Simo Leone committed
15
    if ! /bin/losetup "/dev/loop${LOOP_NUM}" ${1} > /dev/null 2>&1; then
Simo Leone's avatar
Simo Leone committed
16
17
18
19
20
21
22
23
24
        echo "ERROR: Cannot mount loop device /dev/loop${LOOP_NUM}"
        echo "       Couldn't mount all addons"
        break
    fi
    /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}"
    /bin/mount -t unionfs -o remount,add=:/tmpfs/mnt/loop${LOOP_NUM}=ro none "/real_root"
    export LOOP_NUM=$(( $LOOP_NUM + 1 ))
}

Aaron Griffin's avatar
Aaron Griffin committed
25
26
27
28
29
30
31
32
33
run_hook ()
{
    if [ "x${ramdisk_size}" = "x" ]; then
        ramdisk_size="75%"
    fi
    msg -n ":: Mounting tmpfs, size=${ramdisk_size}..."
	mount -t tmpfs -o "size=${ramdisk_size}" tmpfs /tmpfs
    msg "done."

Dan McGee's avatar
Dan McGee committed
34
    if [ "x${BOOT_MOUNT}" = "x" ]; then
35
36
        echo "ERROR: BOOT_MOUNT is not set. The boot-cd or boot-usb hook MUST"
        echo "       be run before this one.  This image was improperly built"
Aaron Griffin's avatar
Aaron Griffin committed
37
38
39
        exit 1
    fi

40
    base_img="${BOOT_MOUNT}/archlive.sqfs"
41
    if [ "${copytoram}" = "y" ]; then
42
        msg ":: Copying squashfs image to RAM"
43
44
        /bin/cat ${base_img} > /tmpfs/archlive.sqfs
        base_img="/tmpfs/archlive.sqfs"
45
    fi
Aaron Griffin's avatar
   
Aaron Griffin committed
46

Aaron Griffin's avatar
   
Aaron Griffin committed
47
    msg ":: Mounting squashfs image"
Aaron Griffin's avatar
Aaron Griffin committed
48
49
    /bin/modprobe -q squashfs >/dev/null 2>&1

Aaron Griffin's avatar
   
Aaron Griffin committed
50
    msg ":: Mounting root (union) filesystem"
Aaron Griffin's avatar
Aaron Griffin committed
51
    /bin/modprobe -q unionfs >/dev/null 2>&1
Simo Leone's avatar
Simo Leone committed
52
    /bin/mount -t unionfs -o dirs=/tmpfs=rw none /real_root
Aaron Griffin's avatar
Aaron Griffin committed
53

54
    export LOOP_NUM="0"
Simo Leone's avatar
Simo Leone committed
55
    addon_dir="${BOOT_MOUNT}/addons"
Simo Leone's avatar
Simo Leone committed
56
57

    # always layer default configuration
58
    _mnt_squashfs "${addon_dir}/overlay.sqfs"
Simo Leone's avatar
Simo Leone committed
59

Simo Leone's avatar
Simo Leone committed
60
    if [ -e "${addon_dir}/config" ]; then
61
        msg ":: Mounting addons"
Simo Leone's avatar
Simo Leone committed
62
63
        while read img mountpoint type; do
            # check if this line is a comment (starts with #)
Simo Leone's avatar
Simo Leone committed
64
            [ "${img#"#"}" != "${img}" ] && continue
Simo Leone's avatar
Simo Leone committed
65
66

            if [ "${type}" = "bind" ]; then
Simo Leone's avatar
Simo Leone committed
67
                _mnt_bind ${img} ${mountpoint}
Simo Leone's avatar
Simo Leone committed
68
            elif [ "${type}" = "squashfs" ]; then
Simo Leone's avatar
Simo Leone committed
69
                _mnt_squashfs "${addon_dir}/${img}"
Simo Leone's avatar
Simo Leone committed
70
71
            fi
        done < ${addon_dir}/config
72
73
    fi

74
75
    # layer the "pristine" base system image last
    _mnt_squashfs ${base_img}
Simo Leone's avatar
Simo Leone committed
76

Aaron Griffin's avatar
Aaron Griffin committed
77
    if [ -d /proc/sys/dev/cdrom ]; then
Aaron Griffin's avatar
Aaron Griffin committed
78
        echo 0 > /proc/sys/dev/cdrom/lock
Simo Leone's avatar
Simo Leone committed
79
        echo 0 > /proc/sys/dev/cdrom/autoeject
Aaron Griffin's avatar
Aaron Griffin committed
80
81
    fi

82
83
84
85
86
87
    if [ "${break}" = "y" ]; then
        echo ":: Break requested, type 'exit' to resume operation"
        echo "   NOTE: klibc contains no 'ls' binary, use 'echo *' instead"
        PS1="ramfs$ " /bin/sh -i
    fi

Aaron Griffin's avatar
Aaron Griffin committed
88
    udevpid=$(/bin/minips -C udevd -o pid=)
Aaron Griffin's avatar
Aaron Griffin committed
89
    [ "x${udevpid}" != "x" ] && /bin/kill -9 $udevpid 2>&1 >/dev/null
Aaron Griffin's avatar
Aaron Griffin committed
90
    #Yep, we're bailing out here.  We don't need kinit.
Aaron Griffin's avatar
Aaron Griffin committed
91
    msg ":: Passing control to Archlinux Initscripts...Please Wait"
Aaron Griffin's avatar
   
Aaron Griffin committed
92
93
    /bin/umount /sys
    /bin/umount /proc
Aaron Griffin's avatar
Aaron Griffin committed
94
95
    exec /bin/run-init -c /dev/console /real_root /sbin/init ${CMDLINE}
}
Dan McGee's avatar
Dan McGee committed
96
97

# vim:ft=sh:ts=4:sw=4:et: