Add a section on how to build the world inside a virtual kernel.
[dragonfly.git] / share / man / man7 / vkernel.7
1 .\"
2 .\" Copyright (c) 2003, 2004, 2005, 2006, 2007
3 .\"     The DragonFly Project.  All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\"
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in
13 .\"    the documentation and/or other materials provided with the
14 .\"    distribution.
15 .\" 3. Neither the name of The DragonFly Project nor the names of its
16 .\"    contributors may be used to endorse or promote products derived
17 .\"    from this software without specific, prior written permission.
18 .\"
19 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\" $DragonFly: src/share/man/man7/vkernel.7,v 1.23 2007/07/03 18:05:55 dillon Exp $
33 .\"
34 .Dd June 14, 2007
35 .Dt VKERNEL 7
36 .Os
37 .Sh NAME
38 .Nm vkernel ,
39 .Nm vkd ,
40 .Nm vke
41 .Nd virtual kernel architecture
42 .Sh SYNOPSIS
43 .Cd "platform vkernel"
44 .Cd "device vkd"
45 .Cd "device vke"
46 .Pp
47 .Pa /usr/obj/usr/src/sys/VKERNEL/kernel.debug
48 .Op Fl sUv
49 .Op Fl c Ar file
50 .Op Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ...
51 .Op Fl i Ar file
52 .Op Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc
53 .Op Fl m Ar size
54 .Op Fl n Ar numcpus
55 .Op Fl p Ar file
56 .Op Fl r Ar file
57 .Sh DESCRIPTION
58 The
59 .Nm
60 architecture allows for running
61 .Dx
62 kernels in userland.
63 .Pp
64 The following options are available:
65 .Bl -tag -width ".Fl m Ar size"
66 .It Fl c Ar file
67 Specify a readonly CD-ROM image
68 .Ar file
69 to be used by the kernel, with the first
70 .Fl c
71 option defining
72 .Li vcd0 ,
73 the second one
74 .Li vcd1 ,
75 and so on.  The first
76 .Fl r
77 or
78 .Fl c
79 option specified on the command line will be the boot disk.
80 The CD9660 filesystem is assumed when booting from this media.
81 .It Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ...
82 Specify an environment to be used by the kernel.
83 .It Fl i Ar file
84 Specify a memory image
85 .Ar file
86 to be used by the virtual kernel.
87 If no
88 .Fl i
89 option is given, the kernel will generate a name of the form
90 .Pa /var/vkernel/memimg.XXXXXX ,
91 with the trailing
92 .Ql X Ns s
93 being replaced by a sequential number, e.g.\&
94 .Pa memimg.000001 .
95 .It Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc
96 Create a virtual network device, with the first
97 .Fl I
98 option defining
99 .Li vke0 ,
100 the second one
101 .Li vke1 ,
102 and so on.
103 .Pp
104 The
105 .Ar interface
106 argument is the name of a
107 .Xr tap 4
108 device node.
109 The
110 .Pa /dev/
111 path prefix does not have to be specified and will be automatically prepended.
112 Specifying
113 .Cm auto
114 will pick the first unused
115 .Xr tap 4
116 device.
117 .Pp
118 The
119 .Ar address1
120 and
121 .Ar address2
122 arguments are the IP addresses of the
123 .Xr tap 4
124 and
125 .Nm vke
126 interfaces.
127 Optionally,
128 .Ar address1
129 may be of the form
130 .Li bridge Ns Em X
131 in which case the
132 .Xr tap 4
133 interface is added to the specified
134 .Xr bridge 4
135 interface.
136 .Pp
137 The
138 .Ar netmask
139 argument applies to all interfaces for which an address is specified.
140 .It Fl m Ar size
141 Specify the amount of memory to be used by the kernel in bytes,
142 .Cm K
143 .Pq kilobytes ,
144 .Cm M
145 .Pq megabytes
146 or
147 .Cm G
148 .Pq gigabytes .
149 Lowercase versions of
150 .Cm K , M ,
151 and
152 .Cm G
153 are allowed.
154 .It Fl n Ar numcpus
155 Specify the number of cpus you wish to emulate.
156 Up to 32 cpus are supported.
157 The virtual kernel must be built with options SMP to use this option
158 and will default to 2 cpus unless otherwise specified.
159 .It Fl p Ar file
160 Specify a file in which to store the process ID.
161 A warning is issued if this file cannot be opened for writing.
162 .It Fl r Ar file
163 Specify a R/W disk image
164 .Ar file
165 to be used by the kernel, with the first
166 .Fl r
167 option defining
168 .Li vkd0 ,
169 the second one
170 .Li vkd1 ,
171 and so on.  The first
172 .Fl r
173 or
174 .Fl c
175 option specified on the command line will be the boot disk.
176 .It Fl s
177 Boot into single-user mode.
178 .It Fl U
179 Enable writing to kernel memory and module loading.
180 By default, those are disabled for security reasons.
181 .It Fl v
182 Turn on verbose booting.
183 .El
184 .Sh DEVICES
185 A number of virtual device drivers exist to supplement the virtual kernel.
186 Their names start with
187 .Li vk .
188 .Ss Disk device
189 The
190 .Nm vkd
191 driver allows for up to 16
192 .Xr vn 4
193 based disk devices.
194 The root device will be
195 .Li vkd0
196 (see
197 .Sx EXAMPLES
198 for further information on how to prepare a root image).
199 .Ss Network interface
200 The
201 .Nm vke
202 driver supports up to 16 virtual network interfaces which are associated with
203 .Xr tap 4
204 devices on the host.
205 For each
206 .Nm vke
207 device, the per-interface read only
208 .Xr sysctl 3
209 variable
210 .Va hw.vke Ns Em X Ns Va .tap_unit
211 holds the unit number of the associated
212 .Xr tap 4
213 device.
214 .Sh SIGNALS
215 The virtual kernel only enables
216 .Dv SIGQUIT
217 and
218 .Dv SIGTERM
219 while operating in regular console mode.
220 Sending
221 .Ql \&^\e
222 .Pq Dv SIGQUIT
223 to the virtual kernel causes the virtual kernel to enter its internal
224 .Xr ddb 4
225 debugger and re-enable all other terminal signals.
226 Sending
227 .Dv SIGTERM
228 to the virtual kernel triggers a clean shutdown by passing a
229 .Dv SIGUSR2
230 to the virtual kernel's
231 .Xr init 8
232 process.
233 .Sh DEBUGGING
234 It is possible to directly gdb the virtual kernel's process.
235 It is recommended that you do a
236 .Ql handle SIGSEGV noprint
237 to ignore page faults processed by the virtual kernel itself.
238 .Sh EXAMPLES
239 A couple of steps are necessary in order to prepare the system to build and
240 run a virtual kernel.
241 .Ss Setting up the filesystem
242 The
243 .Nm
244 architecture needs a number of files which reside in
245 .Pa /var/vkernel .
246 Since these files tend to get rather big and the
247 .Pa /var
248 partition is usually of limited size, we recommend the directory to be
249 created in the
250 .Pa /home
251 partition with a link to it in
252 .Pa /var :
253 .Bd -literal
254 mkdir /home/var.vkernel
255 ln -s /home/var.vkernel /var/vkernel
256 .Ed
257 .Pp
258 Next, a filesystem image to be used by the virtual kernel has to be
259 created and populated (assuming world has been built previously):
260 .Bd -literal
261 dd if=/dev/zero of=/var/vkernel/rootimg.01 bs=1m count=2048
262 vnconfig -c -s labels vn0 /var/vkernel/rootimg.01
263 disklabel -r -w vn0s0 auto
264 disklabel -e vn0s0      # edit the label to create a vn0s0a partition
265 newfs /dev/vn0s0a
266 mount /dev/vn0s0a /mnt
267 cd /usr/src
268 make installworld DESTDIR=/mnt
269 cd etc
270 make distribution DESTDIR=/mnt
271 echo '/dev/vkd0a / ufs rw 1 1' >/mnt/etc/fstab
272 .Ed
273 .Pp
274 Edit
275 .Pa /mnt/etc/ttys
276 and replace the
277 .Li console
278 entry with the following line and turn off all other gettys.
279 .Bd -literal
280 console "/usr/libexec/getty Pc"         cons25  on  secure
281 .Ed
282 .Pp
283 Then, unmount the disk.
284 .Bd -literal
285 umount /mnt
286 vnconfig -u vn0
287 .Ed
288 .Ss Compiling the virtual kernel
289 In order to compile a virtual kernel use the
290 .Li VKERNEL
291 kernel configuration file residing in
292 .Pa /usr/src/sys/config
293 (or a configuration file derived thereof):
294 .Bd -literal
295 cd /usr/src
296 make -DNO_MODULES buildkernel KERNCONF=VKERNEL
297 .Ed
298 .Ss Enabling virtual kernel operation
299 A special
300 .Xr sysctl 8 ,
301 .Va vm.vkernel_enable ,
302 must be set to enable
303 .Nm
304 operation:
305 .Bd -literal
306 sysctl vm.vkernel_enable=1
307 .Ed
308 .Ss Configuring the network on the host system
309 In order to access a network interface of the host system from the
310 .Nm ,
311 you must add the interface to a
312 .Xr bridge 4
313 device which will then be passed to the
314 .Fl I
315 option:
316 .Bd -literal
317 kldload if_bridge.ko
318 kldload if_tap.ko
319 ifconfig bridge0 create
320 ifconfig bridge0 addm re0       # assuming re0 is the host's interface
321 ifconfig bridge0 up
322 .Ed
323 .Ss Running the kernel
324 Finally, the virtual kernel can be run:
325 .Bd -literal
326 cd /usr/obj/usr/src/sys/VKERNEL
327 \&./kernel.debug -m 64m -r /var/vkernel/rootimg.01 -I auto:bridge0
328 .Ed
329 .Pp
330 The
331 .Xr reboot 8
332 command can be used to stop a virtual kernel.
333 .Sh BUILDING THE WORLD UNDER A VKERNEL
334 The virtual kernel platform does not have all the header files expected
335 by a world build, so the easiest thing to do right now is to specify a
336 pc32 target when building the world under a virtual kernel, like this:
337 .Bd -literal
338 vkernel# make MACHINE_PLATFORM=pc32 buildworld
339 vkernel# make MACHINE_PLATFORM=pc32 installworld
340 .Ed
341 .Sh SEE ALSO
342 .Xr bridge 4 ,
343 .Xr tap 4 ,
344 .Xr vn 4 ,
345 .Xr build 7 ,
346 .Xr disklabel 8 ,
347 .Xr ifconfig 8 ,
348 .Xr vnconfig 8
349 .Sh HISTORY
350 Virtual kernels were introduced in
351 .Dx 1.7 .
352 .Sh AUTHORS
353 .An -nosplit
354 .An Matt Dillon
355 thought up and implemented the
356 .Nm
357 architecture and wrote the
358 .Nm vkd
359 device driver.
360 .An Sepherosa Ziehau
361 wrote the
362 .Nm vke
363 device driver.
364 This manual page was written by
365 .An Sascha Wildner .