diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-11-24 07:58:56 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-11-24 07:58:56 +0000 |
commit | 81d8dac5286fc0d2981df1a3284c184ae3c6e9d5 (patch) | |
tree | 02c8d9ed18b4e832e7e4f28e5f1a183d2be41829 /usr.sbin/vmd/vmm.c | |
parent | 318a7884e9d299146de19d369e29bf264cc1180c (diff) |
Add support for booting the kernel from the disk image.
This make the kernel/-k argument optional and, if not specified, tries
to find the /bsd kernel in the primary hd0a partition of the first
disk image itself. It doesn't support hd0a:/etc/boot.conf yet, and it
is no BIOS or full boot loader, but it makes booting and handling of
VMs a bit easier - booting an external kernel is still supported.
The UFS file system code ufs.c is directly from libsa which is also
used by the real boot loader. The code compiles with a few signedness
warning which will be fixed separately.
OK mlarkin@
Diffstat (limited to 'usr.sbin/vmd/vmm.c')
-rw-r--r-- | usr.sbin/vmd/vmm.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 226b8ceefa4..ecd74545c1b 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.55 2016/11/22 22:51:45 reyk Exp $ */ +/* $OpenBSD: vmm.c,v 1.56 2016/11/24 07:58:55 reyk Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -465,7 +465,9 @@ start_vm(struct imsg *imsg, uint32_t *id) size_t i; int ret = EINVAL; int fds[2], nicfds[VMM_MAX_NICS_PER_VM]; - struct vcpu_reg_state vrs; + struct vcpu_reg_state vrs; + FILE *kernfp; + void *boot; if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { log_warnx("%s: can't find vm", __func__); @@ -566,14 +568,22 @@ start_vm(struct imsg *imsg, uint32_t *id) */ memcpy(&vrs, &vcpu_init_flat32, sizeof(struct vcpu_reg_state)); + /* Find and open kernel image */ + if ((kernfp = vmboot_open(vm->vm_kernel, + vm->vm_disks[0], &boot)) == NULL) + fatalx("failed to open kernel - exiting"); + /* Load kernel image */ - ret = loadelf_main(vm->vm_kernel, vcp, &vrs); + ret = loadelf_main(kernfp, vcp, &vrs); if (ret) { errno = ret; fatal("failed to load kernel - exiting"); } - close(vm->vm_kernel); + vmboot_close(kernfp, boot); + + if (vm->vm_kernel != -1) + close(vm->vm_kernel); con_fd = vm->vm_tty; if (fcntl(con_fd, F_SETFL, O_NONBLOCK) == -1) |