The goal is to have an iso image that boots when the PC starts.

some software to generate a bootable iso image:

  1. dd: A command line tool used to write an ISO image to a USB on macOS.
  2. Disk Utility: A tool built into macOS used to create and manage disks and partitions, including creating bootable USBs.

GRUB configuration is done through a configuration file called grub.cfg. This file is located in the /boot/grub directory on most Linux systems.

boot is 2 directories higher than the user folder

To make the ISO image of a C executable bootable, you need to add a bootloader like GRUB

You need:

  • The mkisofs or genisoimage tool to create the ISO image
  • The grub-install tool to install GRUB on the ISO image

Yes, to make a bootable ISO image, you need to create an ISO file that contains the operating system or application you want to boot, and you also need to include a bootloader such as GRUB.

Create a GRUB configuration file: Create a GRUB configuration file named grub.cfg in the working directory. This file should contain the GRUB configuration for loading the operating system or application.

  • boot/grub/i386-pc/core.img is the GRUB boot file.
  • boot/grub/grub.cfg is the GRUB configuration file.

iso/

|– boot/

|   |– grub/

|   |   |– i386-pc/

|   |   |   |– core.img

|   |   |– grub.cfg

|– executable

Where:

  • iso/: Is the root directory of the ISO.
  • boot/: Is the directory containing the GRUB boot files.
  • boot/grub/: Is the directory containing the GRUB configuration files.
  • boot/grub/i386-pc/: Is the directory containing the GRUB boot files for the i386-pc architecture.
  • boot/grub/i386-pc/core.img: Is the GRUB boot file.
  • boot/grub/grub.cfg: Is the GRUB configuration file.
  • executable: Is the C executable to be booted and run.

Contents of grub.cfg:

menuentry 'My executable' 
{
set root=(hd0,0)
linux/executable
}

Where:

  • menuentry ‘My executable’: This is the GRUB menu entry to be used to boot the executable.
  • set root=(hd0,0): Sets the boot device to the primary hard drive (hd0,0).
  • linux /executable: Loads the C executable from the root of the boot device.

Command to create the ISO:

mkisofs -o mi_iso.iso -b boot/grub/i386-pc/core.img -c boot/grub/grub.cfg -R -J -V "Mi ISO" iso/

Where:

  • my_iso.iso: Is the name of the ISO to be created.
  • boot/grub/i386-pc/core.img: Is the GRUB boot file.
  • boot/grub/grub.cfg: Is the GRUB configuration file.
  • iso/: Is the root directory of the ISO.
  • -R and -J are options that allow you to create an ISO that is compatible with most operating systems.
  • -V is the option that allows you to specify the volume name of the ISO.

The core.img file is a GRUB boot file that is used to load the GRUB kernel and allow the system to boot.

To get the core.img file, you need to install GRUB on your system and then copy the core.img file from the GRUB installation directory.

sudo apt-get install grub-pc 

The GRUB installation directory is usually /usr/lib/grub/i386-pc

Copy the core.img file: Copy the core.img file from the GRUB installation directory to the iso/boot/grub/i386-pc directory of your project.

sudo cp /usr/lib/grub/i386-pc/core.img iso/boot/grub/i386-pc/

The core.img file is specific to the i386-pc architecture, so if you are using a different architecture, you must use the corresponding core.img file.

If you have the ISO on a USB, you must configure the grub.cfg file so that GRUB can find and load the kernel and initrd from the ISO on the USB.

menuentry 'My executable' 
{
set root=(hd0,0)
linux (hd0,0)/executable
boot
}
  • menuentry ‘My executable’: This is the GRUB menu entry to be used to load the executable.
  • set root=(hd0,0): Sets the boot device to the USB (hd0,0).
  • linux (hd0,0)/executable: Loads the executable from the ISO on the USB.
  • boot: Starts the boot process.

You must replace (hd0,0) with the correct USB location on your system.

  • (hd0,0): This refers to the first storage device (in this case, the USB) and the first partition (in this case, the root partition of the USB).
  • (hd1,0): This refers to the second storage device (in this case, the USB) and the first partition (in this case, the root partition of the USB).
  • (usb0,0): This refers to the first USB device and the first partition (in this case, the root partition of the USB).

To determine the correct location of the USB, you can use the lsblk or fdisk -l command to view the list of storage devices and partitions on your system.

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT

sda      8:0    0 465.8G  0 disk 

└─sda1   8:1    0 465.8G  0 part /

sdb      8:16   1  14.5G  0 disk 

└─sdb1   8:17   1  14.5G  0 part /media/usb

In this example, the USB is connected as /dev/sdb and the root partition of the USB is mounted on /media/usb. Therefore, the correct location of the USB would be (hd1,0).

The GRUB screen you’re seeing probably looks something like this:

GNU GRUB  version 2.04

Ubuntu 20.04 LTS (20.04)

Ubuntu 20.04 LTS (20.04) (recovery mode)

Windows 10 (on /dev/sda1)

macOS does not use GRUB as a bootloader, but instead uses a bootloader called boot.efi

If you want to install Linux on a Mac machine, you may need to use a bootloader such as GRUB or rEFInd to load the Linux kernel.

Windows uses a bootloader called BOOTMGR (Boot Manager) in Windows Vista and later versions. BOOTMGR is responsible for loading the Windows kernel and operating system into RAM.

In earlier versions of Windows, such as Windows XP and Windows 2000, a bootloader called NTLDR (NT Loader) was used. NTLDR was responsible for loading the Windows kernel and operating system into RAM.

Bootloaders you can freely use:

  • GRUB (GRand Unified Bootloader): It is an open source bootloader that is commonly used on Linux systems.
  • rEFInd: It is an open source bootloader that is commonly used on Mac machines to load Linux and other operating systems.
  • LILO (LInux LOader): It is an open source bootloader that is commonly used on Linux systems.
  • Syslinux: It is an open source bootloader that is commonly used on Linux systems.
  • OpenBoot: It is an open source bootloader that is commonly used on Linux systems.

These bootloaders are open source, meaning you can freely use, modify, and distribute them.

You don’t have to pay anything to use the bootloader.

licenses for previous bootloaders: