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

initrd/etc/functions: Refine list_usb_storage logic to enable booting from a USB device with an isohybrid-created image #1540

Closed
wants to merge 2 commits into from

Conversation

P5vc
Copy link

@P5vc P5vc commented Nov 27, 2023

This pull request modifies the list_usb_storage function within /initrd/etc/functions with the primary goal of correcting a bug that prevents a user from booting from certain USB media.

For example, here's a post from the Qubes OS forum of users encountering this bug, and here's an article outlining, in depth, the root cause of this issue.

In addition to correcting the aforementioned bug, this pull request takes advantage of having to rewrite a chunk of the core logic anyways, to:

  • Generalize the fat32 workaround to apply to theoretically any filesystem causing the same type of error
  • Simplify some of the logic to better-conform to the POSIX standard, and remove dependence on more-complex utilities (such as sed and awk), when simpler utilities will do the trick
  • Standardize some of the terminology; different parts of the function used different terms when referring to the USB block storage devices (such as "devices", "disks", "drives", etc.)
  • Write additional comments/descriptions to better-document the purpose of each utility. This should be especially helpful given the long chain of piped output found in this function

As a final note, you may notice that main addition to the pre-existing logic was to add a mount test for all detected USB block storage devices (but not for their partitions). Although perhaps not the prettiest way to address this issue, I was unfortunately unable to find a better solution within the confines of the busybox environment. For example, I initially attempted to simply add logic looking for the ISO 9660 filesystem on the block devices, however utilities that can easily do this on most systems (such as blkid), do not support this functionality in their busybox versions. In fact, the only busybox utility I could find with this functionality was mount. Therefore, this pull request could theoretically be modified to add the -t iso9660 option to the mount command, and as a result only end up mounting (and including) devices with the ISO 9660 filesystem (fixing the specific error from the links above). However, adding this option would not significantly impact efficiency (at least it didn't during my limited testing), and may unnecessarily limit the fix by making it overly-specific to the above issues. That being said, if you think that adding this option is preferred, or if you know of a better approach that doesn't require using mount, please let me know!

@tlaurion
Copy link
Collaborator

New requirement from linuxboot org: commits need to be --sign-off

Sorry about that @P5vc . Reading from phone will check code tomorrow

@tlaurion
Copy link
Collaborator

tlaurion commented Nov 28, 2023

@P5vc testing https://app.circleci.com/pipelines/github/linuxboot/heads/701/workflows/90e1bf0d-f35a-43fe-ae46-f1c9975a7b73/jobs/13647 's https://output.circle-artifacts.com/output/job/521ebb13-af2b-469e-8eed-31954831d3dc/artifacts/0/build/x86/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.0-1919-g73c790e.zip against Q4.2 rc5 dd'ed to usb thumb drive. Will edit with results and comment on code afterward.

Note that I never use dd'ed iso to dedicated usb thumb drive or dvd anymore.
I prefer to detach sign isos with my key after having verified their integrity once, and then attest of their state by detach-signing them. This permits to use and reuse a single USB thumb drive with plenty of ISOs that I just need to replace when a new version is released instead of keeping individual thumb drives per installation method. That is also what Heads is for, while Qubes, Tails, Archlinux are detached signed and can be verified automatically by heads when distro.iso is sitting side by side with distro.asc or distro.sig per distribution detach-signing preference against distro public key fused in rom.

It boots successfully:

  • Q4.2 rc5 dd'ed (usb-init)
  • tails 5.19.1 dd'ed (usb-init)
  • media-scan /dev/sdb1 where I hold my detached signed isos, booting Q4.2 rc5 iso+iso.asc

Enabling debug+tracing through config option. Redoing:

  • Q4.2 rc5 dd'ed (usb-init)
  • tails 5.19.1 dd'ed (usb-init)
  • media-scan /dev/sdb1 where I hold my detached signed isos, booting Q4.2 rc5 iso+iso.asc

tlaurion
tlaurion previously approved these changes Nov 28, 2023
Copy link
Collaborator

@tlaurion tlaurion left a comment

Choose a reason for hiding this comment

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

@P5vc I love what I see. @JonathonHall-Purism : veto?

@P5vc
Copy link
Author

P5vc commented Nov 28, 2023

New requirement from linuxboot org: commits need to be --sign-off

Sorry about that @P5vc . Reading from phone will check code tomorrow

@tlaurion No worries! Would you like me to force push signed versions of those commits? If so, I don't mind, just let me know!


testing... against Q4.2 rc5 dd'ed to usb thumb drive.

Just a heads up, it appears that the Qubes OS devs reverted the switch to using isohybrid just before Qubes OS 4.2 Release Candidate 5 was built, in response to this issue. Therefore, using one of the two previous RC builds (Qubes-R4.2.0-rc3-x86_64.iso or Qubes-R4.2.0-rc4-x86_64.iso) may be a better test of the bug fix. 👍


I prefer to detach sign isos with my key after having verified their integrity once, and then attest of their state by detach-signing them. This permits to use and reuse a single USB thumb drive with plenty of ISOs that I just need to replace when a new version is released instead of keeping individual thumb drives per installation method.

This is objectively a much better method that I will certainly need to start using more often!! Thanks for the tip!

@tlaurion
Copy link
Collaborator

tlaurion commented Nov 28, 2023

Well I'm happy regression tests worked. Can do one last test with older release on test laptop.

  • test q4.2 rc4

@P5vc yes please sign-off. Info is availle under failed test

@tlaurion tlaurion dismissed their stale review November 28, 2023 03:12

To have in under matrix

@tlaurion tlaurion self-requested a review November 28, 2023 03:14
P5vc added 2 commits November 28, 2023 00:21
… function

Main changes to the list_usb_storage function include:
  - Modifying the logic to include in its output block devices that have filesystems written directly to them. This is primarily designed fix a bug preventing some bootable media (such as those with an isohybrid-created image written to them) from being included in the USB boot options
  - Simplifying some of the logic to better-conform to the POSIX standard, and remove dependence on more-complex utilities (such as sed and awk), when simpler utilities will do the trick
  - Adding comments to better-document the purpose of each command; especially helpful given the long chain of piped output

Signed-off-by: Priveasy Admin <[email protected]>
@P5vc P5vc force-pushed the isohybrid-boot-fix branch from 73c790e to 91b1191 Compare November 28, 2023 05:31
@P5vc
Copy link
Author

P5vc commented Nov 28, 2023

The commits have been signed off on, as requested!

@JonathonHall-Purism
Copy link
Collaborator

@P5vc Thanks a lot for the cleanup and consistency, and for identifying the problem here. Thanks also for the context from Qubes.

TL;DR - Unfortunately, using the device iso9660 filesystem creates problems for a number of install media I tried today. I do not think it is correct to boot isohybrid from flash media using the device iso9660 filesystem, we should use the partition table - that's the entire reason isohybrid exists, otherwise it would not exist and we'd just use iso9660 everywhere.

The real issue here was that Qubes 4.2 RC media had a broken partition table, as mentioned in the linked change reverting it. Using the device iso9660 filesystem was a workaround to ignore the broken partition table. They've fixed it, so we should not do this.

The cleanup is great though, I would like to merge that. Below I listed the problems I ran into, so if we can revert the behavior of allowing the device to mount when partitions exist, this would be a great improvement.

I liked the idea of doing a test mount of the device to see if it contains a filesystem, the test before was a bit fragile. However, since we need to favor the partitions if both exist, I don't think we can go that direction.

Images offering both disk and partitions

Several images that used to offer two partition choices now offer both the disk itself and the partitions: memtest86+ GRUB, Debian 12 netinstall, PureOS byzantium Plasma, Debian 11 GNOME live, Librem EC update ISO. That makes the partition selection more complex. In a few cases it used to be able to select the partition automatically.

Old remnant ISO9660 found

I have one flash drive in particular that behaves strangely with this change. It has a GPT partition table, one ext4 partition, and that partition contains a bunch of ISOs I use to test Heads/PureBoot. Current master works fine, finds the partition automatically and asks to select an ISO.

Strangely, with the MR it now finds remnants of an old iso9660 filesystem and mounts that automatically - it doesn't even offer me a choice between that or the legitimate ext4 partition. Apparently I had a Fedora 36 image on this at one point, because those are the boot options I get. I don't think we can blame the partitioning here, we can't require zeroing the entire disk to repartition it.

Restricting the device mount to iso9660 won't solve this (tried it, that's what it's finding).

test_mntpt='/tmp/direct-mount-test'
mkdir -p "$test_mntpt"
blkdev_included='false'
if mount -r "$blkdev" "$test_mntpt" >/dev/null 2>/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Per my other comment, we need to go back to the strategy of checking if the device has a partition table first, and using only the partitions if it does.

I liked the idea of doing a mount test - maybe we could apply that to the partitions or to unpartitioned media in the future - but since it can apparently find remnant filesystems after repartitioning I don't think we can go this route.

@P5vc
Copy link
Author

P5vc commented Nov 29, 2023

@JonathonHall-Purism Thank you so much for the feedback! I spent the latter half of my day tweaking these commits per your comments, and then conducting extensive testing. I also managed to go down an embarrassing number of rabbit holes in the process, but hey, it made for a fascinating and educational day! :) I should hopefully be ready to push these new changes in the next couple of days, schedule permitting, and will likely have a couple of follow up questions for you as well. Thanks again!

