aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2014-07-17 11:44:36 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2014-07-17 11:44:36 +0200
commit5856a288a732b2a5de650983854d684e6dd81c55 (patch)
tree2fbb002241a211c8a594add37e3c56be67c38763
parenta5ad7c4c0a1e649033699a3ba832c3810fb576dc (diff)
downloadalpine-conf-5856a288a732b2a5de650983854d684e6dd81c55.tar.bz2
alpine-conf-5856a288a732b2a5de650983854d684e6dd81c55.tar.xz
setup-bootable: do not run syslinux on mounted devices
Running syslinux on a device that is mounted causes undefined behaviour. We have been 'lucky' up til now but it is known that this can corrupt syslinux.cfg. This should fix #3137
-rw-r--r--setup-bootable.in33
1 files changed, 26 insertions, 7 deletions
diff --git a/setup-bootable.in b/setup-bootable.in
index 374a40c..a78f391 100644
--- a/setup-bootable.in
+++ b/setup-bootable.in
@@ -3,12 +3,9 @@
prog=${0##*/}
version=@VERSION@
-cleanup() {
+cleanup_mounts() {
local i=
cd /
- if [ -n "$uninstalls" ]; then
- apk del --quiet syslinux
- fi
sync
sleep 1
for i in $read_only_mounts; do
@@ -19,9 +16,16 @@ cleanup() {
fi
}
+cleanup_installs() {
+ if [ -n "$uninstalls" ]; then
+ apk del --quiet syslinux
+ fi
+}
+
die() {
echo "$@" >&2
- cleanup
+ cleanup_mounts
+ cleanup_installs
exit 1
}
@@ -142,6 +146,10 @@ if [ -d "$dest" ]; then
if ! awk '{print $2}' /proc/mounts | grep -q "^$dest\$"; then
mount "$dest" || die "Failed to mount $dest"
umounts="$umounts $dest"
+ elif [ -n "$syslinux" ]; then
+ die "Cannot run syslinux on mounted device"
+ else
+ nosyslinux=1
fi
destdir="$dest"
dest=$(find_dev "$destdir")
@@ -285,7 +293,15 @@ fi
# If we only copy then we are done.
if [ -n "$upgrade" ] && [ -z "$syslinux" ]; then
- cleanup
+ cleanup_installs
+ cleanup_mounts
+ exit 0
+fi
+
+# prevent running syslinux on mounted device
+if [ -n "$nosyslinux" ]; then
+ echo "Warning: Can not run syslinux on a mounted device"
+ echo " You might need run syslinux manually and install MBR manually"
exit 0
fi
@@ -296,6 +312,9 @@ if ! [ -x "$(which syslinux)" ]; then
uninstalls="syslinux"
fi
+# we need to unmount the device before we can run syslinux
+cleanup_mounts
+fsync $dest
syslinux $dest
if [ -b $parent_dev ]; then
@@ -303,5 +322,5 @@ if [ -b $parent_dev ]; then
else
echo "Warning: Could not find the parent device for $dest"
fi
+cleanup_installs
-cleanup