WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Some UEFI questions  (Read 5846 times)

Offline cv007

  • Newbie
  • *
  • Posts: 13
Some UEFI questions
« on: September 14, 2015, 10:13:48 PM »
-current setup-
vmlinuz + core.gz (stripped of uneeded files) - total ~5MB
(only running text console app)
using isohybrid to create an iso that I can either create a bootable cd, or dd to a flash drive
(syslinux/isolinux)

this boots into a pc one time only, for a simple purpose (on Windows 2000 to Windows 10 pc's)
works fine for now, but want to be able to boot a UEFI pc if needed in the future
(although if CSM is available it will be simpler to just use that temporarily, as in any case secure boot needs to be disabled also)

-goal-
combine current setup to get bootable cd or bootable usb flash drive to boot 'any' pc (UEFI 32bit/64bit or BIOS)

-what I have tried-
I can boot vmlinux64 (on a UEFI 64bit pc) from a flash drive using syslinux efi boot loader, but get native video resolution (instead of 800x600x16)
(same core.gz, except I need the 64bit modules, I only use 2)


-uefi questions-
if I want to support both uefi32 and uefi64, it appears I need 2 kernels- is there any way to boot a 32bit kernel from a 64bit uefi? (so I only need one 32bit kernel)
from what I have read, it seems booting a 64bit kernel from a 32bit uefi is now possible, but nobody talks about the reverse (32bit kernel from 64bit UEFI)

is there a way to get the linux kernel to switch to a graphic mode similar to what I have in my current setup? (800x600x16 via vga= commandline option)



Thanks for any pointers.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
Re: Some UEFI questions
« Reply #1 on: September 15, 2015, 03:03:15 AM »
I'm not sure if you're aware, but since v6.2 the TinyCorePure64.iso has been legacy-bios/(u)efi multi-boot - i.e. if you burn it to cd/dvd, it will boot on either bios or uefi.

I haven't seen anything about booting 32-bit uefi from a 64-bit kernel.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Some UEFI questions
« Reply #2 on: September 15, 2015, 03:54:23 AM »
The kernel will prefer the EFI native FB over any resolution you give, I doubt there's a way around that without recompiling the kernel without efifb (may also need code changes).
The only barriers that can stop you are the ones you create yourself.

Offline Alatun

  • Newbie
  • *
  • Posts: 41
Re: Some UEFI questions
« Reply #3 on: September 15, 2015, 04:31:01 AM »
Regarding UEFI. There is an UEFI firmware in the flash memory of your mainboard. This UEFI firmware can be 32 or 64 bit. I think nearly all recent mainboards are running a 64 bit UEFI firmware . (EFI is actually nearly 17 years old, at that time not that much systems were 64 bit, so older mainboards may have 32 bit firmware) When you install an UEFI boot loader (i.e. grub2) the bitness of the boot loader must match the bitness of the UEFI firmware .

The boot loader however can boot any OS (any bitness). I've installed 64-bit grub2 booting a 32-bit Tinycore. I took the 64 bit grub2 files and copied them to the ESP partition.

Code: [Select]
>EFI
  >Boot
    BOOTX64.EFI   (the 64 bit grub2 loader)
    >grub
       grub2.cfg    (grub config)
    >x86_64-efi     (grub EFI modules)

I was using EasyUEFI (a Windows Tool) to create an UEFI boot configuration in the NVRAM (which only points to the BOOTX64.EFI file).

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
Re: Some UEFI questions
« Reply #4 on: September 15, 2015, 06:23:55 AM »
I just revisited my uefi boot usb stick and indeed, with a 64-bit grub2 installation and 64-bit uefi firmware, I can boot both 32-bit and 64-bit tinycore.

I'm not sure how I missed that up until now, but it's good to know  :)

The one minor problem with uefi boot from a usb stick is that it is not easy to share files with windows machines, windows having decided that a usb stick formatted with gpt can only have one partition, when of course it can have many  :(

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
Re: Some UEFI questions
« Reply #5 on: September 15, 2015, 10:14:29 AM »
..so, to go back to your original question, I guess you could re-master the TinyCorePure64.iso - add core, remove corepure64, remove the extensions (if you're booting to the console), edit grub.cfg, edit isolinux.cfg - and end up with something +/- 15mb that, when burnt to cd/dvd would boot uefi or legacy bios 32-bit.

You'd need a command something like this to re-pack the iso:
Code: [Select]
$ sudo mkisofs -pad -l -r -J -V TinyCorePure64 -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -hide-rr-moved -eltorito-alt-boot -eltorito-platform efi -b EFI/BOOT/efiboot.img -no-emul-boot -o TinyCorePure64.iso iso
Edit: and I also read somewhere:
Quote
A disk can have both an ESP and a BIOS Boot Partition. The latter is used only by GRUB, so a disk can be bootable in both EFI and BIOS even without the latter, depending on what boot loader is used
..but I did not try this.
« Last Edit: September 15, 2015, 11:46:18 AM by Juanito »

Offline cv007

  • Newbie
  • *
  • Posts: 13
Re: Some UEFI questions
« Reply #6 on: September 15, 2015, 01:53:21 PM »
Thanks.

I'll have to look at grub efi if it can load 32bit kernel from its 64bit efi. I'll also have to deal with the video resolution somehow. The program I run has a text ui (mostly text, some lines, one write directly to the framebuffer for my 'splash' screen), and I check the console dimensions and adjust accordingly, but with uefi I end up with way too much space and it looks a little silly. (Although I guess I could just center what I have into the middle of the screen instead of adjusting/fitting to actual console resolution).

I'll describe what I currently do to be a little clearer-
download vmlinuz, core.gz (from x86/release/distribution_files/)
extract core.gz, remove lots of stuff, change some  files, create my own init, add a program, etc. (all scripted)
(at this point I get a kernel, root fs, busybox, some libraries, a couple modules- without having to compile it myself- this is about the only distro I can figure out whats going on from start to finish)
now pack my core files back up to core.gz
use mkisofs to create an iso (using isolinux.bin, config file, ldlinux.c32)
use isohybrid to make it usable as both an iso or a dd image to flash

At this point I'm really good to go, and have booted many pc's (usually using flash drive, unless an old pc that doesn't boot usb, then I use cd). With Windows 8+ pc's, I have to turn off secure boot and enable csm, boot my drive, do my thing, put settings back. If I get uefi booting to work, I still have to disable secure boot, but don't have to also find out where they hid the csm settings (I have also seen pc's where they 'forgot' to put in the csm option, requiring a firmware update).

other notes-
uefi can boot the kernel directly (same bitness only it seems), but it is not of much use unless you also pack initramfs inside the kernel, as you are then booting the kernel with no commandline options

syslinux efi, from what I can gather, will only boot same bitness kernels (if I'm reading its source code correctly- it takes me a week of studying to understand what's going on, and only a day or two to forget what I figured out)

I'll have to get a uefi firmware for qemu so I can try some more things without actual uefi hardware

Offline cv007

  • Newbie
  • *
  • Posts: 13
Re: Some UEFI questions
« Reply #7 on: September 16, 2015, 09:27:38 PM »
update (in case anyone is interested)

as mentioned by Alatun, grub2 can boot a 32bit kernel from its 64bit efi loader (but syslinux cannot- it needs kernel/uefi bitness to match)

I created a fat32 formatted flash drive, setup these files/folders-
\efi\boot\bootx64.efi  (grub 64bit efi )
\efi\boot\bootia32.efi  (grub 32bit ef ) (not tested, but assume it will work)
\boot\grub\grub.cfg (minimal grub config)
\vmlinuz (32bit)
\core.gz

test pc- HP business pc with uefi booting enabled, legacy boot disabled, secure boot disabled
it will boot up the 32bit kernel just fine, and for some reason I'm getting 800x600x16 as requested from kernel commandline  (1024x768 lcd monitor)

now I just have to sort it all out- getting it all combined into one hybrid iso

Offline cv007

  • Newbie
  • *
  • Posts: 13
Re: Some UEFI questions
« Reply #8 on: September 20, 2015, 09:28:04 PM »
Here is my final summary to close this question. It could use more tweaking, and there are other ways I would like to try, but this is currently working. I'm sure grub could replace the isolinux part , but I already had isolinux working so only added grub for uefi (as syslinux would not boot a 32bit kernel from its 64bit efi).

--temp folder for all iso files needed (tmp)
  vmlinuz (32bit)
  core.gz
  ldlinux.c32 (syslinux 6.03)
  isolinux.bin (syslinux 6.03)
  isolinux.cfg (see below)
  efi.img (see below)
  boot/grub/grub.cfg (see below)

--efi.img (floppy image file for uefi use)
  efi/boot/bootx64.efi  (grub)
  efi/boot/bootia32.efi  (grub)
  boot/grub/grub.cfg (see below)

--isolinux.cfg start--
  DEFAULT TEST
  LABEL TEST
  KERNEL /vmlinuz
  INITRD /core.gz
  APPEND loglevel=2 vga=788 logo.nologo
--isolinux.cfg end--

--grub.cfg start--
  set default=0
  set timeout=0

  menuentry "TEST" {
    search --file --no-floppy --set=root /vmlinuz
   linux   ($root)/vmlinuz loglevel=2 vga=788 logo.nologo
   initrd   ($root)/core.gz
  }
--grub.cfg end--

--create iso (mkisofs is genisoimage on my system)
  mkisofs -l -J -R \
  -V TEST \
  -o test.iso \
  -b isolinux.bin \
  -c boot.cat \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  -eltorito-alt-boot \
  -e efi.img \
  -no-emul-boot \
  tmp

--iso hybrid
  isohybrid -u test.iso

notes:
  -can boot cd either via bios or uefi
  -iso dd'd to usb flash drive, can boot via bios or uefi
  -syslinux 6.03 needed
  (6.02 would not boot bios cd on my test pc)
  -I put all files in root folder of iso if possible
  -grub config file needed in both the efi image file and in iso
  (could be optimized if I could create my own grub efi files)
  -grub efi files were grabbed somewhere off the internet
  (which seem to have most mod files, and are larger than I need)

  -booting from cd via bios-
   isolinux.bin bootloader runs
  -booting from cd via uefi-
   uefi firmware sees efi image as system partition,
   finds/loads bootx64.efi or bootia32.efi
  -booting from usb flash drive via bios-
   mbr code (isohybrid created) finds/runs isolinux.bin
  -booting from usb flash drive via uefi-
   uefi firmware sees mbr partition info, sees system partition,
   (points to efi image) finds/loads bootx64.efi or bootia32.efi