help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to enumerate files in a directory using the builtin shell?


From: Thiago Padilha
Subject: Re: How to enumerate files in a directory using the builtin shell?
Date: Sat, 30 Jan 2016 21:44:26 +0000

After following Andrei's suggestion of adding a sleep command I could finally see the error. It turns out I needed to add the required module(regexp.mod) to the subdirectory "x86_64-efi".

I'm sharing my final config in case anyone needs something similar in the future:

    set superusers="root"
    password_pbkdf2 root grub.pbkdf2.sha512.10000. ...(password hash)
    
    insmod regexp
    
    search.fs_uuid 1b3fdfe0-99cb-4aba-9acd-695b84be63cc root hd0,gpt3 
    
    for os_path in ($root)/os/*; do
      regexp --set=os_name '^\([^)]*\)/os/(.*)$' $os_path
      menuentry "boot $os_name" --unrestricted {
        configfile $os_path/boot/grub/grub.cfg
      }
    done
    
    submenu "boot iso file ->" --users "" {
      insmod loopback
      for iso in ($root)/iso/*.iso; do
        loopback tmp $iso
        regexp --set=iso_file '^\([^)]*\)/iso/(.*)$' $iso
        if [ -f (tmp)/boot/grub/loopback.cfg ]; then
          menuentry "boot $iso_file" $iso /iso/$iso_file {
            iso_path=$3
            export iso_path
            loopback loop $2
            root=(loop)
            configfile /boot/grub/loopback.cfg
            loopback --delete loop
          }
        elif [ -f (tmp)/boot/grub/grub.cfg ]; then
          menuentry "boot $iso_file" $iso {
            loopback loop $2
            root=(loop)
            configfile /boot/grub/grub.cfg
            loopback --delete loop
          }
        fi
        loopback --delete tmp
      done
    }

It is a bit bigger than I expected but working great nevertheless. This configuration targets a btrfs partition with two directories: "os" and "iso". "os" contains one subvolume per installed os, and "iso" a bunch of iso files that can be booted to. The "elif" is there for small isos that just contain a linux image and a initrd.(such as ubuntu minimal isos)

Note that I have added a small extra protection to booting the isos, to avoid the case where someone with temporary physical access to my computer can boot into an iso and mess with my installed distros.(Still possible for a thief to take my hd, but he would have to take it off my laptop since my bios is password protected and locked to boot my hard drive)

Anyway, thank you all for the help!

On Fri, Jan 29, 2016 at 2:19 PM Andrei Borzenkov <address@hidden> wrote:
29.01.2016 17:56, Thiago Padilha пишет:
> Jordan, thanks for the help
>
> Unfortunately, the "insmod regexp" line is not working for me, at least not
> from the configuration file. This my grub.cfg:
...

>
>     search.fs_uuid 1b3fdfe0-99cb-4aba-9acd-695b84be63cc btrfs hd0,gpt3
>     insmod regexp
>     for os_path in ($btrfs)/os/*; do
>       echo $os_path
>       regexp --set=os_name '^\([^)]*\)/os/(.*)$' $os_path
>     done
>
> Notice that I removed the configfile line to enter the interactive shell. I
> was expecting to see a list of distro names printed but nothing happens.

It does; but after grub finished processing of grub.cfg it clears screen
and displays usual banner. Add "sleep 15" after for loop.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]