archiso 3.84 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()
{
12
    /sbin/modprobe -q loop > /dev/null 2>&1
13

Aaron Griffin's avatar
Aaron Griffin committed
14
15
    img="${1}"
    base_img="${img##*/}";
16
    mnt="${2}"
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

Aaron Griffin's avatar
Aaron Griffin committed
25
    msg "::: Adding new aufs branch: ${base_img%.*}"
Simo Leone's avatar
Simo Leone committed
26
    mkdir -p "/tmpfs/mnt/loop${LOOP_NUM}"
Simo Leone's avatar
Simo Leone committed
27
    # sometimes it takes udev a while to create device nodes
Aaron Griffin's avatar
Aaron Griffin committed
28
    while [ ! -e "/dev/loop${LOOP_NUM}" ]; do
Simo Leone's avatar
Simo Leone committed
29
30
        sleep 1
    done
31
    if ! /sbin/losetup "/dev/loop${LOOP_NUM}" ${img}; then
Simo Leone's avatar
Simo Leone committed
32
33
34
35
        echo "ERROR: Cannot mount loop device /dev/loop${LOOP_NUM}"
        break
    fi
    /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}"
36
    if [ "${mnt}" = "/" ]; then
37
        /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "$newroot"
38
39
40
    else
        _mnt_bind "/tmpfs/mnt/loop${LOOP_NUM}" "${mnt}"
    fi
Simo Leone's avatar
Simo Leone committed
41
42
43
    export LOOP_NUM=$(( $LOOP_NUM + 1 ))
}

Aaron Griffin's avatar
Aaron Griffin committed
44
45
run_hook ()
{
46
47
48
49
    if [ "x${arch}" = "x" ]; then
        arch="$(uname -m)"
    fi

50
51
    if [ "x${tmpfs_size}" = "x" ]; then
        tmpfs_size="75%"
Aaron Griffin's avatar
Aaron Griffin committed
52
    fi
53
54
55
56
57
58
59

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

60
61
62
63
    if [ "x${archisodevice}" = "x" ]; then
        archisodevice="/dev/archiso"
    fi

64
65
66
67
68
69
70
    # set mount handler for archiso
    mount_handler="archiso_mount_handler"
}

archiso_mount_handler() {
    newroot="$1"

71
72
    msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
    mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs
Aaron Griffin's avatar
Aaron Griffin committed
73
74
    msg "done."

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

83
    FSTYPE=$(blkid -o value -s TYPE ${archisodevice} 2> /dev/null)
84
    if [ -n "${FSTYPE}" ]; then
85
        if mount -r -t "${FSTYPE}" ${archisodevice} /bootmnt > /dev/null 2>&1; then
86
            if [ -e "${isomounts}" ]; then
87
88
                echo "SUCCESS: Mounted archiso volume successfully."
            else
89
                echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist."
90
91
92
                exit 1
            fi
        else
93
            echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})"
94
            exit 1
95
        fi
96
    else
97
        echo "ERROR: ${archisodevice} found, but the filesystem type is unknown."
Aaron Griffin's avatar
Aaron Griffin committed
98
99
    fi

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

107
    export LOOP_NUM="0"
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
118
119

        if [ "${type}" = "bind" ]; then
            _mnt_bind "/bootmnt/${img}" ${mountpoint}
        elif [ "${type}" = "squashfs" ]; then
120
            _mnt_squashfs "/bootmnt/${img}" "${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 /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: