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

10
11
# args: /path/to/image_file, mountpoint
_mnt_squashfs() {
Aaron Griffin's avatar
Aaron Griffin committed
12
    img="${1}"
13
    mnt="${2}"
14
15
16
    img_fullname="${img##*/}";
    img_name="${img_fullname%.*}"
    tmp_mnt="/tmpfs/mnt/${img_name}"
Aaron Griffin's avatar
Aaron Griffin committed
17

18
19
20
    msg "::: Adding new aufs branch: ${img_name}"
    mkdir -p "${tmp_mnt}"
    /bin/mount -r -t squashfs "${img}" "${tmp_mnt}"
21
22
    if [ "/${mnt#/*/}" = "/" ]; then
        /bin/mount -t aufs -o remount,append:"${tmp_mnt}"=ro none "${mnt}"
23
    else
24
        _mnt_bind "${tmp_mnt}" "${mnt}"
25
    fi
Simo Leone's avatar
Simo Leone committed
26
27
}

28
run_hook () {
29
30
31
32
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

33
34
    if [ "x${tmpfs_size}" = "x" ]; then
        tmpfs_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
35
    fi
36
37
38
39
40
41
42

    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
        isomounts="/bootmnt/isomounts"
    fi

43
44
45
46
    if [ "x${archisodevice}" = "x" ]; then
        archisodevice="/dev/archiso"
    fi

47
48
49
50
51
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
52
    newroot="${1}"
53

54
55
    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
    mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs
Aaron Griffin's avatar
Aaron Griffin committed
56
57
    msg "done."

58
    msg ":: Waiting for boot device..."
59
    while ! poll_device ${archisodevice} 30; do
60
61
62
63
        echo "ERROR: boot device didn't show up after 30 seconds..."
        echo "   Falling back to interactive prompt"
        echo "   You can try to fix the problem manually, log out when you are finished"
        launch_interactive_shell
64
    done
65

66
    FSTYPE=$(blkid -o value -s TYPE ${archisodevice} 2> /dev/null)
67
    if [ -n "${FSTYPE}" ]; then
68
        if mount -r -t "${FSTYPE}" ${archisodevice} /bootmnt > /dev/null 2>&1; then
69
            if [ -e "${isomounts}" ]; then
70
                echo "SUCCESS: Mounted archiso volume successfully."
71
                fserror="0"
72
            else
73
                echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist."
74
                fserror="1"
75
76
            fi
        else
77
            echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})"
78
            fserror="1"
79
        fi
80
    else
81
        echo "ERROR: ${archisodevice} found, but the filesystem type is unknown."
82
83
84
85
86
87
88
        fserror="1"
    fi

    if [ "${fserror}" = "1" ]; then
        echo "   Falling back to interactive prompt"
        echo "   You can try to fix the problem manually, log out when you are finished"
        launch_interactive_shell
Aaron Griffin's avatar
Aaron Griffin committed
89
90
    fi

Aaron Griffin's avatar
Aaron Griffin committed
91
    msg ":: Mounting root (aufs) filesystem"
92
    /bin/mount -t aufs -o dirs=/tmpfs=rw none "${newroot}"
93
94
95
96
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
        exit 1
    fi
Aaron Griffin's avatar
Aaron Griffin committed
97

Aaron Griffin's avatar
Aaron Griffin committed
98
99
100
101
102
103
104
    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

105
        [ ! -r "/bootmnt/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
106
107

        if [ "${type}" = "bind" ]; then
108
            _mnt_bind "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
109
        elif [ "${type}" = "squashfs" ]; then
110
            _mnt_squashfs "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
111
        fi
112
    done < "${isomounts}"
113

Aaron Griffin's avatar
Aaron Griffin committed
114
    # Bind our bootmnt dir into the live system
115
    _mnt_bind /bootmnt "${newroot}/bootmnt"
Simo Leone's avatar
Simo Leone committed
116

117
118
119
120
121
    if [ "${FSTYPE}" = "iso9660" -o "${FSTYPE}" = "udf" ]; then
        if [ -d /proc/sys/dev/cdrom ]; then
            echo 0 > /proc/sys/dev/cdrom/lock
            echo 0 > /proc/sys/dev/cdrom/autoeject
        fi
Aaron Griffin's avatar
Aaron Griffin committed
122
123
124
    fi

}
Dan McGee's avatar
Dan McGee committed
125
126

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