summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-05-24 21:58:07 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-05-24 21:58:07 +0000
commit8e951b71677d1a3ab306927ca4b9fbb780374746 (patch)
tree4f7372b936883c4d172d401817567da26b41d945 /etc
parent255a6606a7622517c1dbd6a102f4481f8d641dca (diff)
Before dd'ing raw partitions around, do stricter sanity checking:
Do not attempt to copy a larger partition onto a smaller one. Backup of non-ffs root partitions was never supported, so don't even try. (Both of the above suggested by guenther@). Also add error messages in case ROOTBACKUP is switched on but severely misconfigured - those were silently ignored in the past: /altroot not defined or wrong type or on the same device as root. otto@ agrees that checking the sizes makes sense
Diffstat (limited to 'etc')
-rw-r--r--etc/daily48
1 files changed, 36 insertions, 12 deletions
diff --git a/etc/daily b/etc/daily
index 0afb4034bf9..438726a079b 100644
--- a/etc/daily
+++ b/etc/daily
@@ -1,5 +1,5 @@
#
-# $OpenBSD: daily,v 1.63 2009/05/21 01:27:52 schwarze Exp $
+# $OpenBSD: daily,v 1.64 2009/05/24 21:58:06 schwarze Exp $
# From: @(#)daily 8.2 (Berkeley) 1/25/94
#
umask 022
@@ -90,20 +90,44 @@ fi
# if filesystem named /altroot is type ffs, on /dev/* and mounted "xx",
# use it as a backup root filesystem to be updated daily.
next_part "Backing up root filesystem:"
-[ "X$ROOTBACKUP" = X1 ] && {
- rootdev=`df -n / | awk '/^\/dev\// { print substr($1, 6) }'`
+while [ "X$ROOTBACKUP" = X1 ]; do
rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ffs" && \
$4 ~ /xx/ \
{ print substr($1, 6) }' < /etc/fstab`
- [ X$rootdev != X -a X$rootbak != X -a X$rootdev != X$rootbak ] && \
- sysctl -n hw.disknames | grep -Fqw ${rootbak%[a-p]} && {
- next_part "Backing up root=/dev/r$rootdev to /dev/r$rootbak:"
- sync
- dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
- conv=noerror
- fsck -y /dev/r$rootbak
- }
-}
+ if [ -z "$rootbak" ]; then
+ echo "No xx ffs /altroot device found in the fstab(5)."
+ break
+ fi
+ bakdisk=${rootbak%[a-p]}
+ sysctl -n hw.disknames | grep -Fqw $bakdisk || break
+ bakpart=${rootbak#$bakdisk}
+ baksize=`disklabel $bakdisk 2>/dev/null | \
+ awk -v "part=$bakpart:" '$1 == part { print $2 }'`
+ rootdev=`mount | awk '$3 == "/" && $1 ~ /^\/dev\// && $5 == "ffs" \
+ { print substr($1, 6) }'`
+ if [ -z "$rootdev" ]; then
+ echo "The root filesystem is not local or not ffs."
+ break
+ fi
+ if [ X$rootdev = X$rootbak ]; then
+ echo "The device $rootdev holds both root and /altroot."
+ break
+ fi
+ rootdisk=${rootdev%[a-p]}
+ rootpart=${rootdev#$rootdisk}
+ rootsize=`disklabel $rootdisk 2>/dev/null | \
+ awk -v "part=$rootpart:" '$1 == part { print $2 }'`
+ if [ $rootsize -gt $baksize ]; then
+ echo "Root ($rootsize) is larger than /altroot ($baksize)."
+ break
+ fi
+ next_part "Backing up root=/dev/r$rootdev to /dev/r$rootbak:"
+ sync
+ dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
+ conv=noerror
+ fsck -y /dev/r$rootbak
+ break
+done
next_part "Checking subsystem status:"
if [ "X$VERBOSESTATUS" != X0 ]; then