~ubuntu-branches/ubuntu/lucid/lupin/lucid-proposed

« back to all changes in this revision

Viewing changes to grub-install/grub-mkimage

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-06-06 16:10:13 UTC
  • Revision ID: james.westby@ubuntu.com-20110606161013-zx07l6h6ullvbugn
Tags: 0.29.1
Detect the case where Wubi's disk images were installed to a different
partition from Windows, which means that wubildr will not be on /host:
update all wubildr images we can find (LP: #610898).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# You should have received a copy of the GNU Lesser General Public License
19
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
 
 
21
newns () {
 
22
    [ "$LUPIN_NEWNS" ] || exec /usr/lib/lupin-support/newns "$0" "$@"
 
23
}
 
24
 
 
25
# Look for wubildr on all partitions of BIOS-accessible disk devices.
 
26
# We can safely ignore the hibernation case here, because the Windows boot
 
27
# loader boots straight into Windows if Windows was hibernated.
 
28
find_wubildr () {
 
29
    local partitions=
 
30
    for disk in $(grub-mkdevicemap -m - | cut -f2); do
 
31
        disk="$(readlink -f "$disk")" || continue
 
32
        sysdisk="/sys$(udevadm info -q path -n "$disk" 2>/dev/null)" || continue
 
33
        for syspartition in "$sysdisk"/*[0-9]; do
 
34
            [ -d "$syspartition" ] || continue
 
35
            partition="/dev/$(udevadm info -q name -p "$syspartition" 2>/dev/null)" || continue
 
36
            fs="$(grub-probe -t fs -d "$partition" 2>/dev/null)" || continue
 
37
            [ "$fs" = fat ] || [ "$fs" = ntfs ] || continue
 
38
            if [ "$(grub-fstest "$partition" ls /wubildr 2>/dev/null)" ]; then
 
39
                partitions="${partitions:+$partitions }$partition"
 
40
            fi
 
41
        done
 
42
    done
 
43
    echo "$partitions"
 
44
}
 
45
 
 
46
parse_proc_mounts () {
 
47
    while read -r line; do
 
48
        set -- $line
 
49
        printf '%s %s %s\n' "$(readlink -f "$1")" "$2" "$3"
 
50
    done
 
51
}
 
52
 
 
53
unescape_mount () {
 
54
    printf %s "$1" | \
 
55
        sed 's/\\011/   /g; s/\\012/\n/g; s/\\040/ /g; s/\\134/\\/g'
 
56
}
 
57
 
 
58
newns "$@"
 
59
 
21
60
prefix=
22
61
test_only=false
23
62
 
61
100
 
62
101
target="${host_mountpoint}/wubildr"
63
102
 
64
 
if [ ! -f "$target" ]; then
65
 
    exit 1
66
 
fi
67
 
 
68
103
if $test_only; then
69
 
    exit 0
 
104
    if [ -f "$target" ]; then
 
105
        # Found on this partition
 
106
        exit 0
 
107
    elif [ "$(find_wubildr)" ]; then
 
108
        # Found on some other partition
 
109
        exit 0
 
110
    else
 
111
        # Not found
 
112
        exit 1
 
113
    fi
 
114
fi
 
115
 
 
116
wubildr_partitions="$(find_wubildr)"
 
117
 
 
118
if [ ! -f "$target" ] && [ -z "$wubildr_partitions" ]; then
 
119
    exit 1
70
120
fi
71
121
 
72
122
# TODO You might want to have this as a proper file somewhere in /usr/share
73
 
lupin_embedded_cfg=$(tempfile)
74
 
cat << EOF >> $lupin_embedded_cfg
 
123
tmp="$(mktemp -dt)"
 
124
cat << EOF >> "$tmp/wubildr.cfg"
75
125
set show_panic_message=true
76
126
if search -s -f -n $loop_file; then
77
127
    if loopback loop0 $loop_file; then
103
153
    search linux boot minicmd cat cpuid chain halt help ls reboot \
104
154
    echo test configfile sh sleep"
105
155
 
106
 
grub-mkimage ${prefix:+--prefix="$prefix"} -c $lupin_embedded_cfg $modules | cat /usr/lib/grub/i386-pc/lnxboot.img - > "$target.new"
107
 
mv "$target.new" "$target"
108
 
rm $lupin_embedded_cfg || true
 
156
grub-mkimage ${prefix:+--prefix="$prefix"} -c "$tmp/wubildr.cfg" $modules | cat /usr/lib/grub/i386-pc/lnxboot.img - > "$tmp/wubildr"
 
157
 
 
158
if [ -f "$target" ]; then
 
159
    cp -af "$tmp/wubildr" "$target.new"
 
160
    mv -f "$target.new" "$target"
 
161
fi
 
162
 
 
163
grep ^/dev/ /proc/mounts | parse_proc_mounts >"$tmp/mounted-map"
 
164
mkdir -p "$tmp/mnt"
 
165
for partition in $wubildr_partitions; do
 
166
    if grep -q "^$partition " "$tmp/mounted-map"; then
 
167
        mpoint="$(grep "^$partition " "$tmp/mounted-map" | head -n1 | cut -d' ' -f2)"
 
168
        mpoint="$(unescape_mount "$mpoint")"
 
169
        if [ "$mpoint" = /host ]; then
 
170
            continue
 
171
        fi
 
172
    else
 
173
        mount "$partition" "$tmp/mnt" 2>/dev/null || continue
 
174
        mpoint="$tmp/mnt"
 
175
    fi
 
176
    if [ -f "$mpoint/wubildr" ]; then
 
177
        cp -af "$tmp/wubildr" "$mpoint/wubildr.new"
 
178
        mv -f "$mpoint/wubildr.new" "$mpoint/wubildr"
 
179
    fi
 
180
    if ! grep -q "^$partition " "$tmp/mounted-map"; then
 
181
        umount "$tmp/mnt" || true
 
182
    fi
 
183
done
 
184
 
 
185
rm -rf --one-file-system "$tmp" || true