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

Aaron Griffin's avatar
Aaron Griffin committed
9
# args: /path/to/image_file
Simo Leone's avatar
Simo Leone committed
10
11
_mnt_squashfs()
{
Simo Leone's avatar
Simo Leone committed
12
    /bin/modprobe -q loop >/dev/null 2>&1
Aaron Griffin's avatar
Aaron Griffin committed
13
14
15
    
    img="${1}"
    base_img="${img##*/}";
16
    mnt="${2}"
Aaron Griffin's avatar
Aaron Griffin committed
17
18
19
20
21
22
23

    if [ "${copytoram}" = "y" ]; then
        msg ":: Copying squashfs image to RAM"
        /bin/cat ${img} > "/tmpfs/${base_img}"
        img="/tmpfs/${base_img}"
    fi

Aaron Griffin's avatar
Aaron Griffin committed
24
    msg "::: Adding new aufs branch: ${base_img%.*}"
Simo Leone's avatar
Simo Leone committed
25
    mkdir -p "/tmpfs/mnt/loop${LOOP_NUM}"
Simo Leone's avatar
Simo Leone committed
26
    # sometimes it takes udev a while to create device nodes
Aaron Griffin's avatar
Aaron Griffin committed
27
    while [ ! -e "/dev/loop${LOOP_NUM}" ]; do
Simo Leone's avatar
Simo Leone committed
28
29
        sleep 1
    done
Aaron Griffin's avatar
Aaron Griffin committed
30
    if ! /bin/losetup "/dev/loop${LOOP_NUM}" ${img}; then
Simo Leone's avatar
Simo Leone committed
31
32
33
34
        echo "ERROR: Cannot mount loop device /dev/loop${LOOP_NUM}"
        break
    fi
    /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}"
35
    if [ "${mnt}" = "/" ]; then
36
        /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "/real_root"
37
38
39
    else
        _mnt_bind "/tmpfs/mnt/loop${LOOP_NUM}" "${mnt}"
    fi
Simo Leone's avatar
Simo Leone committed
40
41
42
    export LOOP_NUM=$(( $LOOP_NUM + 1 ))
}

