snapd icon indicating copy to clipboard operation
snapd copied to clipboard

snap-bootstrap: add scan-disk subcommand

Open valentindavid opened this issue 3 years ago • 9 comments

This command is expected to be called from udev. This creates symlinks /dev/ubuntu/ubuntu-{seed,boot,data,save}.

Then we can bind snap-bootstrap initramfs-mounts to dev-ubuntu-ubuntu-seed.device.

valentindavid avatar Jul 28 '22 15:07 valentindavid

This works with snapcore/core-initrd#107

valentindavid avatar Jul 28 '22 15:07 valentindavid

Would it be possible to get the same information just by running blkid instead of using the library?

We cannot list partitions from blkid.

valentindavid avatar Aug 11 '22 14:08 valentindavid

Given SEED is ESP; and we bind the initramfs-mounts unit to the SEED; i am wondering if we can instead turn on / patch the systemd's gpt-auto-generator which can create esp mount in /efi and use that instead?

Looking more at this, I actually don't quite like the behaviour of gpt-auto-generator. Because the good bits of it are not what we need here.

Ideally we would only read efi_loader_get_device_part_uuid (aka LoaderDevicePartUUID) and generate .device unit for it, and bind initramfs-mounts service unit to it. Before any drives appear.

Thus without waiting udev to exec scan-disk to process them all either.

xnox avatar Aug 15 '22 11:08 xnox

Ideally we would only read efi_loader_get_device_part_uuid (aka LoaderDevicePartUUID) and generate .device unit for it, and bind initramfs-mounts service unit to it. Before any drives appear.

Thus without waiting udev to exec scan-disk to process them all either.

So almost what I have done, but a symlink on the whole disk rather than the partitions?

valentindavid avatar Aug 15 '22 15:08 valentindavid

@valentindavid can the description or some comment in the code include the actual udev rules that this will be used from? it's a bit unclear just from the code how things go from the code in scan-disk to have /dev/ubuntu/disk symlinked?

What's the plan for testing the cmd_scan_disk code?

pedronis avatar Feb 23 '23 19:02 pedronis

@valentindavid can the description or some comment in the code include the actual udev rules that this will be used from? it's a bit unclear just from the code how things go from the code in scan-disk to have /dev/ubuntu/disk symlinked?

Sure. We could even add the rules to snapd and install them into core-initrd.

What's the plan for testing the cmd_scan_disk code?

I think I will need to mock libblkid somehow to test it.

Loop devices need root to be setup, and I do not think there is as this point any nice user land block devices. I think only character devices can be emulated with CUSE. Not block.

valentindavid avatar Feb 23 '23 23:02 valentindavid

What's the plan for testing the cmd_scan_disk code?

I have added tests.

I still have to add tests for the changes in cmd_initramfs_mounts.go (when /dev/ubuntu/disk exists). But that should be straight forward.

valentindavid avatar Mar 03 '23 14:03 valentindavid

Codecov Report

Attention: Patch coverage is 62.35294% with 96 lines in your changes are missing coverage. Please review.

Project coverage is 78.84%. Comparing base (f7fea7f) to head (6ee943e). Report is 44 commits behind head on master.

Files Patch % Lines
cmd/snap-bootstrap/cmd_scan_disk.go 68.42% 46 Missing and 20 partials :warning:
osutil/disks/disks_linux.go 0.00% 12 Missing :warning:
osutil/disks/mockdisk.go 0.00% 12 Missing :warning:
cmd/snap-bootstrap/cmd_initramfs_mounts.go 72.72% 4 Missing and 2 partials :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12006      +/-   ##
==========================================
- Coverage   78.88%   78.84%   -0.04%     
==========================================
  Files        1037     1039       +2     
  Lines      132881   133744     +863     
==========================================
+ Hits       104817   105454     +637     
- Misses      21523    21692     +169     
- Partials     6541     6598      +57     
Flag Coverage Δ
unittests 78.84% <62.35%> (-0.04%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Mar 05 '24 13:03 codecov-commenter