Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] GRUB2 custom menu entry (ISO)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 546

PostPosted: Thu Jan 23, 2014 2:33 pm    Post subject: [SOLVED] GRUB2 custom menu entry (ISO) Reply with quote

Hi,

I'm trying to add a GRUB2 meny entry to boot an ISO system.
When I select this entry at the Grub boot menu I get an error:

Code:
error: invalid file name `'


What is wrong with the following custom menu entry?

Code:

# cat /etc/grub.d/09_CUSTOM2
#!/bin/sh -e
echo "Adding custom ISO entries to GRUB2"
cat << EOF
menuentry "LIVE systemrescuecd-x86-4.0.0.iso (32-bit)" {
set root=(hd0,4)
set isofile="/opt/custom/ISO/systemrescuecd-x86-4.0.0.iso"
loopback loop (hd0,4)$isofile
linux (loop)/isolinux/rescue32 setkmap=us isoloop=$isofile
initrd (loop)/isolinux/initram.igz
}
EOF


Thanks,

Vieri


Last edited by Vieri on Fri Jan 24, 2014 7:56 am; edited 1 time in total
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2584
Location: userland

PostPosted: Thu Jan 23, 2014 6:20 pm    Post subject: Reply with quote

Can't find the error... is it possible that quotation marks in grub2's shell work differently from bash? Try to drop them from the 'set isofile' line. Anyway, the following is working for me, just for reference:
Code:
menuentry "sysresccd" {
set root=(hd0,3)
loopback loop /data/images/systemrescuecd-x86-3.7.1.iso
linux (loop)/isolinux/rescue64 isoloop=/data/images/systemrescuecd-x86-3.7.1.iso
initrd (loop)/isolinux/initram.igz
}
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 546

PostPosted: Thu Jan 23, 2014 7:18 pm    Post subject: Reply with quote

Voltago, so if I get it right, your iso file is on your third partition (something like sda3)?
I haven't tried yet "loopback loop $isofile" (that is, removing the extra (hd0,4) in my example".
However, I did try to drop the double quotes but it gave me the same error message (didn't try single quotes yet).
I'm new to grub2 and I'm wondering where you specified your menuentry. Did you create a file in /etc/grub.d starting it with code such as the folllowing:
Code:

#!/bin/sh -e
cat << EOF

or did you do it somewhere else?

Thanks
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 546

PostPosted: Thu Jan 23, 2014 7:24 pm    Post subject: Reply with quote

I'm wondering if the problem could be with the $ in $isofile. Maybe I need to escape it with \$.
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2584
Location: userland

PostPosted: Thu Jan 23, 2014 8:41 pm    Post subject: Reply with quote

Vieri wrote:
Voltago, so if I get it right, your iso file is on your third partition (something like sda3)?

Yes, that's right. For you that would be changed to (hd0,4).
Vieri wrote:

I'm new to grub2 and I'm wondering where you specified your menuentry. Did you create a file in /etc/grub.d starting it with code such as the folllowing:
Code:

#!/bin/sh -e
cat << EOF

or did you do it somewhere else?

Sorry, I'm confused now... are you trying to generate a file here that's supposed to go to /etc/grub.d/ with a script, or is your code that file itself? If the latter is true, remove the initial shebang and the cat << EOF ... EOF construct, grub2-mkconfig does all that for you.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2970
Location: Germany

PostPosted: Thu Jan 23, 2014 11:43 pm    Post subject: Reply with quote

Mine look like this. (hd0,msdos3) being the /dev/sdx3 of a USB stick with msdos partitions. I put the ISO in the root of that filesystem, it's easier to handle both in the grub.cfg and for the livecd to find its ISO for the loopmounting.

Code:

    submenu "SystemRescueCD >" {
        menuentry "SystemRescueCD 3.1.2 i386" {
            set isofile="systemrescuecd-x86-3.1.2.iso"
            loopback loop (hd0,msdos3)/$isofile
            linux (loop)/isolinux/rescue32 isoloop=$isofile
            initrd (loop)/isolinux/initram.igz
        }
        menuentry "SystemRescueCD 3.1.2 amd64" {
            set isofile="systemrescuecd-x86-3.1.2.iso"
            loopback loop (hd0,msdos3)/$isofile
            linux (loop)/isolinux/rescue64 isoloop=$isofile
            initrd (loop)/isolinux/initram.igz
        }
        menuentry "SystemRescueCD 2.8.1 i386" {
            set isofile="systemrescuecd-x86-2.8.1.iso"
            loopback loop (hd0,msdos3)/$isofile
            linux (loop)/isolinux/rescue32 isoloop=$isofile
            initrd (loop)/isolinux/initram.igz
        }
        menuentry "SystemRescueCD 2.8.1 amd64" {
            set isofile="systemrescuecd-x86-2.8.1.iso"
            loopback loop (hd0,msdos3)/$isofile
            linux (loop)/isolinux/rescue64 isoloop=$isofile
            initrd (loop)/isolinux/initram.igz
        }
    }


Yes, I still need to update that for the new version... might be a good time to invest in a faster USB3 stick now that I have a USB3 system...
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 546

PostPosted: Fri Jan 24, 2014 7:54 am    Post subject: Reply with quote

Hi,

Now I'm even more confused...
But I think I straightened everything out.

I'm guessing that you are all placing your menuentry sections into
Code:
/etc/grub.d/40_custom

below the "exec tail" line. Am I right?

I'm not using 40_custom but creating seperate scripts in /etc/grub.d.

In fact, if I were to eliminate the shebang and not echo the lines then this would be the result:

Code:

# cat /etc/grub.d/09_CUSTOM2
menuentry "LIVE systemrescuecd-x86-4.0.0.iso (32-bit)" {
set root=(hd0,4)
set isofile="/opt/custom/ISO/systemrescuecd-x86-4.0.0.iso"
loopback loop (hd0,4)$isofile
linux (loop)/isolinux/rescue32 setkmap=us isoloop=$isofile
initrd (loop)/isolinux/initram.igz
}


When applying this GRUB2 would abort with the following errors:

Code:

Generating grub.cfg ...
/etc/grub.d/09_CUSTOM2: line 1: menuentry: command not found
/etc/grub.d/09_CUSTOM2: line 2: syntax error near unexpected token `('
/etc/grub.d/09_CUSTOM2: line 2: `set root=(hd0,4)'


So I followed my hunch about the $ sign and did the following:

Code:

# cat /etc/grub.d/09_CUSTOM2
#!/bin/sh -e
echo "Adding custom ISO entries to GRUB2"
cat << EOF
menuentry "LIVE systemrescuecd-x86-4.0.0.iso (32-bit)" {
set root=(hd0,4)
set isofile="/opt/custom/ISO/systemrescuecd-x86-4.0.0.iso"
loopback loop (hd0,4)\$isofile
linux (loop)/isolinux/rescue32 setkmap=us isoloop=\$isofile
initrd (loop)/isolinux/initram.igz
}
EOF


Applying with mkconfig yields no errors and I can read the following code within: /boot/grub/grub.cfg

Code:

### BEGIN /etc/grub.d/09_CUSTOM2 ###
Adding custom ISO entries to GRUB2
menuentry "LIVE systemrescuecd-x86-4.0.0.iso (32-bit)" {
set root=(hd0,4)
set isofile="/opt/custom/ISO/systemrescuecd-x86-4.0.0.iso"
loopback loop (hd0,4)$isofile
linux (loop)/isolinux/rescue32 setkmap=us isoloop=$isofile
initrd (loop)/isolinux/initram.igz
}
### END /etc/grub.d/09_CUSTOM2 ###


Finally I can reboot and select the ISO from GRUB and load the live system fine.

So the whole trouble was with escaping the $ character.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2970
Location: Germany

PostPosted: Fri Jan 24, 2014 8:15 am    Post subject: Reply with quote

Glad you solved it. I don't use /etc/grub.d at all, I hate the generated stuff.

Any time you add something to grub.d you should have a look at your generated grub.conf to verify that stuff looks as it's supposed to.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum