1.\" 2.\" Copyright (c) 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.Dd February 22, 2013 33.Dt VKERNEL 7 34.Os 35.Sh NAME 36.Nm vkernel , 37.Nm vcd , 38.Nm vkd , 39.Nm vke 40.Nd virtual kernel architecture 41.Sh SYNOPSIS 42.Cd "platform vkernel # for 32 bit vkernels" 43.Cd "platform vkernel64 # for 64 bit vkernels" 44.Cd "device vcd" 45.Cd "device vkd" 46.Cd "device vke" 47.Pp 48.Pa /var/vkernel/boot/kernel/kernel 49.Op Fl hsUv 50.Op Fl c Ar file 51.Op Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ... 52.Op Fl i Ar file 53.Op Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc Ns Oo Ar =mac Oc 54.Op Fl l Ar cpulock 55.Op Fl m Ar size 56.Op Fl n Ar numcpus Ns Op Ar :lbits Ns Oo Ar :cbits Oc 57.Op Fl p Ar pidfile 58.Op Fl r Ar file Ns Op Ar :serno 59.Sh DESCRIPTION 60The 61.Nm 62architecture allows for running 63.Dx 64kernels in userland. 65.Pp 66The following options are available: 67.Bl -tag -width ".Fl m Ar size" 68.It Fl c Ar file 69Specify a readonly CD-ROM image 70.Ar file 71to be used by the kernel, with the first 72.Fl c 73option defining 74.Li vcd0 , 75the second one 76.Li vcd1 , 77and so on. 78The first 79.Fl r 80or 81.Fl c 82option specified on the command line will be the boot disk. 83The CD9660 filesystem is assumed when booting from this media. 84.It Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ... 85Specify an environment to be used by the kernel. 86This option can be specified more than once. 87.It Fl h 88Shows a list of available options, each with a short description. 89.It Fl i Ar file 90Specify a memory image 91.Ar file 92to be used by the virtual kernel. 93If no 94.Fl i 95option is given, the kernel will generate a name of the form 96.Pa /var/vkernel/memimg.XXXXXX , 97with the trailing 98.Ql X Ns s 99being replaced by a sequential number, e.g.\& 100.Pa memimg.000001 . 101.It Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc Ns Oo Ar =MAC Oc 102Create a virtual network device, with the first 103.Fl I 104option defining 105.Li vke0 , 106the second one 107.Li vke1 , 108and so on. 109.Pp 110The 111.Ar interface 112argument is the name of a 113.Xr tap 4 114device node or the path to a 115.Xr vknetd 8 116socket. 117The 118.Pa /dev/ 119path prefix does not have to be specified and will be automatically prepended 120for a device node. 121Specifying 122.Cm auto 123will pick the first unused 124.Xr tap 4 125device. 126.Pp 127The 128.Ar address1 129and 130.Ar address2 131arguments are the IP addresses of the 132.Xr tap 4 133and 134.Nm vke 135interfaces. 136Optionally, 137.Ar address1 138may be of the form 139.Li bridge Ns Em X 140in which case the 141.Xr tap 4 142interface is added to the specified 143.Xr bridge 4 144interface. 145The 146.Nm vke 147address is not assigned until the interface is brought up in the guest. 148.Pp 149The 150.Ar netmask 151argument applies to all interfaces for which an address is specified. 152.Pp 153The 154.Ar MAC 155argument is the MAC address of the 156.Xr vke 4 157interface. 158If not specified, a pseudo-random one will be generated. 159.Pp 160When running multiple vkernels it is often more convenient to simply 161connect to a 162.Xr vknetd 8 163socket and let vknetd deal with the tap and/or bridge. An example of 164this would be '/var/run/vknet:0.0.0.0:10.2.0.2/16'. 165.It Fl l Ar cpulock 166Specify which, if any, real CPUs to lock virtual CPUs to. 167.Ar cpulock 168is one of 169.Cm any , 170.Cm map Ns Op Ns , Ns Ar startCPU , 171or 172.Ar CPU . 173.Pp 174.Cm any 175does not map virtual CPUs to real CPUs. 176This is the default. 177.Pp 178.Cm map Ns Op Ns , Ns Ar startCPU 179maps each virtual CPU to a real CPU starting with real CPU 0 or 180.Ar startCPU 181if specified. 182.Pp 183.Ar CPU 184locks all virtual CPUs to the real CPU specified by 185.Ar CPU . 186.It Fl m Ar size 187Specify the amount of memory to be used by the kernel in bytes, 188.Cm K 189.Pq kilobytes , 190.Cm M 191.Pq megabytes 192or 193.Cm G 194.Pq gigabytes . 195Lowercase versions of 196.Cm K , M , 197and 198.Cm G 199are allowed. 200.It Fl n Ar numcpus Ns Op Ar :lbits Ns Oo Ar :cbits Oc 201.Ar numcpus 202specifies the number of CPUs you wish to emulate. 203Up to 16 CPUs are supported with 2 being the default unless otherwise 204specified. 205.Ar lbits 206specifies the number of bits within APICID(=CPUID) needed for representing 207the logical ID. 208Controls the number of threads/core (0bits - 1 thread, 1bit - 2 threads). 209This parameter is optional (mandatory only if 210.Ar cbits 211is specified). 212.Ar cbits 213specifies the number of bits within APICID(=CPUID) needed for representing 214the core ID. 215Controls the number of core/package (0bits - 1 core, 1bit - 2 cores). 216This parameter is optional. 217.It Fl p Ar pidfile 218Specify a pidfile in which to store the process ID. 219Scripts can use this file to locate the vkernel pid for the purpose of 220shutting down or killing it. 221.Pp 222The vkernel will hold a lock on the pidfile while running. 223Scripts may test for the lock to determine if the pidfile is valid or 224stale so as to avoid accidentally killing a random process. 225Something like '/usr/bin/lockf -ks -t 0 pidfile echo -n' may be used 226to test the lock. 227A non-zero exit code indicates that the pidfile represents a running 228vkernel. 229.Pp 230An error is issued and the vkernel exits if this file cannot be opened for 231writing or if it is already locked by an active vkernel process. 232.It Fl r Ar file Ns Op Ar :serno 233Specify a R/W disk image 234.Ar file 235to be used by the kernel, with the first 236.Fl r 237option defining 238.Li vkd0 , 239the second one 240.Li vkd1 , 241and so on. 242A serial number for the virtual disk can be specified in 243.Ar serno . 244.Pp 245The first 246.Fl r 247or 248.Fl c 249option specified on the command line will be the boot disk. 250.It Fl s 251Boot into single-user mode. 252.It Fl U 253Enable writing to kernel memory and module loading. 254By default, those are disabled for security reasons. 255.It Fl v 256Turn on verbose booting. 257.El 258.Sh DEVICES 259A number of virtual device drivers exist to supplement the virtual kernel. 260.Ss Disk device 261The 262.Nm vkd 263driver allows for up to 16 264.Xr vn 4 265based disk devices. 266The root device will be 267.Li vkd0 268(see 269.Sx EXAMPLES 270for further information on how to prepare a root image). 271.Ss CD-ROM device 272The 273.Nm vcd 274driver allows for up to 16 virtual CD-ROM devices. 275Basically this is a read only 276.Nm vkd 277device with a block size of 2048. 278.Ss Network interface 279The 280.Nm vke 281driver supports up to 16 virtual network interfaces which are associated with 282.Xr tap 4 283devices on the host. 284For each 285.Nm vke 286device, the per-interface read only 287.Xr sysctl 3 288variable 289.Va hw.vke Ns Em X Ns Va .tap_unit 290holds the unit number of the associated 291.Xr tap 4 292device. 293.Sh SIGNALS 294The virtual kernel only enables 295.Dv SIGQUIT 296and 297.Dv SIGTERM 298while operating in regular console mode. 299Sending 300.Ql \&^\e 301.Pq Dv SIGQUIT 302to the virtual kernel causes the virtual kernel to enter its internal 303.Xr ddb 4 304debugger and re-enable all other terminal signals. 305Sending 306.Dv SIGTERM 307to the virtual kernel triggers a clean shutdown by passing a 308.Dv SIGUSR2 309to the virtual kernel's 310.Xr init 8 311process. 312.Sh DEBUGGING 313It is possible to directly gdb the virtual kernel's process. 314It is recommended that you do a 315.Ql handle SIGSEGV noprint 316to ignore page faults processed by the virtual kernel itself and 317.Ql handle SIGUSR1 noprint 318to ignore signals used for simulating inter-processor interrupts. 319.Sh PROFILING 320To compile a vkernel with profiling support, the 321.Va CONFIGARGS 322variable needs to be used to pass 323.Fl p 324to 325.Xr config 8 . 326.Bd -literal 327cd /usr/src 328make -DNO_MODULES CONFIGARGS=-p buildkernel KERNCONF=VKERNEL 329.Ed 330.Sh FILES 331.Bl -tag -width ".It Pa /sys/config/VKERNEL" -compact 332.It Pa /sys/config/VKERNEL 333.It Pa /sys/config/VKERNEL64 334.El 335.Pp 336Per architecture 337.Nm 338configuration files, for 339.Xr config 8 . 340.Sh CONFIGURATION FILES 341Your virtual kernel is a complete 342.Dx 343system, but you might not want to run all the services a normal kernel runs. 344Here is what a typical virtual kernel's 345.Pa /etc/rc.conf 346file looks like, with some additional possibilities commented out. 347.Bd -literal 348hostname="vkernel" 349network_interfaces="lo0 vke0" 350ifconfig_vke0="DHCP" 351sendmail_enable="NO" 352#syslog_enable="NO" 353blanktime="NO" 354.Ed 355.Sh DISKLESS OPERATION 356To boot a 357.Nm 358from a NFS root, a number of tunables need to be set: 359.Bl -tag -width indent 360.It Va boot.netif.ip 361IP address to be set in the vkernel interface. 362.It Va boot.netif.netmask 363Netmask for the IP to be set. 364.It Va boot.netif.name 365Network interface name inside the vkernel. 366.It Va boot.nfsroot.server 367Host running 368.Xr nfsd 8 . 369.It Va boot.nfsroot.path 370Host path where a world and distribution 371targets are properly installed. 372.El 373.Pp 374See an example on how to boot a diskless 375.Nm 376in the 377.Sx EXAMPLES 378section. 379.Sh EXAMPLES 380A couple of steps are necessary in order to prepare the system to build and 381run a virtual kernel. 382.Ss Setting up the filesystem 383The 384.Nm 385architecture needs a number of files which reside in 386.Pa /var/vkernel . 387Since these files tend to get rather big and the 388.Pa /var 389partition is usually of limited size, we recommend the directory to be 390created in the 391.Pa /home 392partition with a link to it in 393.Pa /var : 394.Bd -literal 395mkdir -p /home/var.vkernel/boot 396ln -s /home/var.vkernel /var/vkernel 397.Ed 398.Pp 399Next, a filesystem image to be used by the virtual kernel has to be 400created and populated (assuming world has been built previously). 401If the image is created on a UFS filesystem you might want to pre-zero it. 402On a HAMMER filesystem you should just truncate-extend to the image size 403as HAMMER does not re-use data blocks already present in the file. 404.Bd -literal 405vnconfig -c -S 2g -T vn0 /var/vkernel/rootimg.01 406disklabel -r -w vn0s0 auto 407disklabel -e vn0s0 # add `a' partition with fstype `4.2BSD' 408newfs /dev/vn0s0a 409mount /dev/vn0s0a /mnt 410cd /usr/src 411make installworld DESTDIR=/mnt 412cd etc 413make distribution DESTDIR=/mnt 414echo '/dev/vkd0s0a / ufs rw 1 1' >/mnt/etc/fstab 415echo 'proc /proc procfs rw 0 0' >>/mnt/etc/fstab 416.Ed 417.Pp 418Edit 419.Pa /mnt/etc/ttys 420and replace the 421.Li console 422entry with the following line and turn off all other gettys. 423.Bd -literal 424console "/usr/libexec/getty Pc" cons25 on secure 425.Ed 426.Pp 427Replace 428.Li \&Pc 429with 430.Li al.Pc 431if you would like to automatically log in as root. 432.Pp 433Then, unmount the disk. 434.Bd -literal 435umount /mnt 436vnconfig -u vn0 437.Ed 438.Ss Compiling the virtual kernel 439In order to compile a virtual kernel use the 440.Li VKERNEL 441kernel configuration file residing in 442.Pa /sys/config 443(or a configuration file derived thereof): 444.Bd -literal 445cd /usr/src 446make -DNO_MODULES buildkernel KERNCONF=VKERNEL 447make -DNO_MODULES installkernel KERNCONF=VKERNEL DESTDIR=/var/vkernel 448.Ed 449.Ss Enabling virtual kernel operation 450A special 451.Xr sysctl 8 , 452.Va vm.vkernel_enable , 453must be set to enable 454.Nm 455operation: 456.Bd -literal 457sysctl vm.vkernel_enable=1 458.Ed 459.Ss Configuring the network on the host system 460In order to access a network interface of the host system from the 461.Nm , 462you must add the interface to a 463.Xr bridge 4 464device which will then be passed to the 465.Fl I 466option: 467.Bd -literal 468kldload if_bridge.ko 469kldload if_tap.ko 470ifconfig bridge0 create 471ifconfig bridge0 addm re0 # assuming re0 is the host's interface 472ifconfig bridge0 up 473.Ed 474.Ss Running the kernel 475Finally, the virtual kernel can be run: 476.Bd -literal 477cd /var/vkernel 478\&./boot/kernel/kernel -m 64m -r rootimg.01 -I auto:bridge0 479.Ed 480.Pp 481You can issue the 482.Xr reboot 8 , 483.Xr halt 8 , 484or 485.Xr shutdown 8 486commands from inside a virtual kernel. 487After doing a clean shutdown the 488.Xr reboot 8 489command will re-exec the virtual kernel binary while the other two will 490cause the virtual kernel to exit. 491.Ss Diskless operation 492Booting a 493.Nm 494with a 495.Xr vknetd 8 496network configuration: 497.Bd -literal 498\&./boot/kernel/kernel -m 64m -m -i memimg.0000 -I /var/run/vknet 499 -e boot.netif.ip=172.1.0.4 500 -e boot.netif.netmask=255.255.0.0 501 -e boot.netif.name=vke0 502 -e boot.nfsroot.server=172.1.0.1 503 -e boot.nfsroot.path=/home/vkernel/vkdiskless 504.Ed 505.Sh BUILDING THE WORLD UNDER A VKERNEL 506The virtual kernel platform does not have all the header files expected 507by a world build, so the easiest thing to do right now is to specify a 508pc32 (in a 32 bit vkernel) or pc64 (in a 64 bit vkernel) target when 509building the world under a virtual kernel, like this: 510.Bd -literal 511vkernel# make MACHINE_PLATFORM=pc32 buildworld 512vkernel# make MACHINE_PLATFORM=pc32 installworld 513.Ed 514.Sh SEE ALSO 515.Xr vknet 1 , 516.Xr bridge 4 , 517.Xr tap 4 , 518.Xr vn 4 , 519.Xr sysctl.conf 5 , 520.Xr build 7 , 521.Xr config 8 , 522.Xr disklabel 8 , 523.Xr ifconfig 8 , 524.Xr vknetd 8 , 525.Xr vnconfig 8 526.Rs 527.%A Aggelos Economopoulos 528.%D March 2007 529.%T "A Peek at the DragonFly Virtual Kernel" 530.Re 531.Sh HISTORY 532Virtual kernels were introduced in 533.Dx 1.7 . 534.Sh AUTHORS 535.An -nosplit 536.An Matt Dillon 537thought up and implemented the 538.Nm 539architecture and wrote the 540.Nm vkd 541device driver. 542.An Sepherosa Ziehau 543wrote the 544.Nm vke 545device driver. 546This manual page was written by 547.An Sascha Wildner . 548