change vn device from old style raw device to block device.
[dragonfly.git] / release / scripts / doFS.sh
1 #!/bin/sh
2 #
3 # $FreeBSD: src/release/scripts/doFS.sh,v 1.24.2.12 2003/04/04 11:58:05 ru Exp $
4 # $DragonFly: src/release/scripts/Attic/doFS.sh,v 1.3 2003/08/25 20:17:25 rob Exp $
5 #
6
7 set -e
8
9 export BLOCKSIZE=512
10
11 if [ "$1" = "-s" ]; then
12         do_size="yes"; shift
13 else
14         do_size=""
15 fi
16
17 FSIMG=$1; shift
18 RD=$1 ; shift
19 MNT=$1 ; shift
20 FSSIZE=$1 ; shift
21 FSPROTO=$1 ; shift
22 FSINODE=$1 ; shift
23 FSLABEL=$1 ; shift
24
25 BOOT1="-b ${RD}/trees/bin/boot/boot1"
26 if [ -f "${RD}/trees/bin/boot/boot2" ]; then
27         BOOT2="-s ${RD}/trees/bin/boot/boot2"
28 else
29         BOOT2=""
30 fi
31
32 deadlock=20
33
34 dofs_vn () {
35     if [ "x$VNDEVICE" = "x" ] ; then
36         VNDEVICE=vn0
37     fi
38     u=`expr $VNDEVICE : 'vn\([0-9]*\)' || true`
39     VNDEVICE=vnn$u
40
41     rm -f /dev/*vnn*
42     mknod /dev/vnn${u} c 43 `expr 65538 + $u '*' 8`
43     ln -s /dev/vnn${u} /dev/rvnn${u}
44     mknod /dev/vnn${u}c c 43 `expr 2 + $u '*' 8`
45     ln -s /dev/vnn${u}c /dev/rvnn${u}c
46
47     while true 
48     do
49         rm -f ${FSIMG}
50
51         umount /dev/${VNDEVICE} 2>/dev/null || true
52         umount ${MNT} 2>/dev/null || true
53         vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true
54
55         dd of=${FSIMG} if=/dev/zero count=${FSSIZE} bs=1k 2>/dev/null
56
57         vnconfig -s labels -c /dev/r${VNDEVICE} ${FSIMG}
58         disklabel -w -B ${BOOT1} ${BOOT2} ${VNDEVICE} ${FSLABEL}
59         newfs -i ${FSINODE} -o space -m 0 /dev/r${VNDEVICE}c
60
61         mount /dev/${VNDEVICE}c ${MNT}
62
63         if [ -d ${FSPROTO} ]; then
64                 (set -e && cd ${FSPROTO} && find . -print | cpio -dump ${MNT})
65         else
66                 cp -p ${FSPROTO} ${MNT}
67         fi
68
69         df -ki ${MNT}
70
71         set `df -ki ${MNT} | tail -1`
72
73         umount ${MNT}
74         vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true
75
76         echo "*** Filesystem is ${FSSIZE} K, $4 left"
77         echo "***     ${FSINODE} bytes/inode, $7 left"
78         if [ "${do_size}" ]; then
79                 echo ${FSSIZE} > ${FSIMG}.size
80         fi
81         break;
82     done
83
84     rm -f /dev/*vnn*
85 }
86
87 dofs_md () {
88     while true 
89     do
90         rm -f ${FSIMG}
91
92         if [ "x${MDDEVICE}" != "x" ] ; then
93                 umount /dev/${MDDEVICE} 2>/dev/null || true
94                 umount ${MNT} 2>/dev/null || true
95                 mdconfig -d -u ${MDDEVICE} 2>/dev/null || true
96         fi
97
98         dd of=${FSIMG} if=/dev/zero count=${FSSIZE} bs=1k 2>/dev/null
99
100         MDDEVICE=`mdconfig -a -t vnode -f ${FSIMG}`
101         if [ ! -c /dev/${MDDEVICE} ] ; then
102                 if [ -f /dev/MAKEDEV ] ; then
103                         ( cd /dev && sh MAKEDEV ${MDDEVICE} )
104                 else
105                         echo "No /dev/$MDDEVICE and no MAKEDEV" 1>&2
106                         exit 1
107                 fi
108         fi
109         disklabel -w -B ${BOOT1} ${BOOT2} ${MDDEVICE} ${FSLABEL}
110         newfs -i ${FSINODE} -o space -m 0 /dev/${MDDEVICE}c
111
112         mount /dev/${MDDEVICE}c ${MNT}
113
114         if [ -d ${FSPROTO} ]; then
115                 (set -e && cd ${FSPROTO} && find . -print | cpio -dump ${MNT})
116         else
117                 cp -p ${FSPROTO} ${MNT}
118         fi
119
120         df -ki ${MNT}
121
122         set `df -ki ${MNT} | tail -1`
123
124         umount ${MNT}
125         mdconfig -d -u ${MDDEVICE} 2>/dev/null || true
126
127         echo "*** Filesystem is ${FSSIZE} K, $4 left"
128         echo "***     ${FSINODE} bytes/inode, $7 left"
129         if [ "${do_size}" ]; then
130                 echo ${FSSIZE} > ${FSIMG}.size
131         fi
132         break;
133     done
134 }
135
136 case `uname -r` in
137 [1-4].*)
138         dofs_vn
139         ;;
140 *)
141         if [ ! -f "${RD}/trees/bin/boot/boot" ]; then
142                 cp -p ${RD}/trees/bin/boot/boot1 ${RD}/trees/bin/boot/boot
143                 if [ -f "${RD}/trees/bin/boot/boot2" ]; then
144                         cat ${RD}/trees/bin/boot/boot2 >> \
145                             ${RD}/trees/bin/boot/boot
146                 fi
147         fi
148         BOOT1="-b ${RD}/trees/bin/boot/boot"
149         BOOT2=""
150         dofs_md
151         ;;
152 esac