Skip to content
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

Order swap before systemd-fsck-root.service #258

Merged
merged 4 commits into from
Nov 13, 2020

Conversation

marmarek
Copy link
Member

@marmarek marmarek commented Nov 2, 2020

When the fsck is run in the target system, make sure it is started after
enabling swap. In recent Fedora versions, it can also run in initramfs - that
part will be handled in dracut module (linux-utils repository). Here just
ensure the root= parameter is properly set in grub (in case of in-VM kernel use).

Fixes QubesOS/qubes-issues#6174

Grub scripts are very persistent in trying to use what is currently
mounted as /. Even if currently (TemplateVM) /dev/xvda3 is mounted
directly, all the configuration should use /dev/mapper/dmroot, to work
also in AppVM.
GRUB_DEVICE is used in various places as root device (including
constructing root= parameter in some versions). Force it to
/dev/mapper/dmroot

QubesOS/qubes-issues#6174
@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #258 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #258   +/-   ##
=======================================
  Coverage   72.65%   72.65%           
=======================================
  Files           3        3           
  Lines         512      512           
=======================================
  Hits          372      372           
  Misses        140      140           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75ffdf6...05a213a. Read the comment docs.

@qubesos-bot
Copy link

qubesos-bot commented Nov 2, 2020

OpenQA test summary

Complete test suite and dependencies: https://openqa.qubes-os.org/tests/13372#dependencies

Failed tests

New failures

Compared to: https://openqa.qubes-os.org/tests/12774#dependencies

Fixed failures

Compared to: https://openqa.qubes-os.org/tests/12774#dependencies

@marmarek
Copy link
Member Author

marmarek commented Nov 2, 2020

This approach fails miserably - VM no longer boots. This is because there is ordering cycle:

  1. swap.target waits for dev-xvdc1.swap
  2. dev-xvdc1.swap waits for dev-xvdc1.device
  3. dev-xvdc1.device is available only after starting udev
  4. systemd-udevd.service has After=systemd-sysusers.service systemd-hwdb-update.service
  5. Both of the above has After=systemd-remount-fs.service
  6. systemd-remount-fs is (obviously) after fsck

And here the cycle closes.

fsck may require significant amount of RAM, enable swap earlier to avoid
out of memory condition. Implement this as a separate service unit, not
a swap unit, because the latter requires udev running (implicit
dependency on dev-xvdc1.device) which is not the case before remounting
root filesystem read-write.

QubesOS/qubes-issues#6174
We don't have systemd in dom0-provided initrd anymore, so this
workaround is not needed now.

Fixes QubesOS/qubes-issues#5992
@DemiMarie
Copy link
Contributor

DemiMarie commented Nov 3, 2020

We could also spawn the commands used by systemd ourselves, or remove the dev-xvdc1.device dependency in a drop-in file.

@marmarek
Copy link
Member Author

marmarek commented Nov 3, 2020

We could also spawn the commands used by systemd ourselves,

This is exactly what I've done in the force-pushed version.

or remove the dev-xvdc1.device dependency in a drop-in file.

That is unfortunately impossible. Ordering dependencies cannot be removed using drop-in.

Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I really want to encrypt the swap partition.


[Service]
Type=oneshot
ExecStart=-/usr/sbin/swapon /dev/xvdc1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest encrypting the swap partition. We can do this using tools already in the initramfs.

@marmarek
Copy link
Member Author

marmarek commented Nov 3, 2020

VM Swap encryption is a good idea, yes. But there are two options:

I'd like to avoid two layers of encryption, especially for swap that should be fast.

fi
if cmp --bytes $private_size "$dev" /dev/zero >/dev/null && { blkid -p "$dev" >/dev/null; [ $? -eq 2 ]; }; then
# check if private.img (xvdb) is empty
if { blkid -p "$dev" >/dev/null; [ $? -eq 2 ]; }; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems potentially dangerous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice we are looking for a filesystem we create ourselves, and ext4 is perfectly detected (-p makes blkid really read the device, not use cache). But also, blkid detects tens of filesystems, including quite exotic ones. Do you have some specific scenario in mind that would fail this? Perhaps compare first 10MB to /dev/zero with an assumption that any kind of FS signature would be there, even if not recognized by blkid?

Reading first 1GB on every DispVM startup is something I'd really like to avoid, as those need to start fast, ideally under 1s (we're quite far from there). But also speeding up fresh VM startup is desirable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing the first 10MB is fine.

Check just 10 MiB of the private volume + blkid before considering it
empty and calling mkfs. Avoid reading 1GB of data at the VM boot -
which should speed up startup even further, especially for fresh
DispVMs.

QubesOS/qubes-issues#3758
Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HVM is significantly slower than PVH (Xen 4.14)
3 participants