Skip to content

run.py: Add --overlay-rwdir flag #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ For script support, you need CONFIG_VIRTIO_CONSOLE.

For disk support, you need CONFIG_SCSI_VIRTIO.

For --overlay-rwdir support, you need CONFIG_OVERLAY_FS.

That kernel needs to be sane. Your kernel is probably sane, but allmodconfig and allyesconfig generate insane kernels. Sanity includes:

CONFIG_CMDLINE_OVERRIDE=n
Expand Down
9 changes: 9 additions & 0 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def make_parser() -> argparse.ArgumentParser:
g.add_argument('--rodir', action='append', default=[],
help="Supply a read-only directory to the guest. Use --rodir=path or --rodir=guestpath=hostpath.")

g.add_argument('--overlay-rwdir', action='append', default=[],
help="Supply a directory that is r/w to the guest but read-only in the host. Use --overlay-rwdir=path.")

return parser

_ARGPARSER = make_parser()
Expand Down Expand Up @@ -292,6 +295,9 @@ def do_it() -> int:

config = mkinitramfs.Config()

if len(args.overlay_rwdir) > 0:
virtmods.MODALIASES.append('overlay')

kernel = find_kernel_and_mods(arch, args)
config.modfiles = kernel.modfiles
if config.modfiles:
Expand Down Expand Up @@ -357,6 +363,9 @@ def do_it() -> int:
export_virtfs(qemu, arch, qemuargs, hostpath, tag, readonly=(dirtype != 'rwdir'))
kernelargs.append('virtme_initmount%d=%s' % (idx, guestpath))

for i, d in enumerate(args.overlay_rwdir):
kernelargs.append('virtme_rw_overlay%d=%s' % (i, d))

# Turn on KVM if available
if is_native:
qemuargs.extend(['-machine', 'accel=kvm:tcg'])
Expand Down
10 changes: 10 additions & 0 deletions virtme/guest/virtme-init
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ if ! findmnt --kernel --mountpoint /dev &>/dev/null; then
fi
fi

for tag in "${!virtme_rw_overlay@}"; do
td=`mktemp -d`
dir="${!tag}"
mount -t tmpfs none "$td"
mkdir "$td/cow" "$td/work"
mount -t overlay -o "lowerdir=$dir,upperdir=$td/cow,workdir=$td/work" cow "$dir"
umount "$td"
rmdir "$td"
done

for tag in "${!virtme_initmount@}"; do
if [[ ! -d "${!tag}" ]]; then
mkdir -p "${!tag}"
Expand Down