diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-17 11:44:36 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-17 11:44:36 +0200 |
commit | 5856a288a732b2a5de650983854d684e6dd81c55 (patch) | |
tree | 2fbb002241a211c8a594add37e3c56be67c38763 /setup-bootable.in | |
parent | a5ad7c4c0a1e649033699a3ba832c3810fb576dc (diff) | |
download | alpine-conf-5856a288a732b2a5de650983854d684e6dd81c55.zip |
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
Diffstat (limited to 'setup-bootable.in')
-rw-r--r-- | setup-bootable.in | 33 |
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 |