summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2024-03-13 01:10:50 +0200
committerzdc <zdc@users.noreply.github.com>2024-03-14 17:39:20 +0200
commit425b808028a993a6ca13196ad6ad7b9daf358518 (patch)
tree5d411c47db43f5120905a4b78601bbf65b0c3641
parent8f2bc373c5bf8b4018814c17dbddad3730ef66bf (diff)
downloadvyos-vm-images-425b808028a993a6ca13196ad6ad7b9daf358518.tar.gz
vyos-vm-images-425b808028a993a6ca13196ad6ad7b9daf358518.zip
Added support for new GRUB configuration in >=1.4
Added support for the new GRUB configuration style used in VyOS 1.4 and newer.
-rw-r--r--hyperv.yml2
-rw-r--r--qemu.yml2
-rw-r--r--raw.yml2
-rw-r--r--roles/install-grub-v2/files/vyos_unattended_installer.py46
-rw-r--r--roles/install-grub-v2/tasks/main.yml55
-rw-r--r--roles/install-grub-v2/tests/inventory2
-rw-r--r--roles/install-grub-v2/tests/test.yml4
-rw-r--r--roles/install-grub-wrapper/tasks/main.yml9
-rw-r--r--roles/install-grub-wrapper/tests/inventory2
-rw-r--r--roles/install-grub-wrapper/tests/test.yml4
-rw-r--r--vagrant-libvirt.yml2
-rw-r--r--vmware.yml2
12 files changed, 127 insertions, 5 deletions
diff --git a/hyperv.yml b/hyperv.yml
index da81568..3aec76b 100644
--- a/hyperv.yml
+++ b/hyperv.yml
@@ -21,7 +21,7 @@
- install-image
- mount-root-fs
- install-config
- - install-grub
+ - install-grub-wrapper
- install-persistence-conf
- install-cloud-init-wrapper
- unmount-pre
diff --git a/qemu.yml b/qemu.yml
index 5b44cca..4efb3bc 100644
--- a/qemu.yml
+++ b/qemu.yml
@@ -24,7 +24,7 @@
- install-image
- mount-root-fs
- install-config
- - install-grub
+ - install-grub-wrapper
- install-persistence-conf
- install-cloud-init-wrapper
- install-guest-agent-wrapper
diff --git a/raw.yml b/raw.yml
index 870ea0f..0515f07 100644
--- a/raw.yml
+++ b/raw.yml
@@ -24,7 +24,7 @@
- install-image
- mount-root-fs
- install-config
- - install-grub
+ - install-grub-wrapper
- install-persistence-conf
- install-cloud-init-wrapper
- install-guest-agent-wrapper
diff --git a/roles/install-grub-v2/files/vyos_unattended_installer.py b/roles/install-grub-v2/files/vyos_unattended_installer.py
new file mode 100644
index 0000000..1d3c17e
--- /dev/null
+++ b/roles/install-grub-v2/files/vyos_unattended_installer.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2023 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from importlib import util
+from os import environ
+from sys import exit
+
+spec = util.spec_from_file_location(
+ "vinstall", "/usr/libexec/vyos/op_mode/image_installer.py"
+)
+vinstall = util.module_from_spec(spec)
+spec.loader.exec_module(vinstall)
+
+if __name__ == "__main__":
+ # read configuration variables
+ vyos_version = environ["vyos_version"]
+ console_type = "tty" if environ["console_type"] == "kvm" else "ttyS"
+ install_target = environ["install_target"]
+
+ # install GRUB configuration files
+ vinstall.setup_grub("/boot")
+ vinstall.grub.version_add(vyos_version, "/boot")
+ vinstall.grub.set_default(vyos_version, "/boot")
+ vinstall.grub.set_console_type(console_type, "/boot")
+
+ # install GRUB
+ vinstall.grub.install(install_target, "/boot/boot", "/boot/efi")
+
+ # sort inodes (to make GRUB read config files in alphabetical order)
+ vinstall.grub.sort_inodes(f"/boot/{vinstall.grub.GRUB_DIR_VYOS}")
+ vinstall.grub.sort_inodes(f"/boot/{vinstall.grub.GRUB_DIR_VYOS_VERS}")
+
+ exit()
diff --git a/roles/install-grub-v2/tasks/main.yml b/roles/install-grub-v2/tasks/main.yml
new file mode 100644
index 0000000..32a57b7
--- /dev/null
+++ b/roles/install-grub-v2/tasks/main.yml
@@ -0,0 +1,55 @@
+# It is necessary to mount and bind /dev, /proc, /sys and /boot in order to execute grub-install
+# and install GRUB correctly within the {{ volume_drive }} using chroot
+
+# XXX: ansible mount module requires fstype so it cannot be used for binding an already
+# mounted location, we get to use mount directly at least for /boot
+- name: Mount and bind /dev /proc /sys and {{ vyos_write_root }}/boot to {{ vyos_install_root }}
+ become: true
+ shell: mount --bind /dev {{ vyos_install_root }}/dev &&
+ mount --bind /proc {{ vyos_install_root }}/proc &&
+ mount --bind /sys {{ vyos_install_root }}/sys &&
+ mount --bind {{ vyos_write_root }} {{ vyos_install_root }}/boot
+
+- name: Mount EFI
+ become: true
+ mount:
+ src: "{{ vyos_target_drive }}p{{ partition_num_efi }}"
+ path: "{{ vyos_install_root }}/boot/efi"
+ fstype: vfat
+ state: mounted
+ boot: no
+ when: partition_num_efi is defined
+
+- name: Pause
+ pause:
+ prompt: "Continue?"
+
+- name: Copy installer
+ become: true
+ copy:
+ src: "files/vyos_unattended_installer.py"
+ dest: "{{ vyos_install_root }}/tmp/vyos_unattended_installer.py"
+
+- name: Install GRUB and configuration
+ become: true
+ command: chroot {{ vyos_install_root }} python3 /tmp/vyos_unattended_installer.py
+ environment:
+ vyos_version: "{{ vyos_version }}"
+ install_target: "{{ loop_device.stdout }}"
+ console_type: "{{ grub_console }}"
+
+- name: Remove installer
+ become: true
+ file:
+ path: "{{ vyos_install_root }}/tmp/vyos_unattended_installer.py"
+ state: absent
+
+- name: Unmount EFI
+ become: true
+ mount:
+ src: "{{ vyos_target_drive }}p{{ partition_num_efi }}"
+ path: "{{ vyos_install_root }}/boot/efi"
+ fstype: vfat
+ state: absent
+ boot: no
+ when: partition_num_efi is defined
diff --git a/roles/install-grub-v2/tests/inventory b/roles/install-grub-v2/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/roles/install-grub-v2/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/roles/install-grub-v2/tests/test.yml b/roles/install-grub-v2/tests/test.yml
new file mode 100644
index 0000000..6adc767
--- /dev/null
+++ b/roles/install-grub-v2/tests/test.yml
@@ -0,0 +1,4 @@
+---
+- hosts: localhost
+ roles:
+ - install-grub-v2
diff --git a/roles/install-grub-wrapper/tasks/main.yml b/roles/install-grub-wrapper/tasks/main.yml
new file mode 100644
index 0000000..9a531f9
--- /dev/null
+++ b/roles/install-grub-wrapper/tasks/main.yml
@@ -0,0 +1,9 @@
+- name: Select GRUB for installer for VyOS <=1.3
+ include_role:
+ name: install-grub
+ when: vyos_version is regex("^1\.[2-3].*$")
+
+- name: Select GRUB for installer for VyOS >=1.4
+ include_role:
+ name: install-grub-v2
+ when: vyos_version is regex("^1\.[4-9].*$")
diff --git a/roles/install-grub-wrapper/tests/inventory b/roles/install-grub-wrapper/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/roles/install-grub-wrapper/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/roles/install-grub-wrapper/tests/test.yml b/roles/install-grub-wrapper/tests/test.yml
new file mode 100644
index 0000000..8d6af07
--- /dev/null
+++ b/roles/install-grub-wrapper/tests/test.yml
@@ -0,0 +1,4 @@
+---
+- hosts: localhost
+ roles:
+ - install-grub-wrapper
diff --git a/vagrant-libvirt.yml b/vagrant-libvirt.yml
index 55449da..a7cf76f 100644
--- a/vagrant-libvirt.yml
+++ b/vagrant-libvirt.yml
@@ -22,7 +22,7 @@
- install-image
- mount-root-fs
- install-config
- - install-grub
+ - install-grub-wrapper
- install-persistence-conf
- unmount-pre
- unmount-all
diff --git a/vmware.yml b/vmware.yml
index c2ec5d2..b30e870 100644
--- a/vmware.yml
+++ b/vmware.yml
@@ -27,7 +27,7 @@
- install-image
- mount-root-fs
- install-config
- - install-grub
+ - install-grub-wrapper
- install-persistence-conf
- install-cloud-init-wrapper
- fstrim