Changing the grub configuration of a provisioned VM?

Hi all,

I use Foreman to provision VMs in my local libvirt installation. When
provisioning Ubuntu 16.04, I can't access the VM after provisioning and
only get a black screen in virt-manager. The reason for this is that the
vt.handoff parameter in the VMs grub-configuration conflicts with my VMs
graphics card somehow.

Workaround: Use another graphics card inside the VM (vmvga seems to work).

Question:
Can I influence the grub2 configuration of the VM via Foreman? I mean
the configuration of the finished VM, not the PXE stuff.

Sorry for bothering the list, but I only find lots of things regarding
the PXE grub configuration of Foreman, not the configuration of the
resulting VM.

I'd be thankfor for RTFM or Links, I just can't seem to find them in the
whole PXE-grub-heap… :wink:

Johannes

··· -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Absolutely you can. It's just a template called "PXEGrub2 default
local boot" and you can either modify it or use host parameters with
hostgroups to do per-host or per-group options.

LZ

··· On Mon, Mar 27, 2017 at 4:06 PM, Johannes Kastl wrote: > Hi all, > > I use Foreman to provision VMs in my local libvirt installation. When > provisioning Ubuntu 16.04, I can't access the VM after provisioning and > only get a black screen in virt-manager. The reason for this is that the > vt.handoff parameter in the VMs grub-configuration conflicts with my VMs > graphics card somehow. > > Workaround: Use another graphics card inside the VM (vmvga seems to work). > > Question: > Can I influence the grub2 configuration of the VM via Foreman? I mean > the configuration of the finished VM, not the PXE stuff. > > Sorry for bothering the list, but I only find lots of things regarding > the *PXE* grub configuration of Foreman, not the configuration of the > resulting VM. > > I'd be thankfor for RTFM or Links, I just can't seem to find them in the > whole PXE-grub-heap... ;-) > > Johannes > > -- > Johannes Kastl > Linux Consultant & Trainer > Tel.: +49 (0) 151 2372 5802 > Mail: kastl@b1-systems.de > > B1 Systems GmbH > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 > > -- > You received this message because you are subscribed to the Google Groups "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.


Later,
Lukas @lzap Zapletal

Hi Lukas,

Lukas Zapletal schrieb:
> Absolutely you can. It's just a template called "PXEGrub2 default
> local boot" and you can either modify it or use host parameters with
> hostgroups to do per-host or per-group options.

I thought that was modifying the PXE configuration, not the one that the
machine has on its local hard drive after provisioning?

Johannes

··· -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

There are two templates, one is when you are in BUILD mode, the other
is for the non-BUILD mode:

provisioning_templates/PXEGrub2/pxegrub2_default_local_boot.erb
provisioning_templates/PXEGrub2/pxegrub2_global_default.erb

LZ

··· On Tue, Mar 28, 2017 at 9:39 AM, Johannes Kastl wrote: > Hi Lukas, > > Lukas Zapletal schrieb: >> Absolutely you can. It's just a template called "PXEGrub2 default >> local boot" and you can either modify it or use host parameters with >> hostgroups to do per-host or per-group options. > > I thought that was modifying the PXE configuration, not the one that the > machine has on its local hard drive after provisioning? > > Johannes > > -- > Johannes Kastl > Linux Consultant & Trainer > Tel.: +49 (0) 151 2372 5802 > Mail: kastl@b1-systems.de > > B1 Systems GmbH > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 > > -- > You received this message because you are subscribed to the Google Groups "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.


Later,
Lukas @lzap Zapletal

Hi Lukas,

Lukas Zapletal schrieb:
> There are two templates, one is when you are in BUILD mode, the other
> is for the non-BUILD mode:
>
> provisioning_templates/PXEGrub2/pxegrub2_default_local_boot.erb
> provisioning_templates/PXEGrub2/pxegrub2_global_default.erb

Correct me if I'm wrong:
The pxegrub2_default_local_boot does nothing more than chainload the
bootloader installed on the machine's hard disk (unless it is an EFI
machine):

> menuentry "Chainload into BIOS bootloader on first disk" {
> set root=(hd0,0)
> chainloader +1
> }

(This is actually from the pxegrub2_chainload snippet that gets included
in the pxegrub2_default_local_boot template)

