Announcement

Collapse
No announcement yet.

Adding an ISO to grub

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Ok, this should do it. It checks if isoinfo exists, and warns about the partition format.
    the "lz problem" is solved, as it now gets the name from the ISO. Thanks, oshunluvr Click image for larger version

Name:	_birra.gif
Views:	1
Size:	762 Bytes
ID:	644670

    Code:
    #!/bin/bash
    ########### This script will add an entry to your grub boot menu for the ISO selected by the Dolphin Service Menu ##########
    ########### It will not work if not called from it ##########
    ###########
    ########### To actually make it work, comment out the "echo "$grubentry" >>customentry.txt" line ##########
    ########### and uncomment the following one ###########
    ########### Do the same for the"ls -la" one ###########
    echo A couple of checks:
    FILE=$(which isoinfo)
    if [ -f "$FILE" ]; then
      echo "$FILE exist." $'\e[0;36m' "OK."$'\e[0;37m'
    else 
      echo "isoinfo is" $'\e[0;31m' "not installed." $'\e[0;37m' "Please [sudo apt] install genisoimage and run this again.";exit
    fi
    echo
    part=$(df -P . | sed -n '$s/[[:blank:]].*//p');p1=${part:7:1};p2=${part:8:1};p3=$(tr abcdefghij 0123456789 <<< "$p1");p4="hd"$p3,$p2
    echo The partition your ISO is on is $'\e[0;32m' $part $'\e[0;37m'
    echo "If this is"$'\e[0;31m' "not"$'\e[0;37m' "in /dev/sdxy (or /dev/hdxy) format (e.g. /dev/sda1 or /dev/hda1)"
    echo "the partition name will" $'\e[0;31m'"not be converted" $'\e[0;37m'"correctly to grub2 format"
    echo "You will have to manually edit /etc/grub.d/40_custom"
    echo
    echo
    isoentry="$1"
    lz=$(isoinfo -l -i $isoentry |grep -i initrd | awk '{ print substr($NF, 1, length($NF)-2)}' | tr '[A-Z]' '[a-z]')
    grubentry="$(cat <<-EOF
    #
    #
    #!/bin/sh
    exec tail -n +3 \$0
    menuentry "New bootable ISO" {
          set isofile="$isoentry"
          loopback loop ($p4)\$isofile
          linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=\$isofile noprompt noeject toram
          initrd (loop)/casper/$lz
    }
    EOF
    )"
    #echo $grubentry
    #exit
    #echo $'\e[0;34m'
    #apt moo ##### this is just to make the script look prettier :·)
    echo $'\e[0;36m'Adding entry to /etc/grub.d/40_custom...
    sleep 1
    #pkexec echo "$grubentry" >>/etc/grub.d/40_custom ## This is the actual line
    echo "$grubentry" >>~/.local/share/kservices5/ServiceMenus/customentry.txt ## This is the line for testing purposes :·)
    echo $'\e[0;36m'Done
    echo $'\e[0;36m'Entry added to /etc/grub.d/40_custom
    echo
    echo The added entry was:
    echo $'\e[0;37m'
    tail -10 ~/.local/share/kservices5/ServiceMenus/customentry.txt
    echo $'\e[0;36m'
    echo
    while true; do
      read -p "Does that look correct? y/n: " yn
      case $yn in
          [Nn]* ) echo Close the window to exit.;exit;;
          [Yy]* ) echo "OK. Let's update grub then."; break;;
      esac
    done
    echo
    echo
    while true; do
      read -p "Would you like to update grub? y/n: " yn
      case $yn in
          [Nn]* ) echo Close the window to exit.;exit;;
          [Yy]* ) echo OK.; break ;;
      esac
    done
    echo
    echo "Updating grub..."
    echo $'\e[0;37m'
    #pkexec update-grub ## This is the actual line
    ls -la ## This is the line for testing purposes :·)
    echo $'\e[0;36m'
    echo "Let's check. "
    echo "These are the last 24 lines of /boot/grub/grub.cfg:"
    echo $'\e[0;37m'
    tail -24 /boot/grub/grub.cfg
    echo $'\e[0;36m'
    echo "You should find an entry for 'New bootable ISO' in your grub menu that should boot the OS"
    echo
    echo Close the window to exit.
    It's still in "testing" mode, it doesn't actually write /etc/grub.d/40_custom or update grub, so feel free to play with it. It still needs the service menu for the ISO name :·)

    Comment


      #32
      I'm surprise you guys get loopback to work at all.
      I haven't had loopback or boot from grub ISO since using efi.

      From a grub> prompt, typing: loopback loop (hd1,2)/WHATEVER/ubuntu.iso
      grub hangs up. I found this topic and bug report:

      https://askubuntu.com/questions/1186...n-ubuntu-19-10

      Bug report: https://bugs.launchpad.net/ubuntu/+s...2/+bug/1851311

      I have the exact same issue.
      Boot Info Script

      Comment


        #33
        It could be the 2.04 thing.

        What does grub-install --version return there?
        Because mine returns grub-install (GRUB) 2.02-2ubuntu8.15

        Comment


          #34
          Yes, it is 2.04. There is a work around inside that bug report. It works for one person, but not for another.
          Boot Info Script

          Comment


            #35
            (Yeah, yeah, I'm still at it ;·) (Well, actually I haven't been for a while, but today...)

            So, I got it to parse all possible partition names in the galactic sector (well, almost, but good enough ;·) so now I'm stuck on the loopy loops.
            I can easily check the grub version:
            PHP Code:
            #!/bin/bash
            grbv=$(grub-install --version  awk '/(GRUB)/ {print substr($3,4,1)}')
            #echo $grbv;exit
            case $grbv in 
            4
            ) echo Your grub version is $'\e[0;33m' "2.0"$grbv". Not OK." $'\e[0;37m'              ;;
            2) echo Your grub version is $'\e[0;32m' "2.0"$grbv". OK." $'\e[0;37m'                 ;;
            esac 
            No, it's not PHP Code, it's bash, but with PHP the colours are prettier ;·)

            Now, is there were a way to, instead of sending a stupid "Not OK" warning, do something else with grub instead of using the loopy loop?

            Comment


              #36
              OK. I think I have it now.
              The loopback thing really looks like it can be solved by adding rmmod tpm before loopy loop loopback loop

              So in the case the grub version is<= 2.02, I skip the rmmod tpm, if it is 2.04 I add it.
              I tested it with K20.04, (grub 2.04) and it does boot the ISO.

              I'll update the code in the original post.

              Comment


                #37
                Don, you used to have problems posting Konsole output to this forum and retain the coloring. How'd you solve that?
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #38
                  I didn't. I just "cheated" a bit with the PHP code tags :·)

                  Anyway, I put it on Sourceforge to see if I get any input there...

                  Comment


                    #39
                    I seem to have a big problem with this.
                    I tested it on the Ubuntu 20.04 ISO.
                    If I look at it with Ark, /casper/initrd is called just that, initrd (no lz or anything.
                    If I grep the isoinfo output...
                    INITRD.;1
                    It's got a trailing dot! Click image for larger version

Name:	shocked.gif
Views:	3
Size:	824 Bytes
ID:	644717
                    Whereas, on another ISO, where it's called initrd.lz,
                    INITRD.LZ;1 - no trailing dot.

                    Now, obviously, once I parse it with
                    lz=$(isoinfo -l -i $isoentry |grep -i initrd | awk '{ print substr($NF, 1, length($NF)-2)}' | tr '[A-Z]' '[a-z]')

                    The INITRD.LZ;1 entry returns initrd.lz , but the INITRD.;1 one returns initrd. (with a dot at the end) :·( :·( :·(

                    Where does the dot come from?

                    Click image for larger version

Name:	Screenshot_20200511_093242.png
Views:	1
Size:	32.3 KB
ID:	644715

                    Click image for larger version

Name:	icon_smile_help.gif
Views:	1
Size:	552 Bytes
ID:	644716

                    Comment


                      #40
                      Hmm. I "patched" it... but I'm a bit worried about other possible "initrd" formats... I did:
                      Code:
                      lz=$(isoinfo -l -i $isoentry | grep -i initrd | awk '{ print substr($NF, 1, length($NF)[COLOR=#008000]-3[/COLOR])}' | tr '[A-Z]' '[a-z]')
                      lzch=${lz:7:1}
                      if [[ ! -z  $lzch  ]]; then
                      lz=$(isoinfo -l -i $isoentry | grep -i initrd | awk '{ print substr($NF, 1, length($NF)[COLOR=#008000]-2[/COLOR])}' | tr '[A-Z]' '[a-z]')
                      fi
                      That is, I check the 7th character, if it's not empty, then...
                      It works... but it's sort of... improvised... what if they package the ISO in an even more annoying way... and what's with the trailing dot anyway?

                      [EDIT] Because, I tried with the Kubuntu ISO, it had the initrd without the lz, and it gave the trailing dot :·(
                      Last edited by Don B. Cilly; May 11, 2020, 05:32 AM.

                      Comment


                        #41
                        As I suggested in post #28, isoinfo looks like an old DOS utility, where the dot in file names is implicit in the short 8.3 form. In such programmes, it was common for the dot to be shown regardless.
                        Regards, John Little

                        Comment


                          #42
                          A funny one.
                          I found something called "iso-info" - with the dash.
                          I had to apt-install it, but.
                          It returns the proper file name with no upper case, no semicolons, no trailing dots, no...

                          Whereas

                          Code:
                          $ isoinfo -l -i ./kubuntu-20.04-desktop-amd64.iso | grep -i initrd | awk '{ print $NF}'
                          INITRD.;1
                          $ isoinfo -l -i ./neon-user-20200416-1115.iso | grep -i initrd | awk '{ print $NF}'
                          INITRD.LZ;1
                          which, as you say looks definitely DOS-related (what with the uppercase and all)

                          Code:
                          $ iso-info -l -i ./kubuntu-20.04-desktop-amd64.iso | grep -i initrd | awk '{ print $NF}'
                          initrd
                          $ iso-info -l -i ./neon-user-20200416-1115.iso | grep -i initrd | awk '{ print $NF}'
                          initrd.lz
                          which needs absolutely no parsing of semicolons, dots, string length or case.
                          Whereas with isoinfo I had to do things like
                          awk '{ print substr($NF, 1, length($NF)-2)}' | tr '[A-Z]' '[a-z]'
                          and have if-thens according to the 7th character of the string (pretty ridiculous).
                          iso-info just returns the proper name, no funny DOS-related stuff.

                          I guess I'll make it depend on it.
                          I'm not even sure if the pesky isoinfo (with no dash) is installed by default anyway :·/

                          Comment


                            #43
                            Originally posted by Don B. Cilly View Post
                            One thing I'm curious about: Will df -P always return partition names in the form /dev/sdxy or can it return things like /dev/nvme0n1, /dev/mmcblk0, and the like?
                            Because in that case the little conversion line from df to grub notation ...
                            No idea why you need that, but anyhow you could also check the output of cat /proc/mounts
                            Well thats all for now, 3M

                            Comment


                              #44
                              I've used both "cat /proc/mounts" and just "mount" to show what is mounted. I was currious to see if the two commands give different results:

                              jerry@jerryAspire-V3-771:~$ cat /proc/mounts
                              Code:
                              sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
                              proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
                              udev /dev devtmpfs rw,nosuid,noexec,relatime,size=8067656k,nr_inodes=2016914,mode=755 0 0
                              devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
                              tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=1623420k,mode=755 0 0
                              /dev/sda1 / btrfs rw,relatime,ssd,space_cache,subvolid=1080,subvol=/@ 0 0
                              securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
                              tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
                              tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
                              tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
                              cgroup2 /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
                              cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0
                              pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
                              none /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
                              cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
                              cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0
                              cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
                              cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
                              cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
                              cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
                              cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
                              cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
                              cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
                              cgroup /sys/fs/cgroup/rdma cgroup rw,nosuid,nodev,noexec,relatime,rdma 0 0
                              cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
                              systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=2464 0 0
                              mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0
                              hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0
                              debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0
                              tracefs /sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0
                              fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0
                              configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0
                              /dev/sda1 /home btrfs rw,relatime,ssd,space_cache,subvolid=1081,subvol=/@home 0 0
                              binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
                              tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=1623416k,mode=700,uid=1000,gid=1000 0
                              jerry@jerryAspire-V3-771:~$ mount
                              Code:
                              sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
                              proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
                              udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=8067656k,nr_inodes=2016914,mode=755)
                              devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
                              tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1623420k,mode=755)
                              /dev/sda1 on / type btrfs (rw,relatime,ssd,space_cache,subvolid=1080,subvol=/@)
                              securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
                              tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
                              tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
                              tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
                              cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
                              cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
                              pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
                              none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
                              cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
                              cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
                              cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
                              cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
                              cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
                              cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
                              cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
                              cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
                              cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
                              cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
                              cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
                              systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=2464)
                              mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
                              hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
                              debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
                              tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
                              fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
                              configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
                              /dev/sda1 on /home type btrfs (rw,relatime,ssd,space_cache,subvolid=1081,subvol=/@home)
                              binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
                              tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=1623416k,mode=700,uid=1000,gid=1000)
                              The difference is obvious. The cat /proc/mounts command includes the "dumping" and "fscking" options. The "dumping" option is an old one and is always zero. The fscking option generally has the root partition set to 1 and the others have higher numbers, giving the order in which they should be checked. This option is vaild mainly for EXT2, EXT3 and EXT4 file systems and is ignored for BTRFS and swapfiles.
                              "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                              – John F. Kennedy, February 26, 1962.

                              Comment


                                #45
                                During the hey day of this thread, in May, I was using a version of grub that I installed in 2018, from 18.04. Another grub thread recently made me look at my grub set up again, and I decided to refresh it from 20.04.

                                This broke iso booting. After an intensive Google session, I found bug 1851311. Even asking grub to "ls" an iso file fails, f.ex., typing from memory:
                                Code:
                                grub> ls ($root)/iso/kubuntu-20.04-desktop-amd64.iso
                                error: out of memory
                                Comment #51 gives a workaround, add the line "rmmod tpm" before the loopback line.

                                A fix seems to be in the works to come in 20.10.
                                Regards, John Little

                                Comment

                                Working...
                                X