archiso 3.73 KB
Newer Older
Simo Leone's avatar
Simo Leone committed
1
2
3
4
# args: source, mountpoint
_mnt_bind()
{
    msg "::: Binding ${1} to ${2}"
5
6
    mkdir -p $newroot${2}
    /bin/mount -o bind ${1} $newroot${2}
Simo Leone's avatar
Simo Leone committed
7
8
}

Aaron Griffin's avatar
Aaron Griffin committed
9
# args: /path/to/image_file
Simo Leone's avatar
Simo Leone committed
10
11
_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
    # FIX: This options does not work (see FS#17182)
Aaron Griffin's avatar
Aaron Griffin committed
19
20
21
22
23
24
    if [ "${copytoram}" = "y" ]; then
        msg ":: Copying squashfs image to RAM"
        /bin/cat ${img} > "/tmpfs/${base_img}"
        img="/tmpfs/${base_img}"
    fi

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

Aaron Griffin's avatar
Aaron Griffin committed
35
36
run_hook ()
{
37
38
39
40
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

41
42
    if [ "x${tmpfs_size}" = "x" ]; then
        tmpfs_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
43
    fi
44
45
46
47
48
49
50

    if [ "x${isomounts}" != "x" ]; then
        isomounts="/bootmnt/${isomounts}"
    else
        isomounts="/bootmnt/isomounts"
    fi

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

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

archiso_mount_handler() {
    newroot="$1"

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

66
    msg ":: Waiting for boot device..."
67
    while ! poll_device ${archisodevice} 30; do
68
69
70
      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"
71
      launch_interactive_shell
72
    done
73

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

Aaron Griffin's avatar
Aaron Griffin committed
99
    msg ":: Mounting root (aufs) filesystem"
100
    /bin/mount -t aufs -o dirs=/tmpfs=rw none $newroot
101
102
103
104
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
        exit 1
    fi
Aaron Griffin's avatar
Aaron Griffin committed
105

Aaron Griffin's avatar
Aaron Griffin committed
106
107
108
109
110
111
112
    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

113
        [ ! -r "/bootmnt/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
114
115
116
117

        if [ "${type}" = "bind" ]; then
            _mnt_bind "/bootmnt/${img}" ${mountpoint}
        elif [ "${type}" = "squashfs" ]; then
118
            _mnt_squashfs "/bootmnt/${img}" "${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
119
        fi
120
    done < "${isomounts}"
121

Aaron Griffin's avatar
Aaron Griffin committed
122
    # Bind our bootmnt dir into the live system
123
    _mnt_bind /bootmnt /bootmnt
Simo Leone's avatar
Simo Leone committed
124

125
126
127
128
129
    if [ "${FSTYPE}" = "iso9660" -o "${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
Aaron Griffin's avatar
Aaron Griffin committed
130
131
132
    fi

}
Dan McGee's avatar
Dan McGee committed
133
134

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