Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ ifndef SHELLCHECK
$(error "cannot find shellcheck; install to run check")
endif
shellcheck -a -x \
vmctl cmd/* common/* lib/qemu/*
vmctl cmd/* common/* lib/qemu/* lib/cloudinit/*

55 changes: 18 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,50 +163,31 @@ This is useful when selftests or modules are needed within the VM.

## Prep boot img

The base configruation `*-base.conf` will look for a base image in
`img/base.qcow2`. You can use [archbase][archbase] to build a lean Arch Linux
base image or grab a QCOW2-based [Ubuntu cloud image][ubuntu-cloud-image] if
that's your vice.
There needs to be a base image in `img/base.qcow2` because the default configs
`*-base.conf` expect it. Use the following command to create a QCOW2-based
[Ubuntu cloud image][ubuntu-cloud-image]:

In the case of a standard "cloud image", you probably want to resize it since
it is usually shrunk to be as small as possible by default.
$ vmctl -c cloudinit.conf run

$ qemu-img resize img/base.qcow2 8G
**Note**: This command will do the following:
1. Create an ubuntu amd64 plucky image
2. Resize it to 8G
3. Add first ~/.ssh/*.pub file for ssh connections
4. Configure default login:"vmuser" and passwd:"vmuser"
5. It will do a qemu seed run and then powerdown to set everything up

**Note** The example `nvme.conf` will define `GUEST_BOOT="img/nvme.qcow2"`.
You do not need to provide that image - if it is not there `$GUEST_BOOT`
will be a differential image backed by `img/base.qcow2`. So, if you ever
need to reset to the "base" state, just remove the `img/nvme.qcow2` image.
After running the `cloudinit.conf` configuration, you should see an image in
`img/base.qcow2` which you can run by doing:

[archbase]: https://github.com/OpenMPDK/archbase
[ubuntu-cloud-image]: https://cloud-images.ubuntu.com

### cloud-init

If your chosen base image is meant to be configured through [cloud-init][cloud-init],
you can use the included cloud-config helper script to generate a basic
cloud-init seed image:

$ ./contrib/generate-cloud-config-seed.sh ~/.ssh/id_rsa.pub

If the image is running freebsd, use the script with `-freebsd` suffix:
$ vmctl -c nvme.conf run -b
$ vmctl -c nvme.conf ssh --wait

$ ./contrib/generate-cloud-config-seed-freebsd.sh ~/.ssh/id_rsa.pub
**Note**: Customize cloudinit.conf if the defaults don't work for you

This will generate a simple cloud-init seed image that will set up the image
with a default `vmuser` account that can be logged into using the given public
key. Place the output image (`seed.img`) in `img/` and pass the `--cloud-init`
(short: `'-c'`) option to `vmctl run` to initialize the image on first boot:

$ vmctl -c CONFIG run -c

cloud-init will automatically power off the virtual machine when it has been
configured.

**Note**: For the cloud-config helper script to work `cloud-utils` is required.

[cloud-init]: https://cloudinit.readthedocs.io/en/latest/
**Note** Use [archbase][archbase] to build a lean Arch Linux base image

[archbase]: https://github.com/OpenMPDK/archbase
[ubuntu-cloud-image]: https://cloud-images.ubuntu.com

## License

Expand Down
22 changes: 3 additions & 19 deletions cmd/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -euo pipefail
#shellcheck source=common/rc
source "${BASEDIR}/common/rc"

for rc in "${BASEDIR}"/lib/qemu/*; do
for rc in "${BASEDIR}"/lib/*/*; do
#shellcheck disable=SC1090
source "$rc"
done
Expand All @@ -24,7 +24,6 @@ Options:
-k, --kernel-dir DIR directory containing the kernel source. The
directory will be made available to the vm as a 9p
virtfs with mount tag 'kernel_dir'
-c, --cloud-init use '\${VMIMG}/seed.img' as a cloud-init seed
-b, --background start in the background
-g, --gdb launch under gdb
-p, --perf perf record
Expand All @@ -36,8 +35,8 @@ Options:
event with a '-'"

_run() {
local short="k:cd:bnfgpt:h"
local long="kernel-dir:,cloud-init,background,print,reset,gdb,perf,trace:,help"
local short="k:d:bnfgpt:h"
local long="kernel-dir:,background,print,reset,gdb,perf,trace:,help"

if ! tmp=$(getopt -o "$short" --long "$long" -n "$BASENAME" -- "$@"); then
exit 1
Expand All @@ -52,10 +51,6 @@ _run() {
local kernel_dir="$2" ; shift 2
;;

'-c' | '--cloud-init' )
local do_cloud_init=1; shift
;;

'-b' | '--background' )
local do_background=1; shift
;;
Expand Down Expand Up @@ -127,17 +122,6 @@ _run() {
truncate -s 0 "${VMLOG}/${logfile}"
done

if [[ -v do_cloud_init ]]; then
if [[ ! -f "${VMIMG}/seed.img" ]]; then
_fatal 1 "no such file: '${VMIMG}/seed.img'"
fi

qemu_drive_add "cloud-init-seed" \
--file "img/seed.img" \
--format "raw" \
--interface "virtio"
fi

QEMU_PARAMS+=("-pidfile" "${VMROOT}/run/${VMNAME}/pidfile")

if [[ -v kernel_dir ]]; then
Expand Down
45 changes: 0 additions & 45 deletions contrib/generate-cloud-config-seed-freebsd.sh

This file was deleted.

109 changes: 0 additions & 109 deletions contrib/generate-cloud-config-seed.sh

This file was deleted.

71 changes: 0 additions & 71 deletions contrib/systemd/mount-shared-kernel-dir.service

This file was deleted.

Loading