slicefix 1.85 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#

Mike Hibler's avatar
Mike Hibler committed
8 9 10 11 12 13
if [ -r /etc/emulab/paths.sh ]; then
	. /etc/emulab/paths.sh
else
	BINDIR=/etc/testbed
fi

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
disk="ad0"

case $# in
1)
	part=$1
	;;
2)
	part=$1
	disk=$2
	;;
*)
	echo "Usage: $0 partition [disk]"
	exit 1
esac

dofreebsd() {
	# see if there is a root ('a') partition on this BSD slice
Mike Hibler's avatar
Mike Hibler committed
31
	`disklabel ${disk}s${part} 2>&1 | grep -s -E '^[ ]+a:' >/dev/null` || {
32 33 34 35 36 37 38 39 40 41 42 43 44
		return 1
	}

	rootdev=/dev/${disk}s${part}a
	echo "fixing FreeBSD root partition ${disk}s${part}a"
	fsck -p $rootdev || {
		echo "Fsck of $rootdev failed"
		return 1
	}
	mount $rootdev /mnt || {
		echo "Mount of $rootdev failed"
		return 1
	}
Mike Hibler's avatar
Mike Hibler committed
45
	sed -E -i .orig -e "s;^/dev/[a-zA-Z]+[0-9]+s[0-9]+;/dev/${disk}s${part};" /mnt/etc/fstab || {
46 47 48 49
		echo "Failed to update /etc/fstab"
		umount $rootdev
		return 1
	}
Mike Hibler's avatar
Mike Hibler committed
50
	sed -E -i .orig -e "s;^/dev/[a-zA-Z]+[0-9]+s[0-9]+;/dev/${disk}s${part};" /mnt/etc/dumpdates || {
51 52 53 54 55 56 57 58 59 60
		echo "Failed to update /etc/dumpdates"
		umount $rootdev
		return 1
	}
	umount $rootdev
	return 0
}

dolinux() {
	# need to update fstab, lilo.conf
Mike Hibler's avatar
Mike Hibler committed
61 62
	echo "do not do linux yet"
	return 0
63 64
}

Mike Hibler's avatar
Mike Hibler committed
65 66 67 68 69 70 71
fixone() {
    echo "*** ${disk}s${part}:"
    ptype=`fdisk -${part} ${disk} | grep sysid | sed 's/.*sysid \([0-9][0-9]*\),.*/\1/'`
    ptype=${ptype:-0}

    case $ptype in
    165)
72
	dofreebsd
Mike Hibler's avatar
Mike Hibler committed
73
	return $?
74
	;;
Mike Hibler's avatar
Mike Hibler committed
75 76 77
    131)
	dolinux
	return $?
78
	;;
Mike Hibler's avatar
Mike Hibler committed
79 80 81 82
    0)
	echo "unused"
	;;
    *)
83 84
	echo "ignoring partition type $ptype"
	;;
Mike Hibler's avatar
Mike Hibler committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    esac
    return 0
}

case $part in
0)
    part=1; fixone
    part=2; fixone
    part=3; fixone
    part=4; fixone

    # for the CD boot, we need to intialize the magic boot block
    if [ -e /cdrom.inf -a -x $BINDIR/tbbootconfig ]; then
	$BINDIR/tbbootconfig -f -c 1 -k 0 -m 1 /dev/${disk}
    fi
    ;;
1|2|3|4)
    fixone
    ;;
*)
    echo "bad partition: $part"
    false
    ;;
108 109
esac

Mike Hibler's avatar
Mike Hibler committed
110
exit $?