Skip to content

Commit

Permalink
isoutils: Add Rufus ISO image support
Browse files Browse the repository at this point in the history
Rufus in iso image mode creates a new filesystem and copies all files
from the iso onto that filesystem. This broke Clear boot because there
were missing files from the CD root to boot (those files were in
efiboot.img), and because initrd was limited to mounting only ISO files
to find the rootfs.

Now the files from efiboot.img are copied to the ISO root (so that Rufus
will now work), the initrd paths have been made congruent (though there
are two initrd.gz files - one in efiboot.img and one on the ISO root),
and some extraneous systemd files have been removed.

Signed-off-by: Brian J Lovin <[email protected]>
  • Loading branch information
evil-brain authored and mdhorn committed May 8, 2019
1 parent dedda92 commit cb0c9f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
8 changes: 4 additions & 4 deletions iso_templates/initrd_init_template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mount -t tmpfs none /run
shell_trap() {
local msg="$1"
while true; do
echo "<1>Unable to boot Clear Linux." |tee /dev/kmsg
echo "<1>Unable to boot Clear Linux*." |tee /dev/kmsg
echo "<1>FATAL: $msg"|tee /dev/kmsg
sleep 30
done
Expand Down Expand Up @@ -88,7 +88,7 @@ have_64bit_cpu() {
}

#Verify CPU features needed to run Clear exist
echo "<1>Checking if system is capable of running Clear Linux..." |tee /dev/kmsg
echo "<1>Checking if system is capable of running Clear Linux*..." |tee /dev/kmsg
have_64bit_cpu
have_ssse3_cpu_feature
have_sse41_cpu_feature
Expand All @@ -104,7 +104,7 @@ insmod {{.}}
mount_root() {
local installer=${1}
mkdir /mnt/media
mount --read-only -t iso9660 $installer /mnt/media
mount --read-only $installer /mnt/media
rootfsloop=$(losetup -fP --show /mnt/media/images/rootfs.img)
if [ -n "${rootfsloop}" ]; then
mkdir /mnt/rootfs
Expand All @@ -131,7 +131,7 @@ find_and_mount_installer() {
done

if [ $retries -ge 5 ]; then
shell_trap "Failed to find installer media, retries exhausted, failed to boot Clear Linux."
shell_trap "Failed to find installer media, retries exhausted, failed to boot Clear Linux*."
fi
}

Expand Down
4 changes: 2 additions & 2 deletions iso_templates/isolinux.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TIMEOUT 50

LABEL clear
MENU DEFAULT
MENU LABEL Clear Linux OS for Intel Architecture
MENU LABEL Clear Linux* OS
LINUX /kernel/kernel.xz
INITRD /images/initrd.gz
INITRD /EFI/BOOT/initrd.gz
APPEND {{.Options}}
45 changes: 25 additions & 20 deletions isoutils/isoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ func buildInitrdImage() error {
return err
}

args := "sudo find .| cpio -o -H newc | gzip >" + tmpPaths[clrCdroot] + "/images/initrd.gz"
initrdPath := tmpPaths[clrCdroot] + "/EFI/BOOT/"
if _, err := os.Stat(initrdPath); os.IsNotExist(err) {
err = os.MkdirAll(initrdPath, os.ModePerm)
if err != nil {
prg.Failure()
return err
}
}

args := "sudo find .| cpio -o -H newc | gzip >" + initrdPath + "initrd.gz"
_, err = exec.Command("bash", "-c", args).CombinedOutput()
if err != nil {
prg.Failure()
Expand Down Expand Up @@ -288,15 +297,6 @@ func mkEfiBoot() error {
}
}

/* create dirs in new efi img */
if _, err := os.Stat(tmpPaths[clrEfi] + "/EFI/systemd"); os.IsNotExist(err) {
err = os.MkdirAll(tmpPaths[clrEfi]+"/EFI/systemd", os.ModePerm)
if err != nil {
prg.Failure()
return err
}
}

/* Modify loader/entries/Clear-linux-*, add initrd= line and remove ROOT= from kernel command line options */
entriesGlob, err := filepath.Glob(tmpPaths[clrEfi] + "/loader/entries/Clear-linux-*")
if err != nil || len(entriesGlob) != 1 {
Expand Down Expand Up @@ -338,18 +338,20 @@ func mkEfiBoot() error {
return err
}

/* Copy all required files to efiboot.img and finally unmount efiboot.img */
paths := [][]string{
{tmpPaths[clrCdroot] + "/images/initrd.gz", tmpPaths[clrEfi] + "/EFI/Boot/initrd.gz"},
{tmpPaths[clrImgEfi] + "/EFI/BOOT/BOOTX64.EFI", tmpPaths[clrEfi] + "/EFI/systemd/systemd-bootx64.efi"},
/* Copy EFI files to the cdroot for Rufus support */
cpCmd := []string{"cp", "-pr", tmpPaths[clrEfi] + "/.", tmpPaths[clrCdroot]}
err = cmd.RunAndLog(cpCmd...)
if err != nil {
prg.Failure()
return err
}

for _, i := range paths {
err = utils.CopyFile(i[0], i[1])
if err != nil {
prg.Failure()
return err
}
/* Copy initrd to efiboot.img and finally unmount efiboot.img */
initrdPaths := []string{tmpPaths[clrCdroot] + "/EFI/BOOT/initrd.gz", tmpPaths[clrEfi] + "/EFI/BOOT/initrd.gz"}
err = utils.CopyFile(initrdPaths[0], initrdPaths[1])
if err != nil {
prg.Failure()
return err
}

/* Unmount EFI partition here, because this must be unmounted when calling xorriso! */
Expand Down Expand Up @@ -567,13 +569,16 @@ func MakeIso(rootDir string, imgName string, model *model.SystemInstall, options
if err = buildInitrdImage(); err != nil {
return err
}

if err = mkEfiBoot(); err != nil {
return err
}

err = mkLegacyBoot(templateDir)
if err != nil {
return err
}

if err = packageIso(imgName); err != nil {
return err
}
Expand Down

0 comments on commit cb0c9f5

Please sign in to comment.