Aaron Griffin's avatar
Aaron Griffin committed
43
44
run_hook ()
{
45
46
47
48
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

Aaron Griffin's avatar
Aaron Griffin committed
49
50
51
52
53
54
55
    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."

56
    # external drives may need to settle
Aaron Griffin's avatar
Aaron Griffin committed
57
    msg ":: Waiting for devices to settle..."
58
59
    /sbin/udevadm trigger --subsystem-match=usb
    /sbin/udevadm settle
60
61
62
    usbdelay=$(( ${usbdelay:-0} + 1 ))
    msg ":: Waiting ${usbdelay}s for USB devices"
    /bin/sleep "${usbdelay}"
63
64
65
66
67
68
69
70

    msg ":: Scanning for boot device..."

    /bin/mkdir -p /bootmnt
    found=0

    /bin/modprobe -q isofs >/dev/null 2>&1
    msg ":: Scanning cd drives..."
Simo Leone's avatar
Simo Leone committed
71
    for cdrom in /dev/hd[a-z] /dev/sr[0-9]* /dev/scd[a-z] /dev/sg[0-9]*; do
72
        [ ! -e "${cdrom}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
73
74
        if mount -r -t iso9660 "${cdrom}" /bootmnt >/dev/null 2>&1; then
            if [ -e "/bootmnt/isomounts" ]; then
75
76
77
78
79
80
81
                found=1
                msg "${cdrom}"
                break
            fi
        else
            echo "Failed to mount ${cdrom}"
        fi
Aaron Griffin's avatar
Aaron Griffin committed
82
        [ ${found} -eq 0 ] && umount /bootmnt >/dev/null 2>&1
83
84
85
86
87
    done

    if [ ${found} -eq 0 ]; then
        msg ":: Scanning usb drives..."
        for usb in /dev/sd[a-z][0-9]; do
88
            [ ! -e "${usb}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
89
90
91
            if mount -r -t vfat "${usb}" /bootmnt >/dev/null 2>&1 ||\
                mount -r -t ext2 "${usb}" /bootmnt >/dev/null 2>&1; then
                if [ -e "/bootmnt/isomounts" ]; then
92
93
94
95
96
97
98
                    found=1
                    msg "${usb}"
                    break
                fi
            else
                echo "Failed to mount ${usb}"
            fi
Aaron Griffin's avatar
Aaron Griffin committed
99
            [ ${found} -eq 0 ] && umount /bootmnt >/dev/null 2>&1
100
101
102
103
104
        done
    fi

    if [ ${found} -eq 0 ]; then
        echo "ERROR: cannot find boot device, cannot continue..."
105
106
        echo "   Falling back to interactive prompt"
        PS1="ramfs$ " /bin/sh -i
Aaron Griffin's avatar
Aaron Griffin committed
107
108
109
110
        exit 1
    fi

    /bin/modprobe -q squashfs >/dev/null 2>&1
Aaron Griffin's avatar
Aaron Griffin committed
111
    /bin/modprobe -q aufs >/dev/null 2>&1
Aaron Griffin's avatar
Aaron Griffin committed
112

Aaron Griffin's avatar
Aaron Griffin committed
113
114
    msg ":: Mounting root (aufs) filesystem"
    /bin/mount -t aufs -o dirs=/tmpfs=rw none /real_root
Aaron Griffin's avatar
Aaron Griffin committed
115

116
    export LOOP_NUM="0"
Aaron Griffin's avatar
Aaron Griffin committed
117
118
119
120
121
122
123
124
125
126
127
128
    msg ":: Mounting images"
    while read img imgarch mountpoint type; do
        # check if this line is a comment (starts with #)
        [ "${img#"#"}" != "${img}" ] && continue

        [ "$imgarch" != "$arch" ] && continue

        [ ! -f "/bootmnt/${img}" ] && continue

        if [ "${type}" = "bind" ]; then
            _mnt_bind "/bootmnt/${img}" ${mountpoint}
        elif [ "${type}" = "squashfs" ]; then
129
            _mnt_squashfs "/bootmnt/${img}" "${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
130
131
        fi
    done < "/bootmnt/isomounts"
132

Aaron Griffin's avatar
Aaron Griffin committed
133
134
    # Bind our bootmnt dir into the live system
    _mnt_bind /bootmnt bootmnt
Simo Leone's avatar
Simo Leone committed
135

Aaron Griffin's avatar
Aaron Griffin committed
136
    if [ -d /proc/sys/dev/cdrom ]; then
Aaron Griffin's avatar
Aaron Griffin committed
137
        echo 0 > /proc/sys/dev/cdrom/lock
Simo Leone's avatar
Simo Leone committed
138
        echo 0 > /proc/sys/dev/cdrom/autoeject
Aaron Griffin's avatar
Aaron Griffin committed
139
140
    fi

141
142
143
144
145
146
    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
147
    udevpid=$(/bin/minips -C udevd -o pid=)
Aaron Griffin's avatar
Aaron Griffin committed
148
    [ "x${udevpid}" != "x" ] && /bin/kill -9 $udevpid 2>&1 >/dev/null
Aaron Griffin's avatar
Aaron Griffin committed
149
    #Yep, we're bailing out here.  We don't need kinit.
150
    msg ":: Passing control to Arch Linux Initscripts...Please Wait"
Aaron Griffin's avatar
   
Aaron Griffin committed
151
152
    /bin/umount /sys
    /bin/umount /proc
Aaron Griffin's avatar
Aaron Griffin committed
153
154
    exec /bin/run-init -c /dev/console /real_root /sbin/init ${CMDLINE}
}
Dan McGee's avatar
Dan McGee committed
155
156

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