archiso 3.79 KB
Newer Older
Simo Leone's avatar
Simo Leone committed
1
2
3
# args: source, mountpoint
_mnt_bind()
{
4
5
6
7
8
    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
9
10
}

Aaron Griffin's avatar
Aaron Griffin committed
11
# args: /path/to/image_file
Simo Leone's avatar
Simo Leone committed
12
13
_mnt_squashfs()
{
Aaron Griffin's avatar
Aaron Griffin committed
14
    img="${1}"
15
    mnt="${2}"
16
17
18
    img_fullname="${img##*/}";
    img_name="${img_fullname%.*}"
    tmp_mnt="/tmpfs/mnt/${img_name}"
Aaron Griffin's avatar
Aaron Griffin committed
19

20
    # FIX: This options does not work (see FS#17182)
Aaron Griffin's avatar
Aaron Griffin committed
21
22
23
24
25
26
    if [ "${copytoram}" = "y" ]; then
        msg ":: Copying squashfs image to RAM"
        /bin/cat ${img} > "/tmpfs/${base_img}"
        img="/tmpfs/${base_img}"
    fi

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

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

43
44
    if [ "x${tmpfs_size}" = "x" ]; then
        tmpfs_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
45
    fi
46
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
62
63
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
    newroot="$1"

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

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

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

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

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

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

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

127
128
129
130
131
    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
132
133
134
    fi

}
Dan McGee's avatar
Dan McGee committed
135
136

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