archiso 4.3 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
61
62
    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
        isomounts="/bootmnt/isomounts"
    fi

63
64
65
66
    if [ "x${archisodevice}" = "x" ]; then
        archisodevice="/dev/archiso"
    fi

67
68
69
70
71
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
72
    newroot="${1}"
73

74
75
    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
    mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs
Aaron Griffin's avatar
Aaron Griffin committed
76
77
    msg "done."

78
79
80
81
82
83
    if [ "${copytoram}" = "y" ]; then
        msg -n ":: Mounting tmpfs (for squashfs), size=${tmpfs_sqfs_size}..."
        mount -t tmpfs -o "size=${tmpfs_sqfs_size}" tmpfs /tmpfs.sqfs
        msg "done."
    fi

84
    msg ":: Waiting for boot device..."
85
    while ! poll_device ${archisodevice} 30; do
86
87
88
89
        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
90
    done
91

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

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

Aaron Griffin's avatar
Aaron Griffin committed
124
125
126
127
128
129
130
    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

131
        [ ! -r "/bootmnt/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
132
133

        if [ "${type}" = "bind" ]; then
134
            _mnt_bind "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
135
        elif [ "${type}" = "squashfs" ]; then
136
            _mnt_squashfs "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
137
        fi
138
    done < "${isomounts}"
139

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

143
144
145
146
147
148
    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
149
        fi
Aaron Griffin's avatar
Aaron Griffin committed
150
151
    fi
}
Dan McGee's avatar
Dan McGee committed
152
153

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