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

Rework iso boot: Use only grub2 and make it easer to add boot menu items #83585

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkg20001
Copy link
Member

@mkg20001 mkg20001 commented Mar 28, 2020

Motivation for this change

Using two bootloaders isn't really a good idea, let's focus on just one

I found this https://willhaley.com/blog/custom-debian-live-environment/ which uses grub for all boot-related things and re-implemented the current boot-process using that

Additionally currently there seems to be a script to create a custom EFI boot image, etc

I've removed that all and it's now only creating a small boot image and loading the rest from the ISO, otherwise this causes havoc with some things such as my own ISO (which is 4gb) being detected as some odd 67mb thing and just launching an empty grub prompt on UEFI

Also that's an opportunity to re-style the grub image


Additionally I added "boot.persistence". It's a kernel parameter that allows replacing the ISO's tmpfs which gets mounted on / with a physical device, so one can boot from an ISO and use it like a normal OS (everything except the store is persistent) Seperated into #83911

And I made it easier to add custom boot items


Currently booting shows a bunch of errors, I'll fix those one error about echo, which is because we're using modloading to check if echo exists, otherwise it changes prefix to /boot and tries to load modules from there. but it's not a fatal error

Additionally history is a mess, I'll get to that later aswell Rebased

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@mkg20001
Copy link
Member Author

Here's a script to test it: https://gist.github.com/mkg20001/6d8a607a28131176fb6ed3b94c282c71

--target=i386-pc \
--boot-directory=$PWD/append/boot \
--no-bootsector \
--skip-fs-probe \
Copy link
Member Author

Choose a reason for hiding this comment

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

this doesn't do it's job properly. would need to fix this, possibly upstream patch

--efi-directory=$PWD/append/EFI \
--boot-directory=$PWD/append/boot \
--no-nvram \
--skip-fs-probe \
Copy link
Member Author

Choose a reason for hiding this comment

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

same as above

Copy link
Member Author

Choose a reason for hiding this comment

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

don't know if this is needed, since all modules are in the efi image (added some code to make detection dynamic)
but dunno if later other archs might have similar problems as MBR with image size limit.... I guess no, we'll see later then

@mkg20001 mkg20001 force-pushed the rework-boot branch 2 times, most recently from 3af8d07 to 5185eb1 Compare March 29, 2020 09:13
#if test -n "$usbBootable"; then
# echo "Making image hybrid..."
# if test -n "$efiBootable"; then
# isohybrid --uefi $out/iso/$isoName
Copy link
Member Author

Choose a reason for hiding this comment

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

This may or may not be relevant

@mkg20001 mkg20001 changed the title Rework boot: Persistence, throw out isolinux, easier adding boot menu items Rework boot: Use only grub2 and make it easer to add boot menu items Apr 16, 2020
@mkg20001 mkg20001 changed the title Rework boot: Use only grub2 and make it easer to add boot menu items Rework iso boot: Use only grub2 and make it easer to add boot menu items Apr 16, 2020
@mkg20001 mkg20001 force-pushed the rework-boot branch 2 times, most recently from d69350f to e8781d4 Compare April 17, 2020 00:05
@mkg20001 mkg20001 force-pushed the rework-boot branch 2 times, most recently from f3782eb to 0d64291 Compare July 31, 2020 05:48
@asdf8dfafjk
Copy link
Contributor

asdf8dfafjk commented Aug 23, 2020

Hello,

I want to help review this PR for inclusion.

About code review- To tell you a bit about what I do and don't know- I am reasonably familiar with how EFI works in principle, and how MBR works (having written asm code that can boot from MBR and read FAT partition). I'm also reasonably familiar with the workings of grub. I am very unfamiliar with NixOS iso creation stuff, or with bootable CD stuff. My knowledge is thus, limited, but if you're only looking for a second pair of eyes then we can chat on discord and I can read up on stuff that I'm unfamiliar with.

About testing- I can test this PR.

To start:

I did the following to run your iso in qemu (adapted from your instructions)-

git clone --depth=3 https://github.com/mkg20001/nixpkgs -b rework-boot ./nixpkgs
cd nixpkgs
git clone https://gist.github.com/mkg20001/6d8a607a28131176fb6ed3b94c282c71 iso-build
cd iso-build
bash iso.sh
nix-env --install --attr nixos.qemu
bash boot-iso.sh

The first thing I did after launch was to hit c and e, neither of which worked, which makes me suspect that the iso didn't use Grub. Are you sure that everything in here is indeed fully contained?

I want to start by enumerating ways to install Linux from an ISO-

  1. Burn to cd, a) Boot in CSM mode, b) Boot in UEFI mode

  2. dd to USB (https://wiki.archlinux.org/index.php/USB_flash_installation_medium#Using_basic_command_line_utilities) and then booting using a) CSM, b) UEFI

  3. Rufus disk tool

  4. Vbox

  5. ⨯Grub loopback command (my trials last year show this is not supported)

How many of these do you support in your current work? I notice that you have removed all usages of usbBootable. I wonder if you don't intend to support (2) ...

Copy link
Contributor

@misuzu misuzu left a comment

Choose a reason for hiding this comment

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

I tested this change (on top of nixos-unstable @ 24c9b05) on ThinkPad T580 with both Legacy boot only and UEFI only:

  1. installer option works with both modes (made sure that /sys/firmware/efi directory exist on UEFI and does not on Legacy boot), so that's great!
  2. copytoram option doesn't boot on both UEFI and Legacy boot (see https://imgur.com/a/qx1JrDt).
  3. copytoram option boots fine on 24c9b05.

I used nix-build nixos -A config.system.build.isoImage -I nixos-config=nixos/modules/installer/cd-dvd/installation-cd-minimal.nix to build iso image.

@mkg20001
Copy link
Member Author

copytoram option doesn't boot on both UEFI and Legacy boot (see imgur.com/a/qx1JrDt).

there's a "no space left" error so it's possible that the image is a bit bigger and therefore there's not enough ram.

@mkg20001
Copy link
Member Author

mkg20001 commented Oct 20, 2020

Currently I don't really have the time to fix some of the remaining nitpicks in this PR and get the usb-booting stuff re-added and I'd be happy for somebody that would help fix it

@stale
Copy link

stale bot commented Jul 2, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 2, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank marked this pull request as draft March 25, 2024 16:19
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.

None yet

4 participants