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 Feb 17, 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 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 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. 242The first 243.Fl r 244or 245.Fl c 246option specified on the command line will be the boot disk. 247.It Fl s 248Boot into single-user mode. 249.It Fl U 250Enable writing to kernel memory and module loading. 251By default, those are disabled for security reasons. 252.It Fl v 253Turn on verbose booting. 254.El 255.Sh DEVICES 256A number of virtual device drivers exist to supplement the virtual kernel. 257.Ss Disk device 258The 259.Nm vkd 260driver allows for up to 16 261.Xr vn 4 262based disk devices. 263The root device will be 264.Li vkd0 265(see 266.Sx EXAMPLES 267for further information on how to prepare a root image). 268.Ss CD-ROM device 269The 270.Nm vcd 271driver allows for up to 16 virtual CD-ROM devices. 272Basically this is a read only 273.Nm vkd 274device with a block size of 2048. 275.Ss Network interface 276The 277.Nm vke 278driver supports up to 16 virtual network interfaces which are associated with 279.Xr tap 4 280devices on the host. 281For each 282.Nm vke 283device, the per-interface read only 284.Xr sysctl 3 285variable 286.Va hw.vke Ns Em X Ns Va .tap_unit 287holds the unit number of the associated 288.Xr tap 4 289device. 290.Sh SIGNALS 291The virtual kernel only enables 292.Dv SIGQUIT 293and 294.Dv SIGTERM 295while operating in regular console mode. 296Sending 297.Ql \&^\e 298.Pq Dv SIGQUIT 299to the virtual kernel causes the virtual kernel to enter its internal 300.Xr ddb 4 301debugger and re-enable all other terminal signals. 302Sending 303.Dv SIGTERM 304to the virtual kernel triggers a clean shutdown by passing a 305.Dv SIGUSR2 306to the virtual kernel's 307.Xr init 8 308process. 309.Sh DEBUGGING 310It is possible to directly gdb the virtual kernel's process. 311It is recommended that you do a 312.Ql handle SIGSEGV noprint 313to ignore page faults processed by the virtual kernel itself and 314.Ql handle SIGUSR1 noprint 315to ignore signals used for simulating inter-processor interrupts. 316.Sh PROFILING 317To compile a vkernel with profiling support, the 318.Va CONFIGARGS 319variable needs to be used to pass 320.Fl p 321to 322.Xr config 8 . 323.Bd -literal 324cd /usr/src 325make -DNO_MODULES CONFIGARGS=-p buildkernel KERNCONF=VKERNEL 326.Ed 327.Sh FILES 328.Bl -tag -width ".It Pa /sys/config/VKERNEL" -compact 329.It Pa /sys/config/VKERNEL 330.It Pa /sys/config/VKERNEL64 331.El 332.Pp 333Per architecture 334.Nm 335configuration files, for 336.Xr config 8 . 337.Sh CONFIGURATION FILES 338Your virtual kernel is a complete 339.Dx 340system, but you might not want to run all the services a normal kernel runs. 341Here is what a typical virtual kernel's 342.Pa /etc/rc.conf 343file looks like, with some additional possibilities commented out. 344.Bd -literal 345hostname="vkernel" 346network_interfaces="lo0 vke0" 347ifconfig_vke0="DHCP" 348sendmail_enable="NO" 349#syslog_enable="NO" 350blanktime="NO" 351.Ed 352.Sh DISKLESS OPERATION 353To boot a 354.Nm 355from a NFS root, a number of tunables need to be set: 356.Bl -tag -width indent 357.It Va boot.netif.ip 358IP address to be set in the vkernel interface. 359.It Va boot.netif.netmask 360Netmask for the IP to be set. 361.It Va boot.netif.name 362Network interface name inside the vkernel. 363.It Va boot.nfsroot.server 364Host running 365.Xr nfsd 8 . 366.It Va boot.nfsroot.path 367Host path where a world and distribution 368targets are properly installed. 369.El 370.Pp 371See an example on how to boot a diskless 372.Nm 373in the 374.Sx EXAMPLES 375section. 376.Sh EXAMPLES 377A couple of steps are necessary in order to prepare the system to build and 378run a virtual kernel. 379.Ss Setting up the filesystem 380The 381.Nm 382architecture needs a number of files which reside in 383.Pa /var/vkernel . 384Since these files tend to get rather big and the 385.Pa /var 386partition is usually of limited size, we recommend the directory to be 387created in the 388.Pa /home 389partition with a link to it in 390.Pa /var : 391.Bd -literal 392mkdir -p /home/var.vkernel/boot 393ln -s /home/var.vkernel /var/vkernel 394.Ed 395.Pp 396Next, a filesystem image to be used by the virtual kernel has to be 397created and populated (assuming world has been built previously). 398If the image is created on a UFS filesystem you might want to pre-zero it. 399On a HAMMER filesystem you should just truncate-extend to the image size 400as HAMMER does not re-use data blocks already present in the file. 401.Bd -literal 402vnconfig -c -S 2g -T vn0 /var/vkernel/rootimg.01 403disklabel -r -w vn0s0 auto 404disklabel -e vn0s0 # add `a' partition with fstype `4.2BSD' 405newfs /dev/vn0s0a 406mount /dev/vn0s0a /mnt 407cd /usr/src 408make installworld DESTDIR=/mnt 409cd etc 410make distribution DESTDIR=/mnt 411echo '/dev/vkd0s0a / ufs rw 1 1' >/mnt/etc/fstab 412echo 'proc /proc procfs rw 0 0' >>/mnt/etc/fstab 413.Ed 414.Pp 415Edit 416.Pa /mnt/etc/ttys 417and replace the 418.Li console 419entry with the following line and turn off all other gettys. 420.Bd -literal 421console "/usr/libexec/getty Pc" cons25 on secure 422.Ed 423.Pp 424Replace 425.Li \&Pc 426with 427.Li al.Pc 428if you would like to automatically log in as root. 429.Pp 430Then, unmount the disk. 431.Bd -literal 432umount /mnt 433vnconfig -u vn0 434.Ed 435.Ss Compiling the virtual kernel 436In order to compile a virtual kernel use the 437.Li VKERNEL 438kernel configuration file residing in 439.Pa /sys/config 440(or a configuration file derived thereof): 441.Bd -literal 442cd /usr/src 443make -DNO_MODULES buildkernel KERNCONF=VKERNEL 444make -DNO_MODULES installkernel KERNCONF=VKERNEL DESTDIR=/var/vkernel 445.Ed 446.Ss Enabling virtual kernel operation 447A special 448.Xr sysctl 8 , 449.Va vm.vkernel_enable , 450must be set to enable 451.Nm 452operation: 453.Bd -literal 454sysctl vm.vkernel_enable=1 455.Ed 456.Ss Configuring the network on the host system 457In order to access a network interface of the host system from the 458.Nm , 459you must add the interface to a 460.Xr bridge 4 461device which will then be passed to the 462.Fl I 463option: 464.Bd -literal 465kldload if_bridge.ko 466kldload if_tap.ko 467ifconfig bridge0 create 468ifconfig bridge0 addm re0 # assuming re0 is the host's interface 469ifconfig bridge0 up 470.Ed 471.Ss Running the kernel 472Finally, the virtual kernel can be run: 473.Bd -literal 474cd /var/vkernel 475\&./boot/kernel/kernel -m 64m -r rootimg.01 -I auto:bridge0 476.Ed 477.Pp 478You can issue the 479.Xr reboot 8 , 480.Xr halt 8 , 481or 482.Xr shutdown 8 483commands from inside a virtual kernel. 484After doing a clean shutdown the 485.Xr reboot 8 486command will re-exec the virtual kernel binary while the other two will 487cause the virtual kernel to exit. 488.Ss Diskless operation 489Booting a 490.Nm 491with a 492.Xr vknetd 8 493network configuration: 494.Bd -literal 495\&./boot/kernel/kernel -m 64m -m -i memimg.0000 -I /var/run/vknet 496 -e boot.netif.ip=172.1.0.4 497 -e boot.netif.netmask=255.255.0.0 498 -e boot.netif.name=vke0 499 -e boot.nfsroot.server=172.1.0.1 500 -e boot.nfsroot.path=/home/vkernel/vkdiskless 501.Ed 502.Sh BUILDING THE WORLD UNDER A VKERNEL 503The virtual kernel platform does not have all the header files expected 504by a world build, so the easiest thing to do right now is to specify a 505pc32 (in a 32 bit vkernel) or pc64 (in a 64 bit vkernel) target when 506building the world under a virtual kernel, like this: 507.Bd -literal 508vkernel# make MACHINE_PLATFORM=pc32 buildworld 509vkernel# make MACHINE_PLATFORM=pc32 installworld 510.Ed 511.Sh SEE ALSO 512.Xr vknet 1 , 513.Xr bridge 4 , 514.Xr tap 4 , 515.Xr vn 4 , 516.Xr sysctl.conf 5 , 517.Xr build 7 , 518.Xr config 8 , 519.Xr disklabel 8 , 520.Xr ifconfig 8 , 521.Xr vknetd 8 , 522.Xr vnconfig 8 523.Rs 524.%A Aggelos Economopoulos 525.%D March 2007 526.%T "A Peek at the DragonFly Virtual Kernel" 527.Re 528.Sh HISTORY 529Virtual kernels were introduced in 530.Dx 1.7 . 531.Sh AUTHORS 532.An -nosplit 533.An Matt Dillon 534thought up and implemented the 535.Nm 536architecture and wrote the 537.Nm vkd 538device driver. 539.An Sepherosa Ziehau 540wrote the 541.Nm vke 542device driver. 543This manual page was written by 544.An Sascha Wildner . 545