archiso 4.59 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
    img_fullname="${img##*/}";
    img_name="${img_fullname%.*}"
25
    tmp_mnt="/ro_branch/${img_name}"
Aaron Griffin's avatar
Aaron Griffin committed
26

27
    if [ "${copytoram}" = "y" ]; then
28
        msg -n ":: Copying squashfs image to RAM..."
29
        /bin/cp "${img}" "/copytoram/${img_fullname}"
30
31
32
33
        if [ $? -ne 0 ]; then
            echo "ERROR: while copy ${img} to /copytoram/${img_fullname}"
            launch_interactive_shell
        fi
34
        img="/copytoram/${img_fullname}"
35
        msg "done."
36
37
    fi

38
39
    mkdir -p "${tmp_mnt}"
    /bin/mount -r -t squashfs "${img}" "${tmp_mnt}"
40
41
42
43
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting ${img} to ${tmp_mnt}"
        launch_interactive_shell
    fi
44

45
    if [ "/${mnt#/*/}" = "/" ]; then
46
        _mnt_aufs "${tmp_mnt}" "${mnt}"
47
    else
48
        _mnt_bind "${tmp_mnt}" "${mnt}"
49
    fi
Simo Leone's avatar
Simo Leone committed
50
51
}

52
run_hook() {
53
54
55
56
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

57
58
    if [ "x${rw_branch_size}" = "x" ]; then
        rw_branch_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
59
    fi
60

61
62
    if [ "x${copytoram_size}" = "x" ]; then
        copytoram_size="75%"
63
64
    fi

65
66
67
68
    if [ "x${archisobasedir}" = "x" ]; then
        archisobasedir="arch"
    fi

69
70
71
    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
72
        isomounts="/bootmnt/${archisobasedir}/isomounts"
73
74
    fi

75
    if [ "x${archisodevice}" = "x" ]; then
76
        archisodevice="/dev/disk/by-label/${archisolabel}"
77
78
    fi

79
80
81
82
83
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
84
    newroot="${1}"
85

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

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

119
    if [ "${copytoram}" = "y" ]; then
120
121
        msg -n ":: Mounting /copytoram (tmpfs) filesystem, size=${copytoram_size}..."
        mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /copytoram
122
123
124
        msg "done."
    fi

125
126
    msg -n ":: Mounting rw_branch (tmpfs) filesystem, size=${rw_branch_size}..."
    mount -t tmpfs -o "size=${rw_branch_size}",mode=0755 rw_branch /rw_branch
127
128
    msg "done."

Aaron Griffin's avatar
Aaron Griffin committed
129
    msg ":: Mounting root (aufs) filesystem"
130
    /bin/mount -t aufs -o dirs=/rw_branch=rw union "${newroot}"
131
132
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
133
        launch_interactive_shell
134
    fi
Aaron Griffin's avatar
Aaron Griffin committed
135

Aaron Griffin's avatar
Aaron Griffin committed
136
137
138
139
140
141
142
    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

143
        [ ! -r "/bootmnt/${archisobasedir}/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
144
145

        if [ "${type}" = "bind" ]; then
146
            _mnt_bind "/bootmnt/${archisobasedir}/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
147
        elif [ "${type}" = "squashfs" ]; then
148
            _mnt_squashfs "/bootmnt/${archisobasedir}/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
149
        fi
150
    done < "${isomounts}"
151

152
153
154
155
    if [ "${copytoram}" = "y" ]; then
        /bin/umount /bootmnt
    else
        _mnt_bind /bootmnt "${newroot}/bootmnt"
Aaron Griffin's avatar
Aaron Griffin committed
156
157
    fi
}
Dan McGee's avatar
Dan McGee committed
158
159

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