Project

General

Profile

« Previous | Next » 

Revision 336e899a

Added by Jim Pingle almost 12 years ago

Fix ufslabels.sh logic to avoid trying to convert slices which are already using appropriate labels. Fixes #3207

View differences:

usr/local/sbin/ufslabels.sh
53 53
}
54 54

  
55 55
FSTAB=/etc/fstab
56
NEED_CHANGES=false
56 57
cp ${FSTAB} ${FSTAB}.tmp
57 58

  
58
ALL_FILESYSTEMS=`/bin/cat /etc/fstab | /usr/bin/grep ufs | /usr/bin/awk '{print $2;}'`
59
ALL_FILESYSTEMS=`/bin/cat /etc/fstab | /usr/bin/awk '/ufs/ && !(/dev\/mirror\// || /dev\/ufsid\// || /dev\/label\// || /dev\/geom\//) {print $2;}'`
59 60

  
60 61
for FS in ${ALL_FILESYSTEMS}
61 62
do
......
67 68
			echo "Invalid UFS ID for FS ${FS} ($UFSID), skipping"
68 69
		else
69 70
			/usr/bin/sed -i'' -e "s/${DEV}/ufsid\/${UFSID}/g" ${FSTAB}.tmp
71
			NEED_CHANGES=true
70 72
		fi
71 73
	else
72 74
		echo "Unable to find device for ${FS}"
......
75 77
	echo "FS: ${FS} on device ${DEV} with ufsid ${UFSID}"
76 78
done
77 79

  
78
find_fs_device swap
79
SWAPDEV=${DEV}
80
echo "FS: Swap on device ${SWAPDEV}"
80
ALL_SWAPFS=`/bin/cat /etc/fstab | /usr/bin/awk '/swap/ && !(/dev\/mirror\// || /dev\/ufsid\// || /dev\/label\// || /dev\/geom\//) {print $1;}'`
81
SWAPNUM=0
82
for SFS in ${ALL_SWAPFS}
83
do
84
	DEV=${SFS##/dev/}
85
	if [ "${DEV}" != "" ]; then
86
		SWAPDEV=${DEV}
87
		echo "FS: Swap slice ${SWAPNUM} on device ${SWAPDEV}"
88
		if [ "${SWAPDEV}" != "" ]; then
89
			/usr/bin/sed -i'' -e "s/${SWAPDEV}/label\/swap${SWAPNUM}/g" ${FSTAB}.tmp
90
			NEED_CHANGES=true
91
		fi
92
		SWAPNUM=`expr ${SWAPNUM} + 1`
93
	fi
94
done
81 95

  
82
if [ "${SWAPDEV}" != "" ]; then
83
	/usr/bin/sed -i'' -e "s/${SWAPDEV}/label\/swap/g" ${FSTAB}.tmp
96
if [ "${NEED_CHANGES}" = "false" ]; then
97
	echo Nothing to do, all filesystems and swap already use some form of device-independent labels
98
	exit
84 99
fi
85 100

  
86 101
echo "===================="
......
101 116
if [ "${COMMIT}" = "y" ] || [ "${COMMIT}" = "Y" ]; then
102 117
	echo "Disabling swap to apply label"
103 118
	/sbin/swapoff /dev/${SWAPDEV}
119

  
104 120
	echo "Applying label to swap parition"
105
	/sbin/glabel label swap /dev/${SWAPDEV}
121
	SWAPNUM=0
122
	for SFS in ${ALL_SWAPFS}
123
	do
124
		find_fs_device ${SFS}
125
		if [ "${DEV}" != "" ]; then
126
			SWAPDEV=${DEV}
127
			if [ "${SWAPDEV}" != "" ]; then
128
				/sbin/glabel label swap${SWAPNUM} /dev/${SWAPDEV}
129
			fi
130
			SWAPNUM=`expr ${SWAPNUM} + 1`
131
		fi
132
	done
106 133

  
107 134
	echo "Activating new fstab"
108 135
	/bin/mv -f ${FSTAB} ${FSTAB}.old

Also available in: Unified diff