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

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

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
32
	`disklabel ${disk}s${part} 2>&1 | grep -s -E '^[ ]+a:' >/dev/null` || {
33
34
35
36
37
38
39
40
41
42
43
44
45
		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
46
	sed -E -i .orig -e "s;^/dev/[a-zA-Z]+[0-9]+s[0-9]+;/dev/${disk}s${part};" /mnt/etc/fstab || {
47
48
49
50
		echo "Failed to update /etc/fstab"
		umount $rootdev
		return 1
	}
Mike Hibler's avatar
Mike Hibler committed
51
	sed -E -i .orig -e "s;^/dev/[a-zA-Z]+[0-9]+s[0-9]+;/dev/${disk}s${part};" /mnt/etc/dumpdates || {
52
53
54
55
56
57
58
59
60
		echo "Failed to update /etc/dumpdates"
		umount $rootdev
		return 1
	}
	umount $rootdev
	return 0
}

dolinux() {
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
	# figure out the linux device name
	dunit=`echo $disk | sed -e 's/..\([0-7]\)/\1/'`
	case $disk in
	# IDE
	ad[0-3])
		dtype="hd"
		d=`echo $dunit | sed -e 'y/0123/048c/'`
		lrootdev="3${d}${part}"
		;;
	# SATA
	ad[4-7])
		dtype="sd"
		dunit=`expr $dunit - 4`
		lrootdev="8${dunit}${part}"
		;;
	# SCSI
	da[0-7])
		dtype="sd"
		lrootdev="8${dunit}${part}"
		;;
	*)
		echo "slicefix: linux: unknown disk $disk"
		return 1
		;;
	esac
	dunit=`echo $dunit | sed -e 'y/01234567/abcdefgh/'`;
	ldisk=$dtype$dunit

	# attempt to mount filesystem   
	rootdev=/dev/${disk}s${part}
	mount -t ext2fs $rootdev /mnt || {
		echo "EXT2FS mount of $rootdev failed"
		return 1
	}

	# change the swap devices in fstab
	sed -i .orig -e "s;^/dev/[hs]d.\([0-7]\);/dev/${ldisk}\1;" /mnt/etc/fstab || {
		echo "Failed to update /etc/fstab"
		umount $rootdev
		return 1
	}

	# update lilo.conf and set indicator to tell Emulab to rerun lilo
	sed -i .orig -e "s;\([br]oot=/dev\)/[hs]d.\([0-7]\);\1/${ldisk}\2;" /mnt/etc/lilo.conf || {
		echo "Failed to update /etc/lilo.conf"
		umount $rootdev
		return 1
	}
109
110
111
112
113

	# XXX note the hardwired path, cannot use BOOTDIR as it is different
        # in frisbee MFS.  This also assumes Linux partition is one big
	# filesystem.
	cp /dev/null /mnt/var/emulab/boot/runlilo
114
115
116
117
118
119
120
121
122

	umount $rootdev

	# setup one time lilo command line, must be done after unmount
	$BINDIR/groklilo -c "linux root=$lrootdev" $part /dev/$disk || {
		echo "Failed to set LILO command line"
		return 1
	}

Mike Hibler's avatar
Mike Hibler committed
123
	return 0
124
125
}

Mike Hibler's avatar
Mike Hibler committed
126
127
fixone() {
    echo "*** ${disk}s${part}:"
128
    ptype=`fdisk -${part} ${disk} | grep sysid | sed 's/^sysid \([0-9][0-9]*\).*/\1/'`
Mike Hibler's avatar
Mike Hibler committed
129
130
131
132
    ptype=${ptype:-0}

    case $ptype in
    165)
133
	dofreebsd
Mike Hibler's avatar
Mike Hibler committed
134
	return $?
135
	;;
Mike Hibler's avatar
Mike Hibler committed
136
137
138
    131)
	dolinux
	return $?
139
	;;
Mike Hibler's avatar
Mike Hibler committed
140
141
142
143
    0)
	echo "unused"
	;;
    *)
144
145
	echo "ignoring partition type $ptype"
	;;
Mike Hibler's avatar
Mike Hibler committed
146
147
148
149
150
151
152
153
154
155
156
    esac
    return 0
}

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

157
158
159
160
161
    # when fixing all partitions, do not fail on an error
    if [ $? -ne 0 ]; then
    	echo "WARNING: failed to fix one or more partitions, BEWARE!"
    fi

Mike Hibler's avatar
Mike Hibler committed
162
163
164
165
166
167
168
169
170
171
172
173
    # 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
    ;;
174
175
esac

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