test - Fix fsx build
[dragonfly.git] / test / vkernel / Makefile
blob85640390d7171167fc99e67e2a0b6a4d0c214439
1 # Makefile - set up a vkernel environment for testing the vkernel
4 # require it to be specified
5 SRCDIR ?= ${.CURDIR}/../..
6 PHYSMEM ?= 256m
7 NCPUS ?= 2
8 FSTYPE ?= ufs
9 EXTRAOPTS ?=
10 MAKE_JOBS?= $$(sysctl -n hw.ncpu)
12 all: help
14 .if ${MACHINE_ARCH} == "x86_64"
15 USEKERNEL=VKERNEL64
16 .endif
18 scratch: world kernel root install
19 @echo "Run the environment with:"
20 @echo "make VKDIR=${VKDIR} run"
22 quickw: quickworld quickkernel reinstall reinstallkernel
23 @echo "Run the environment with:"
24 @echo "make VKDIR=${VKDIR} run"
26 quick: quickkernel reinstallkernel
27 @echo "Run the environment with:"
28 @echo "make VKDIR=${VKDIR} run"
30 help:
31 @echo "Setup Instructions:"
32 @echo ""
33 @echo " setenv ROOTSIZE size (optional)"
34 @echo " setenv VKDIR target_dir"
35 @echo " setenv FSTYPE fstype (optional. values: hammer, hammer2, ufs)"
36 @echo " setenv MAKE_JOBS njobs (optional)"
37 @echo ""
38 @echo "Meta target components:"
39 @echo ""
40 @echo " help - this help"
41 @echo " clean - clean up"
42 @echo " scratch - build and install everything from scratch"
43 @echo " (this is absolutely everything)"
44 @echo " quick - incremental kernel build & reinstall"
45 @echo " quickw - incremental world & kernel build & reinstall"
46 @echo " run - run vkernel with VKDIR/root.img"
47 @echo " mount - mount VKDIR/root.img at VKDIR/root"
48 @echo " umount - unmount"
49 @echo " fsck - fsck VKDIR/root.img"
50 @echo ""
51 @echo "Individual target components:"
52 @echo ""
53 @echo " world - build the world from scratch"
54 @echo " root - create a new, empty root.img"
55 @echo " install - install a world & kernel"
56 @echo " into root.img"
57 @echo " leaf - additional customization"
58 @echo " kernel - build vkernel"
59 @echo " quickworld - incremental rebuild world"
60 @echo " quickkernel - incremental rebuild kernel"
61 @echo " reinstall - reinstall world into root.img"
62 @echo " (just the installworld piece)"
63 @echo " reinstallkernel - reinstall kernel into root.img"
64 @echo ""
66 # Unmount everything, de-configured VN, and clean up.
67 # (check handles umounting/deconfiguring)
69 clean: check
70 rm -rf ${VKDIR}/root.img ${VKDIR}/root
72 # Build the world and kernel
75 world: checkq
76 cd ${SRCDIR} && make -j ${MAKE_JOBS} buildworld
78 kernel: checkq
79 cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} buildkernel
81 nativekernel: checkq
82 cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} nativekernel
84 # Quick build - just rebuild the kernel quickly
87 quickworld: checkq
88 cd ${SRCDIR} && make -j ${MAKE_JOBS} quickworld
90 quickkernel: checkq
91 cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} quickkernel
93 # Build and mount an empty filesystem for the emulated root disk
95 # NOTE: root must umount when done because a later dependency may
96 # have a dependency on mount.
98 root: check
99 vnconfig -c -T -S ${ROOTSIZE} -s labels \
100 `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
101 dd if=/dev/zero of=/dev/`cat ${VKDIR}/vn.which` bs=32k count=4
102 fdisk -IB `cat ${VKDIR}/vn.which`
103 disklabel -r -w `cat ${VKDIR}/vn.which`s1 auto
104 disklabel `cat ${VKDIR}/vn.which`s1 > ${VKDIR}/label.tmp
105 .if ${FSTYPE} == "ufs"
106 echo 'a: * 0 4.2BSD' >> ${VKDIR}/label.tmp
107 .else
108 echo 'a: * 0 ${FSTYPE}' >> ${VKDIR}/label.tmp
109 .endif
110 disklabel -R `cat ${VKDIR}/vn.which`s1 ${VKDIR}/label.tmp
111 disklabel -B `cat ${VKDIR}/vn.which`s1
112 ${NEWFS_CMD} ${NEWFS_ARGS} /dev/`cat ${VKDIR}/vn.which`s1a
113 mkdir -p ${VKDIR}/root
114 vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
116 mount: check
117 vnconfig -c -s labels `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
118 . if ${FSTYPE} == "ufs"
119 fsck -p /dev/`cat ${VKDIR}/vn.which`s1a
120 . endif
121 ${MOUNT_CMD} /dev/`cat ${VKDIR}/vn.which`s1a ${VKDIR}/root
122 @echo "Mounted ${VKDIR}/root"
124 umount: check
126 fsck: check
127 vnconfig -c -s labels `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
128 fsck -y /dev/`cat ${VKDIR}/vn.which`s1a
129 make umount
131 # Install a fresh world & distribution, and kernel
133 install: mount
134 cd ${SRCDIR} && \
135 make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
136 cd ${SRCDIR}/etc && \
137 make -j 4 DESTDIR=${VKDIR}/root distribution
138 .if ${FSTYPE} == "ufs"
139 echo '/dev/vkd0s1a / ufs rw 1 1' > ${VKDIR}/root/etc/fstab
140 .else
141 echo '/dev/vkd0s1a / ${FSTYPE} rw 0 0' > ${VKDIR}/root/etc/fstab
142 .endif
143 echo 'proc /proc procfs rw 0 0' >> ${VKDIR}/root/etc/fstab
144 echo "vfs.root.mountfrom=\"${FSTYPE}:vkd0s1a\"" > ${VKDIR}/root/boot/loader.conf
145 #(egrep -v '^console' ${VKDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc" cons25 on secure') > ${VKDIR}/root/etc/ttys.new
146 #mv -f ${VKDIR}/root/etc/ttys.new ${VKDIR}/root/etc/ttys
147 cd ${SRCDIR} && \
148 make -j 4 \
149 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
150 installkernel
151 cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
153 leaf: mount
154 echo 'ifconfig_vke0="up"' > ${VKDIR}/root/etc/rc.conf
155 echo 'defaultrouter="10.26.0.1"' >> ${VKDIR}/root/etc/rc.conf
156 echo 'search dragonflybsd.org backplane.com' > ${VKDIR}/root/etc/resolv.conf
157 echo 'nameserver 10.0.0.25' >> ${VKDIR}/root/etc/resolv.conf
158 echo 'nameserver 10.0.0.2' >> ${VKDIR}/root/etc/resolv.conf
159 echo 'nameserver 8.8.8.8' >> ${VKDIR}/root/etc/resolv.conf
160 make umount
161 chmod 644 /build/vkernel/root.img
163 # Quick reinstall - just install a new kernel on top of an existing image
166 reinstall: mount
167 cd ${SRCDIR} && \
168 make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
170 reinstallkernel: mount
171 cd ${SRCDIR} && \
172 make -j 4 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
173 installkernel
174 cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
176 sysloader: mount
177 cp /boot/loader ${VKDIR}/root/boot/loader
178 sync
180 # Run the vkernel on our image. Make sure we are unmounted so
181 # we do not compete against the emulated kernel when writing to root.img.
182 # (check does this for us)
184 run: check
185 mkdir -p /var/vkernel
186 sysctl vm.vkernel_enable=1
187 cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} \
188 -r root.img -U -v \
189 -I /var/run/vknet ${EXTRAOPTS} ${MNTOPTS}
191 # When running w/ a NFS root
193 NFS_IP?= 10.0.0.53
194 NFS_NETMASK?= 255.255.255.0
195 NFS_ROOT_IP?= 10.0.0.1
196 NFS_ROOT_PATH?= /netboot2
198 run_nfsroot: check
199 cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} -U -v \
200 -I /var/run/vknet \
201 -e 'boot.netif.ip=${NFS_IP}:boot.netif.netmask=${NFS_NETMASK}:boot.netif.name=vke0:boot.nfsroot.server=${NFS_ROOT_IP}:boot.nfsroot.path=${NFS_ROOT_PATH}'
203 # Make sure we are not mounted and the VN device is unconfigured,
205 # Find an unused VN device but do not do anything with it yet.
207 checkq:
208 .if !defined(VKDIR)
209 @(echo "must specify VKDIR=target or as an environment variable"; /usr/bin/false)
210 .endif
212 .if exists(${VKDIR})
213 @echo "${VKDIR} found"
214 .else
215 mkdir -p ${VKDIR}
216 .endif
218 .if ${FSTYPE} == "hammer"
219 NEWFS_CMD = newfs_${FSTYPE}
220 NEWFS_ARGS = -L VKROOT -f
221 MOUNT_CMD = mount_${FSTYPE}
222 ROOTSIZE ?= 5G
223 MNTOPTS += -e vfs.root.mountfrom=\'${FSTYPE}:vkd0s1a\'
224 .elif ${FSTYPE} == "hammer2"
225 NEWFS_CMD = newfs_${FSTYPE}
226 NEWFS_ARGS = -f
227 MOUNT_CMD = mount_${FSTYPE}
228 ROOTSIZE ?= 5G
229 MNTOPTS += -e vfs.root.mountfrom=\'${FSTYPE}:vkd0s1a\'
230 .elif ${FSTYPE} == "ufs"
231 NEWFS_CMD = newfs
232 NEWFS_ARGS =
233 MOUNT_CMD = mount
234 ROOTSIZE ?= 2G
235 .else
236 @(echo "\"${FSTYPE}\" is not a valid filesystem"; /usr/bin/false)
237 .endif
238 .if ${FSTYPE} == "hammer" || ${FSTYPE} == "hammer2"
239 .endif
242 check: checkq
243 .if exists(${VKDIR}/vn.which)
244 -umount ${VKDIR}/root > /dev/null 2>&1
245 -vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
246 rm -f ${VKDIR}/vn.which
247 .endif
248 (vnconfig -l | fgrep "not in use" > /dev/null) || \
249 (echo "Cannot find unused VN"; /usr/bin/false)
250 vnconfig -l | fgrep "not in use" | \
251 cut -f 1 -d : | head -1 > ${VKDIR}/vn.which
252 egrep '^vn' ${VKDIR}/vn.which > /dev/null || \
253 (echo "VN device selection is bad"; /usr/bin/false)