@tlaurion
Copy link
Collaborator

tlaurion commented Nov 30, 2023

Main question on my side is: what other OS is doing hybrid ISOs that would not boot from heads if user guided into detach signing them.

That would be #1438 (comment) instead.

The reasoning being: should ISOs dd'ed or prepared by external tools be deprecated and replaced by booting ISOs that don't show the bug in question? Is supporting raw iso over USB thumb drive simply a need of users not aware that booting from ISOs is better and would be improved by Heads trying to find iso.asc iso.sig for same iso and if not found, prompt user to verify sha256sum once and then detach sign that iso? And support checksum mechanisms and signing that are done from other distributions today? Maybe that is where the time should be invested instead?

@JonathonHall-Purism
Copy link
Collaborator

should ISOs dd'ed or prepared by external tools be deprecated and replaced by booting ISOs that don't show the bug in question?

No! Practically all instructions for installing any Linux distribution tell users to prepare a bootable USB flash drive this way. It's great to support additional means, but if that most common method does not work in Heads, it will bring a lot of pain to users.

IMO, we should work toward closing the gap between "things that boot with BIOS/UEFI" and "things that boot with Heads", not widening it.

Copy link
Collaborator

@tlaurion tlaurion left a comment

Choose a reason for hiding this comment

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

@P5vc
Copy link
Author

P5vc commented Apr 27, 2024

@tlaurion I'll go ahead and close this pull request. The original premise was mistaken, and although I ended up making some good changes, I got wrapped up in a bunch of other projects and haven't had a chance to revisit that work and update this pull request accordingly. In any event, those changes would probably be more appropriate to propose in separate pull requests. Thank you both again for your feedback and suggestions!

@P5vc P5vc closed this Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants