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

PV Grub #1354

Closed
marmarek opened this Issue Oct 23, 2015 · 11 comments

Comments

Projects
None yet
4 participants
@marmarek
Member

marmarek commented Oct 23, 2015

Implement ability to boot VM from the kernel provided by the VM (template) itself. This would greatly ease kernel package management:

  • no need to "blacklist" kernel packages
  • easier to compile kernel modules (use standard instructions, instead of some Qubes specific steps)
  • easier to install non-default modules - possibility to install and use upstream packages directly
  • no more problems with read-only /lib/modules

Required steps:

  • package pvgrub for dom0 (fc20 grub package doesn't contain it)
  • make sure that VM have the right initramfs additions (/dev/mapper/dmroot assembling code) - theoretically dracut module is already available in qubes-kernel-vm-support Fedora package.
  • make sure that the above is actually used on VM kernel package upgrades
  • generate grub configuration in the VM (no need to have grub installed in boot sector, but shouldn't harm)
  • do not mount /lib/modules when the VM kernel is used
  • decide what to do with kernelopts VM setting (ignore in this case? somehow pass to the VM kernel?)
  • write documentation, Qubes Manager support, add to release notes
@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Oct 23, 2015

Member

General idea is to provide PVGRUB as one of "VM kernel" in /var/lib/qubes/vm-kernels. It would require placing pvgrub binary as vmlinuz (handle it somehow better?) and some dummy initramfs and modules.img.

Member

marmarek commented Oct 23, 2015

General idea is to provide PVGRUB as one of "VM kernel" in /var/lib/qubes/vm-kernels. It would require placing pvgrub binary as vmlinuz (handle it somehow better?) and some dummy initramfs and modules.img.

@qubesuser

This comment has been minimized.

Show comment
Hide comment
@qubesuser

qubesuser Oct 23, 2015

Another advantage is that PV VMs can then be booted as an HVM with no changes other than changing the VM type in the libvirt config (as long as normal GRUB is installed).

This is useful for things that Xen only supports on HVM guests like using hardware nested paging for better performance on some workloads, CPUID hiding for anonymity or development purposes and nested virtualization.

decide what to do with kernelopts VM setting (ignore in this case? somehow pass to the VM kernel?)

Could possibly point pvgrub to a config file generated by dom0 and placed in the modules or volatile disk, which would define a GRUB variable with the kernelopts and source the main config file in /boot, which would apply the options as long as the VM has a Qubes package installed that adds a reference to the GRUB variable in the commandline defined in /etc/default/grub. Not sure if it's that useful though.

Another advantage is that PV VMs can then be booted as an HVM with no changes other than changing the VM type in the libvirt config (as long as normal GRUB is installed).

This is useful for things that Xen only supports on HVM guests like using hardware nested paging for better performance on some workloads, CPUID hiding for anonymity or development purposes and nested virtualization.

decide what to do with kernelopts VM setting (ignore in this case? somehow pass to the VM kernel?)

Could possibly point pvgrub to a config file generated by dom0 and placed in the modules or volatile disk, which would define a GRUB variable with the kernelopts and source the main config file in /boot, which would apply the options as long as the VM has a Qubes package installed that adds a reference to the GRUB variable in the commandline defined in /etc/default/grub. Not sure if it's that useful though.

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Oct 24, 2015

Member

Another advantage is that PV VMs can then be booted as an HVM with no changes other than changing the VM type in the libvirt config (as long as normal GRUB is installed).

Yes, this is also an important step. Also because we're going to integrate underlying mechanisms for PV/HVM and for example be able to use HVM NetVM.

BTW We're also considering usage of PVH. Do you know if CPUID hiding is available there?

Could possibly point pvgrub to a config file generated by dom0 and placed in the modules or volatile disk, which would define a GRUB variable with the kernelopts, source the main config file, which would apply the options as long as the VM has a Qubes package installed that adds a reference to the GRUB variable in the commandline defined in /etc/default/grub. Not sure if it's that useful though.

If it is possible to do, yes, this may be an option. Haven't got that far in PV Grub configuration yet. All I know is possibility (requirement?) for config file bundled to PV Grub binary, visible as memdisk, which is (I think) responsible for loading the real config from VM disk. If you can provide some examples, that would be great :)

Member

marmarek commented Oct 24, 2015

Another advantage is that PV VMs can then be booted as an HVM with no changes other than changing the VM type in the libvirt config (as long as normal GRUB is installed).

Yes, this is also an important step. Also because we're going to integrate underlying mechanisms for PV/HVM and for example be able to use HVM NetVM.

BTW We're also considering usage of PVH. Do you know if CPUID hiding is available there?

Could possibly point pvgrub to a config file generated by dom0 and placed in the modules or volatile disk, which would define a GRUB variable with the kernelopts, source the main config file, which would apply the options as long as the VM has a Qubes package installed that adds a reference to the GRUB variable in the commandline defined in /etc/default/grub. Not sure if it's that useful though.

If it is possible to do, yes, this may be an option. Haven't got that far in PV Grub configuration yet. All I know is possibility (requirement?) for config file bundled to PV Grub binary, visible as memdisk, which is (I think) responsible for loading the real config from VM disk. If you can provide some examples, that would be great :)

@qubesuser

This comment has been minimized.

Show comment
Hide comment
@qubesuser

qubesuser Oct 24, 2015

Unfortunately PVH doesn't currently support CPUID hiding and nested virtualization, and in general it seems like it was more of a "quick hack" than a well-designed mechanism.

It seems that to fix that the Xen team has deprecated it favor of "HVMlite", which seems to be a modification of the HVM code to run without a device model but which is not yet ready.

Unfortunately PVH doesn't currently support CPUID hiding and nested virtualization, and in general it seems like it was more of a "quick hack" than a well-designed mechanism.

It seems that to fix that the Xen team has deprecated it favor of "HVMlite", which seems to be a modification of the HVM code to run without a device model but which is not yet ready.

@northox

This comment has been minimized.

Show comment
Hide comment
@northox

northox Nov 6, 2015

Hum, not sure about that last part.

As we are planning to rename HVMlite to PVH, I would avoid the use of HVMlite in committed code.

See http://lists.xenproject.org/archives/html/xen-devel/2015-08/msg01927.html

northox commented Nov 6, 2015

Hum, not sure about that last part.

As we are planning to rename HVMlite to PVH, I would avoid the use of HVMlite in committed code.

See http://lists.xenproject.org/archives/html/xen-devel/2015-08/msg01927.html

marmarek added a commit to QubesOS/qubes-linux-pvgrub2 that referenced this issue Nov 8, 2015

Initial pvgrub2 package - based on grub2 Fedora package
Most important changes:
- remove all Fedora patches
- change version 2.00->2.02~beta2
- remove common files, leave only platform specific
- build for platform 'xen' instead of 'pc'
- remove all subpackages
- remove EFI build
- remove theme, locale and scrips in /etc - clashes with main grub package

QubesOS/qubes-issues#1354
@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Nov 8, 2015

Member

Having VM-provided kernel means that it also must obtain (compile) u2mfn kernel module. Currently it is done using dkms. This means that dkms with all its dependencies (gcc, kernel headers etc) needs to be installed in the VM.
A question: should it be available in minimal template by default? Or another way: should it be required package? @axon-qubes

Member

marmarek commented Nov 8, 2015

Having VM-provided kernel means that it also must obtain (compile) u2mfn kernel module. Currently it is done using dkms. This means that dkms with all its dependencies (gcc, kernel headers etc) needs to be installed in the VM.
A question: should it be available in minimal template by default? Or another way: should it be required package? @axon-qubes

@andrewdavidwong

This comment has been minimized.

Show comment
Hide comment
@andrewdavidwong

andrewdavidwong Nov 8, 2015

Member

Did you mention me by mistake, @marmarek?

Member

andrewdavidwong commented Nov 8, 2015

Did you mention me by mistake, @marmarek?

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Nov 8, 2015

Member

No mistake, you are using minimal templates a lot ;)

Member

marmarek commented Nov 8, 2015

No mistake, you are using minimal templates a lot ;)

@andrewdavidwong

This comment has been minimized.

Show comment
Hide comment
@andrewdavidwong

andrewdavidwong Nov 8, 2015

Member

IIUC, the downsides would be increasing the size of the minimal template (by how much approximately?) and arguably increasing the attack surface(?).

What would the benefit be in the case of the minimal template? Are there many common use-cases where someone would need this in a minimal template?

IMHO, we should err on the side of keeping the minimal template truly "minimal," and let the user install any additional software at her discretion. This seems preferable to requiring users to try to further strip down the minimal template when they need an actually-minimal template.

Member

andrewdavidwong commented Nov 8, 2015

IIUC, the downsides would be increasing the size of the minimal template (by how much approximately?) and arguably increasing the attack surface(?).

What would the benefit be in the case of the minimal template? Are there many common use-cases where someone would need this in a minimal template?

IMHO, we should err on the side of keeping the minimal template truly "minimal," and let the user install any additional software at her discretion. This seems preferable to requiring users to try to further strip down the minimal template when they need an actually-minimal template.

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Nov 8, 2015

Member

Ouch, a lot: 167MB (https://gist.github.com/marmarek/d79382f300331a8f5db2)
Generally it is about ability to use kernel installed in the VM, which makes it easier to update, install additional modules etc.
Anyway I think you're right - minimal should stay minimal, especially given above size.

Member

marmarek commented Nov 8, 2015

Ouch, a lot: 167MB (https://gist.github.com/marmarek/d79382f300331a8f5db2)
Generally it is about ability to use kernel installed in the VM, which makes it easier to update, install additional modules etc.
Anyway I think you're right - minimal should stay minimal, especially given above size.

marmarek added a commit to marmarek/qubes-linux-pvgrub2 that referenced this issue Nov 8, 2015

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

dracut: split 'full' dracut module into 'full-dmroot' and 'full-modules'
When PV Grub will be used, VM initramfs should not contain /lib/modules
mounting code, as the VM root.img will already contains kernel modules.
Make it possible by splitting the module.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

dracut: fix qubes-vm module dependencies
It needs 'dm' for 'dmsetup' utility. Additionally fix check - qubesdb
path starts with '/'.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

dracut: mount only subdirectory of /lib/modules
This makes is possible to modify /lib/modules content - especially
install other kernel packages, without unmounting the whole
/lib/modules. Since dom0-provided modules will no longer conflict with
VM kernel packages (assuming kernel versions are different), there is no
need for qubes-kernel-vm-placeholder anymore.

Having only one subdirectory of /lib/modules mounted is somehow tricky,
because:
1. Directory name isn't always the same - it depends on kernel version.
This means that mountpoint must be created dynamically (so $NEWROOT must
be mounted in R/W for a moment).
2. There is one-command way to mount only a subdirectory of some
filesystem. So use a trick: mount it in some temporary directory, get
interesting subdir with `mount --bind`, then unmount temporary
directory.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

kernel-modules: build/install u2mfn module by default
The module is required by gui-agent, so make sure it will be actually
installed. This would also install the module in dom0 (when
qubes-kernel-vm-support is installed there), but this this is harmless.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

dracut: add dmsetup --noudevsync since we're running in pre-udev hook
When udev is installed (and scheduled to be started), but not running
yet, plain dmsetup will deadlock on waiting for udev. Since we call
`dmsetup mknodes dmroot` anyway

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-linux-utils that referenced this issue Nov 11, 2015

debian: introduce qubes-kernel-vm-support package
This package is responsible for kernel modules and initramfs additions
needed in Qubes VM. When installed, it is possible to switch the VM to
use PV Grub and load the kernel from inside of VM. This greatly ease
installing custom kernel modules.

Changes:
 - make qubes_cow_setup.sh working with both dracut and initramfs-tools
 - add initramfs-tools configuration/scripts (including
         qubes_cow_setup.sh)
 - modify DESTDIR to handle multiple binary packages out of single
   source

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-core-agent-linux that referenced this issue Nov 11, 2015

dracut: disable hostonly mode
Initramfs created in TemplateVM may be used also in AppVMs based on it, so
technically it is different system. Especially it has different devices
mounted (own /rw, own swap etc), so prevent hardcoding UUIDs here.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-core-agent-linux that referenced this issue Nov 11, 2015

Get rid of qubes-core-vm-kernel-placeholder
Since /lib/modules is not mounted read-only anymore (only a selected
subdirectory there), it is no longer required to prevent kernel package
installation. Even more - since PV Grub being supported, it makes sense
to have kernel installed in the VM.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-core-admin that referenced this issue Nov 11, 2015

core: make modules.img optional even for PV
When using PVGrub it doesn't make sense to attach modules.img, since
modules are already in the VM. Initramfs there will already handle such
situation and will not try to mount it, when VM's root filesystem
already contains appropriate /lib/modules/`uname -r`.

On the other hand, error earlier when initramfs is missing. While also
not used by PV Grub, the file is always specified in libvirt config and
when missing libvirt will throw rather cryptic error message.

QubesOS/qubes-issues#1354

marmarek added a commit to QubesOS/qubes-core-admin that referenced this issue Nov 11, 2015

marmarek added a commit to QubesOS/qubes-doc that referenced this issue Nov 12, 2015

marmarek added a commit to marmarek/qubes-builder that referenced this issue Nov 13, 2015

marmarek added a commit to marmarek/qubes-linux-utils that referenced this issue Nov 15, 2015

initramfs: fix swap size
It should be 1GB, not 1MB...

QubesOS/qubes-issues#1354
@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Nov 15, 2015

Member

Done.

Member

marmarek commented Nov 15, 2015

Done.

@marmarek marmarek closed this Nov 15, 2015

marmarek added a commit to marmarek/qubes-linux-pvgrub2 that referenced this issue Nov 29, 2015

Install actual PV GRUB binary as original name
Then create 'vmlinuz' symlink. This way it is much clearer that it isn't
real Linux kernel.

QubesOS/qubes-issues#1354

marmarek added a commit to marmarek/qubes-linux-pvgrub2 that referenced this issue Nov 29, 2015

Split tools into grub2-xen-tools package
Those tools are not needed normally, because all modules are embedded in
pvgrub binary and grub configuration is created inside of VM. Probably
needed only for some power users to embed some additional automation
inside PV GRUB memdisk.

QubesOS/qubes-issues#1354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment