1

I'm trying to boot an ISO containing a Linux live system from an existing NTFS partition on a PC. The PC has UEFI, and the hard disk is partitioned with GPT, so GRUB4DOS is not an option. Can this be done at all?

I know that the question has been asked before: Grub - boot debian iso file from ntfs partition and install it, but there is no approved answers there - that's why I'm asking again. Also I would like to use my own kernel instead of some fixed and precompiled one.

From the other answers it seems like I would need to include some sort of customized kernel file (I assume place it to EFI partition), which is then capable of loading the rest of the ISO(?) from the NTFS itself.

This can be done on FAT partition already, by simply doing a GRUB entry

menuentry "Boot LINUX FROM ISO FILE" {
  set iso_path=/path_to/image_on_FAT_filesystem.iso
  loopback loop (hdX,msdosY)$iso_path
  linux (loop)/path_to/vmlinuz nomagic base_only norootcopy from=$iso_path
}
  • 2
    what Linux Live ISO image you are trying to boot? – Serge Jan 23 at 15:20
  • 1
    @Serge, I don't think that it matters a lot here, but I'm trying to boot Arch linux ISO image. It is also possible for me to customize the image before booting it. – Jussi Hietanen Jan 23 at 16:18
  • 1
    Well, I believe it matters: Fedora uses a specially crafted ISO image which incorporates MBR record at the beginning of the image to support creation of USB bootable stick by simply copying the image onto USB device from the beginning of the device. Also Fedora Live ISO has all necessary parts to support EFI e.t.c. So, I doubt that its boot code would run properly if you put the image somewhere in the middle of the device. – Serge Jan 23 at 16:48
  • 1
    @Serge yes, you are correct, but afaik the EFI partition is made into the ISO for both El Torito (DVD/CD media booting) and the EFI folder booting (bootin from USB). Also GRUB should be able to boot these kind of ISO images by simply setting a loopback option toGRUB boot options. TL;DR: It is possible to load the ISO file from the middle of the device, it can be easily done on FAT partitions. I'm asking help here for NTFS type of partitions. – Jussi Hietanen Jan 23 at 16:54
  • 1
    I have updated the original question so it hopefully describes the question and the problem more clearly – Jussi Hietanen Jan 23 at 17:27
2

So, as a solution;

Background: I'm using Arch Linux. It uses mkinitcpio to generate its initramfs (and the early userspace(!)). Because we are booting a filesystem image from the NTFS, we need to tweak the initramfs. We can use GRUB and its ntfs module to read (GRUB ntfs module is ro afaik.) the kernel and initramfs from the NTFS partition. After this we still need to mount the NTFS partition from the initramfs for full read/write access.

Theory of operation of the solution: I added ntfs-3g and fusefs packages to the initramfs, so that the NTFS partition can be mounted. I also created a new mkinitcpio hook that needs to be loaded before the actual mounting hook. The hook is a simple shell script that gets the parameters (these are given as kernel arguments from GRUB) like

menuentry "Boot LINUX FROM ISO FILE" {
  insmod ntfs
  set root='(hdX,Y)'
  linux /in_ntfs/vmlinuz-linux root=UUID=*GPT_UUID_OF_ROOTFS_ON_DISK_IMAGE* image_path=*path_to_disk_image_on_NTFS* image_hd=*GPT_UUID_OF_NTFS_DISK*
  initrd /in_ntfs/initrd.img
}
  1. Disk image location inside the NTFS partition (image_path)
  2. NTFS partition GPT GUID (image_hd)
  3. If the disk image contains multiple partitions, the rootfs UUID (root)

The boot procedure regarding disk mounts:

  1. initcpio hook mounts the NTFS partition
  2. initcpio hook mounts the disk image from the NTFS partition as a loop device
  3. Now the normal mount hook is run, it is given the ext4 or whatever partition containing linux rootfs inside that disk image mounted in step 2
  4. The system exits the early userspace; newroot is set to the NTFS-loop-mounted image file's rootfs partition.
  5. Ta-dah, we got a running Linux system with read&write permissions running from a disk image/iso image inside a NTFS partition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.