archiso 4.24 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 ":: Waiting for boot device..."
79
    while ! poll_device ${archisodevice} 30; do
80
81
82
83
        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
84
    done
85

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

111
112
113
114
115
116
117
118
119
120
    if [ "${copytoram}" = "y" ]; then
        msg -n ":: Mounting tmpfs (for squashfs), size=${tmpfs_sqfs_size}..."
        mount -t tmpfs -o "size=${tmpfs_sqfs_size}",mode=0755 tmpfs /tmpfs.sqfs
        msg "done."
    fi

    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
    mount -t tmpfs -o "size=${tmpfs_size}",mode=0755 tmpfs /tmpfs
    msg "done."

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

144
145
146
147
    if [ "${copytoram}" = "y" ]; then
        /bin/umount /bootmnt
    else
        _mnt_bind /bootmnt "${newroot}/bootmnt"
Aaron Griffin's avatar
Aaron Griffin committed
148
149
    fi
}
Dan McGee's avatar
Dan McGee committed
150
151

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