archiso 4.15 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
21
22
23
    if [ "${copytoram}" = "y" ]; then
        msg ":: Copying squashfs image to RAM"
        /bin/cp "${img}" "/tmpfs.sqfs/${img_fullname}"
        img="/tmpfs.sqfs/${img_fullname}"
    fi

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

34
run_hook () {
35
36
37
38
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

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

43
44
45
46
    if [ "x${tmpfs_sqfs_size}" = "x" ]; then
        tmpfs_sqfs_size="75%"
    fi

47
48
49
50
51
52
    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
        isomounts="/bootmnt/isomounts"
    fi

53
54
55
56
    if [ "x${archisodevice}" = "x" ]; then
        archisodevice="/dev/archiso"
    fi

57
58
59
60
61
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
62
    newroot="${1}"
63

64
65
    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
    mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs
Aaron Griffin's avatar
Aaron Griffin committed
66
67
    msg "done."

68
69
70
71
72
73
    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

74
    msg ":: Waiting for boot device..."
75
    while ! poll_device ${archisodevice} 30; do
76
77
78
79
        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
80
    done
81

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

Aaron Griffin's avatar
Aaron Griffin committed
107
    msg ":: Mounting root (aufs) filesystem"
108
    /bin/mount -t aufs -o dirs=/tmpfs=rw none "${newroot}"
109
110
111
112
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
        exit 1
    fi
Aaron Griffin's avatar
Aaron Griffin committed
113

Aaron Griffin's avatar
Aaron Griffin committed
114
115
116
117
118
119
120
    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

121
        [ ! -r "/bootmnt/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
122
123

        if [ "${type}" = "bind" ]; then
124
            _mnt_bind "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
125
        elif [ "${type}" = "squashfs" ]; then
126
            _mnt_squashfs "/bootmnt/${img}" "${newroot}${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
127
        fi
128
    done < "${isomounts}"
129

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

133
134
135
136
137
138
    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
139
        fi
Aaron Griffin's avatar
Aaron Griffin committed
140
141
    fi
}
Dan McGee's avatar
Dan McGee committed
142
143

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