archiso 4.24 KB
Newer Older
Simo Leone's avatar
Simo Leone committed
1
2
3
4
5
# args: source, mountpoint
_mnt_bind()
{
    msg "::: Binding ${1} to ${2}"
    mkdir -p /real_root${2}
6
    /bin/mount -o bind ${1} /real_root${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
Aaron Griffin's avatar
Aaron Griffin committed
13
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 "/real_root"
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
    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
73
74
      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"
      PS1="ramfs$ " /bin/sh -i
    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
81
                echo "SUCCESS: Mounted archiso volume successfully."
            else
82
                echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist."
83
84
85
                exit 1
            fi
        else
86
            echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})"
87
            exit 1
88
        fi
89
    else
90
        echo "ERROR: ${archisodevice} found, but the filesystem type is unknown."
Aaron Griffin's avatar
Aaron Griffin committed
91
92
    fi

Aaron Griffin's avatar
Aaron Griffin committed
93
94
    msg ":: Mounting root (aufs) filesystem"
    /bin/mount -t aufs -o dirs=/tmpfs=rw none /real_root
95
96
97
98
    if [ $? -ne 0 ]; then
        echo "ERROR: while mounting root (aufs) filesystem."
        exit 1
    fi
Aaron Griffin's avatar
Aaron Griffin committed
99

100
    export LOOP_NUM="0"
Aaron Griffin's avatar
Aaron Griffin committed
101
102
103
104
105
106
107
    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

108
        [ ! -r "/bootmnt/${img}" ] && continue
Aaron Griffin's avatar
Aaron Griffin committed
109
110
111
112

        if [ "${type}" = "bind" ]; then
            _mnt_bind "/bootmnt/${img}" ${mountpoint}
        elif [ "${type}" = "squashfs" ]; then
113
            _mnt_squashfs "/bootmnt/${img}" "${mountpoint}"
Aaron Griffin's avatar
Aaron Griffin committed
114
        fi
115
    done < "${isomounts}"
116

Aaron Griffin's avatar
Aaron Griffin committed
117
    # Bind our bootmnt dir into the live system
118
    _mnt_bind /bootmnt /bootmnt
Simo Leone's avatar
Simo Leone committed
119

120
121
122
123
124
    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
125
126
    fi

127
128
129
130
131
    if [ "${break}" = "y" ]; then
        echo ":: Break requested, type 'exit' to resume operation"
        PS1="ramfs$ " /bin/sh -i
    fi

132
133
134
135
136
137
    #Special handling if udev is running
    udevpid=$(/bin/pidof udevd)
    if [ -n "${udevpid}" ]; then
        /bin/kill -9 ${udevpid} > /dev/null 2>&1
        /bin/sleep 0.01
    fi
138
    msg ":: Passing control to Arch Linux Initscripts...Please Wait"
Aaron Griffin's avatar
   
Aaron Griffin committed
139
140
    /bin/umount /sys
    /bin/umount /proc
141
    exec /sbin/switch_root -c /dev/console /real_root /sbin/init ${CMDLINE}
Aaron Griffin's avatar
Aaron Griffin committed
142
}
Dan McGee's avatar
Dan McGee committed
143
144

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