So with a normal bios boot, it just boots the machine via PXE and tells
it to chainload the bootloader in the mbr and boot from that.

What I am interested in is the configuration of this bootloader in the
mbr. I.e. the one, that can be configured on the machine itself
(/boot/grub/grub.cfg).

I hope I could clarify what I want to achieve.

I tried to do some stuff via preseed, but it never got called
apparently. I'm debugging this right now, but have not got any clue this
far.

Johannes

··· -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Oh that one, I don't know. Anaconda in RHEL can configure something,
but definitely not everything. Do a post install scriplet… It's just
bunch of config files.

LZ

··· On Tue, Mar 28, 2017 at 12:36 PM, Johannes Kastl wrote: > Hi Lukas, > > Lukas Zapletal schrieb: >> There are two templates, one is when you are in BUILD mode, the other >> is for the non-BUILD mode: >> >> provisioning_templates/PXEGrub2/pxegrub2_default_local_boot.erb >> provisioning_templates/PXEGrub2/pxegrub2_global_default.erb > > Correct me if I'm wrong: > The pxegrub2_default_local_boot does nothing more than chainload the > bootloader installed on the machine's hard disk (unless it is an EFI > machine): > >> menuentry "Chainload into BIOS bootloader on first disk" { >> set root=(hd0,0) >> chainloader +1 >> } > > (This is actually from the pxegrub2_chainload snippet that gets included > in the pxegrub2_default_local_boot template) > > So with a normal bios boot, it just boots the machine via PXE and tells > it to chainload the bootloader in the mbr and boot from that. > > What I am interested in is the configuration of this bootloader in the > mbr. I.e. the one, that can be configured on the machine itself > (/boot/grub/grub.cfg). > > I hope I could clarify what I want to achieve. > > I tried to do some stuff via preseed, but it never got called > apparently. I'm debugging this right now, but have not got any clue this > far. > > Johannes > > -- > Johannes Kastl > Linux Consultant & Trainer > Tel.: +49 (0) 151 2372 5802 > Mail: kastl@b1-systems.de > > B1 Systems GmbH > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 > > -- > You received this message because you are subscribed to the Google Groups "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.


Later,
Lukas @lzap Zapletal

Lukas Zapletal schrieb:
> Oh that one, I don't know. Anaconda in RHEL can configure something,
> but definitely not everything. Do a post install scriplet… It's just
> bunch of config files.

I was hoping for a more specific answer… ;-(

I tried the following (using preseed, as its an Ubuntu system, that is
being deployed).

I cloned the "Preseed default user data" template and added the
following lines, but they were never executed (at least I found no trace
of them in any log files):

> /bin/sed -i".BAK" 's/vt_handoff="1"/vt_handoff="0"/' /target/etc/grub.d/10_linux
> +/usr/bin/touch /target/root/PRESEED_HAS_RUN
> /usr/sbin/update-grub

I tried various version, with and without the /target/, with the path to
sed being "/target/bin/sed" or without full paths.

Then I cloned the "Preseed default finish" template and added these
commands, but this resulted in an error during preseed, although the
error shows the previous wget command returning an error.

In the presed finish template there are a couple of sed commands, that
do not use the /target prefix. I'll try and adapt that one again and see
if it works.

In the meantime: Has anyone enhanced the preseed finish template and
could show me an example? Or has anyone got any RTFMfor me?

Thanks in advance,
Johannes

··· -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Johannes Kastl schrieb:

> Then I cloned the "Preseed default finish" template and added these
> commands, but this resulted in an error during preseed, although the
> error shows the previous wget command returning an error.

I retested in the "Preseed default finish" and it worked. I'll try to
put it into a snippet and add it conditionally, but basically this is
the lines I now have (with some context before and after):

> <%
> # safemode renderer does not support unary negation
> pm_set = @host.puppetmaster.empty? ? false : true
> puppet_enabled = pm_set || @host.param_true?('force-puppet')
> salt_enabled = @host.params['salt_master'] ? true : false
> chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
> %>
>
> /bin/sed -i".BAK" 's/vt_handoff="1"/vt_handoff="0"/' /etc/grub.d/10_linux
> /usr/sbin/update-grub
>
> <% subnet = @host.subnet -%>

Johannes

··· -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

This fix works on ubuntu 20.04 together with Foreman 2.0.1.