archiso 4.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
# args: source, mountpoint
_mnt_aufs() {
    src="${1}"
    mnt="${2}"
    msg "::: Adding new aufs branch: ${src} to ${mnt}"
    mkdir -p "${mnt}"
    /bin/mount -t aufs -o remount,append:"${src}"=ro none "${mnt}"
}

Simo Leone's avatar
Simo Leone committed
10
# args: source, mountpoint
11
_mnt_bind() {
12
13
14
15
16
    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
17
18
}

19
20
# args: /path/to/image_file, mountpoint
_mnt_squashfs() {
Aaron Griffin's avatar
Aaron Griffin committed
21
    img="${1}"
22
    mnt="${2}"
23
24
25
    img_fullname="${img##*/}";
    img_name="${img_fullname%.*}"
    tmp_mnt="/tmpfs/mnt/${img_name}"
Aaron Griffin's avatar
Aaron Griffin committed
26

27
    if [ "${copytoram}" = "y" ]; then
28
        msg -n ":: Copying squashfs image to RAM..."
29
30
        /bin/cp "${img}" "/tmpfs.sqfs/${img_fullname}"
        img="/tmpfs.sqfs/${img_fullname}"
31
        msg "done."
32
33
    fi

34
35
    mkdir -p "${tmp_mnt}"
    /bin/mount -r -t squashfs "${img}" "${tmp_mnt}"
36

37
    if [ "/${mnt#/*/}" = "/" ]; then
38
        _mnt_aufs "${tmp_mnt}" "${mnt}"
39
    else
40
        _mnt_bind "${tmp_mnt}" "${mnt}"
41
    fi
Simo Leone's avatar
Simo Leone committed
42
43
}

44
run_hook () {
45
46
47
48
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

49
50
    if [ "x${tmpfs_size}" = "x" ]; then
        tmpfs_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
51
    fi
52

53
54
55
56
    if [ "x${tmpfs_sqfs_size}" = "x" ]; then
        tmpfs_sqfs_size="75%"
    fi

57
58
59
60
    if [ "x${archisobasedir}" != "x" ]; then
        archisobasedir=""
    fi

61
62
63
    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
64
        isomounts="/bootmnt/${archisobasedir}/isomounts"
65
66
    fi

67
    if [ "x${archisodevice}" = "x" ]; then
68
        archisodevice="/dev/disk/by-label/${archisolabel}"
69
70
    fi

71
72
73
74
75
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
76
    newroot="${1}"
77

78
    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
79
    mount -t tmpfs -o "size=${tmpfs_size}",mode=0755 tmpfs /tmpfs
Aaron Griffin's avatar
Aaron Griffin committed
80
81
    msg "done."

82
83
    if [ "${copytoram}" = "y" ]; then
        msg -n ":: Mounting tmpfs (for squashfs), size=${tmpfs_sqfs_size}..."
84
        mount -t tmpfs -o "size=${tmpfs_sqfs_size}",mode=0755 tmpfs /tmpfs.sqfs
85
86
87
        msg "done."
    fi

88
    msg ":: Waiting for boot device..."
89
    while ! poll_device ${archisodevice} 30; do
90
91
92
93
        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
94
    done
95

96
    FSTYPE=$(blkid -o value -s TYPE -p ${archisodevice} 2> /dev/null)
97
    if [ -n "${FSTYPE}" ]; then
98
        if mount -r -t "${FSTYPE}" ${archisodevice} /bootmnt > /dev/null 2>&1; then
99
            if [ -e "${isomounts}" ]; then
100
                echo "SUCCESS: Mounted archiso volume successfully."
101
                fserror="0"
102
            else
103
                echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist."
104
                fserror="1"
105
106
            fi
        else
107
            echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})"
108
            fserror="1"
109
        fi
110
    else
111
        echo "ERROR: ${archisodevice} found, but the filesystem type is unknown."
112
113
114
115
116
117
118
        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
119
120
    fi

Aaron Griffin's avatar
Aaron Griffin committed
121
    msg ":: Mounting root (aufs) filesystem"
122
    /bin/mount -t aufs -o dirs=/tmpfs=rw none "${newroot}"
123
124
125
126
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
        exit 1
    fi
Aaron Griffin's avatar
Aaron Griffin committed
127

Aaron Griffin's avatar
Aaron Griffin committed
128
129
130
131
132
133
134
    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

135
        [ ! -r "/bootmnt/${archisobasedir}/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
136
137

        if [ "${type}" = "bind" ]; then
138
            _mnt_bind "/bootmnt/${archisobasedir}/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
139
        elif [ "${type}" = "squashfs" ]; then
140
            _mnt_squashfs "/bootmnt/${archisobasedir}/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
141
        fi
142
    done < "${isomounts}"
143

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

147
148
149
150
151
152
    if [ "${copytoram}" != "y" ]; then
        if [ "${FSTYPE}" = "iso9660" ] || [ "${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
153
        fi
Aaron Griffin's avatar
Aaron Griffin committed
154
155
    fi
}
Dan McGee's avatar
Dan McGee committed
156
157

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