diff options
author | kroy <kroy@kroy.io> | 2020-04-28 13:54:00 -0500 |
---|---|---|
committer | kroy <kroy@kroy.io> | 2020-04-29 09:30:37 -0500 |
commit | 3ee8d560dc91173a2f1834cbad119b29177a6b3c (patch) | |
tree | 52d757c1e2361ceeaedceb2c9bed5052b286f40a | |
parent | 4e0f2e4c6a648343a8132f1eadc0cdb89bda8c4a (diff) | |
download | vyos-vm-images-3ee8d560dc91173a2f1834cbad119b29177a6b3c.tar.gz vyos-vm-images-3ee8d560dc91173a2f1834cbad119b29177a6b3c.zip |
Build BIOS/UEFI Hybrid Images
-rw-r--r-- | hyperv.yml | 7 | ||||
-rw-r--r-- | qemu.yml | 1 | ||||
-rw-r--r-- | roles/attach-loop-device/tasks/main.yml | 12 | ||||
-rw-r--r-- | roles/attach-loop-device/tests/inventory | 2 | ||||
-rw-r--r-- | roles/attach-loop-device/tests/test.yml | 4 | ||||
-rw-r--r-- | roles/hyperv-vhd/tasks/main.yml | 4 | ||||
-rw-r--r-- | roles/install-grub/tasks/main.yml | 29 | ||||
-rw-r--r-- | roles/install-grub/templates/boot/grub/grub.cfg.j2 | 2 | ||||
-rw-r--r-- | roles/install-packages/tasks/main.yml | 8 | ||||
-rw-r--r-- | roles/setup-root-partition/tasks/main.yml | 55 | ||||
-rw-r--r-- | roles/unmount-all/tasks/main.yml | 4 | ||||
-rw-r--r-- | vagrant-libvirt.yml | 1 | ||||
-rw-r--r-- | vmware.yml | 1 |
13 files changed, 81 insertions, 49 deletions
@@ -5,10 +5,10 @@ connection: local vars: vyos_platform: Hyper-V - vyos_format: vhd - vyos_hyperv_img: /tmp/vyos_hyperv_image.vhd + vyos_format: vhdx + vyos_hyperv_img: /tmp/vyos_hyperv_image.vhdx vyos_output_img: "{{ vyos_hyperv_img }}" - cloud_init: "true" + cloud_init: "false" cloud_init_ds_string: "{{ cloud_init_ds | default('NoCloud, ConfigDrive, None') }}" cloud_init_ds_list: "{{ cloud_init_ds_string.split(',') }}" roles: @@ -18,7 +18,6 @@ - mount-iso - get-version - create-disk - - attach-loop-device - setup-root-partition - install-image - mount-root-fs @@ -17,7 +17,6 @@ - mount-iso - get-version - create-disk - - attach-loop-device - setup-root-partition - install-image - mount-root-fs diff --git a/roles/attach-loop-device/tasks/main.yml b/roles/attach-loop-device/tasks/main.yml deleted file mode 100644 index 8815910..0000000 --- a/roles/attach-loop-device/tasks/main.yml +++ /dev/null @@ -1,12 +0,0 @@ -- name: Find the first unused loop device. - become: true - shell: losetup -f - register: result - -- name: Set up a loop device. - become: true - command: "losetup {{ result.stdout }} {{ vyos_raw_img }}" - -- name: Set vyos_target_drive. - set_fact: - vyos_target_drive: "{{ result.stdout }}" diff --git a/roles/attach-loop-device/tests/inventory b/roles/attach-loop-device/tests/inventory deleted file mode 100644 index 878877b..0000000 --- a/roles/attach-loop-device/tests/inventory +++ /dev/null @@ -1,2 +0,0 @@ -localhost - diff --git a/roles/attach-loop-device/tests/test.yml b/roles/attach-loop-device/tests/test.yml deleted file mode 100644 index 2864e74..0000000 --- a/roles/attach-loop-device/tests/test.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- hosts: localhost - roles: - - attach-loop-device diff --git a/roles/hyperv-vhd/tasks/main.yml b/roles/hyperv-vhd/tasks/main.yml index 7d118f7..08a5762 100644 --- a/roles/hyperv-vhd/tasks/main.yml +++ b/roles/hyperv-vhd/tasks/main.yml @@ -1,2 +1,2 @@ -- name: Convert raw to vhd - command: qemu-img convert -f raw "{{ vyos_raw_img }}" -O vpc "{{ vyos_hyperv_img }}" +- name: Convert raw to "{{ vyos_format }}" + command: qemu-img convert -f raw "{{ vyos_raw_img }}" -O "{{ vyos_format }}" -o subformat=dynamic "{{ vyos_hyperv_img }}" diff --git a/roles/install-grub/tasks/main.yml b/roles/install-grub/tasks/main.yml index 33a1049..f9cc772 100644 --- a/roles/install-grub/tasks/main.yml +++ b/roles/install-grub/tasks/main.yml @@ -1,7 +1,8 @@ + - name: Create GRUB directory become: true file: - path: "{{ vyos_write_root }}/boot/grub" + path: "{{ vyos_install_root }}/boot/grub" state: directory # It is necessary to mount and bind /dev, /proc, /sys and /boot in order to execute grub-install @@ -14,15 +15,27 @@ 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 + mount --bind {{ vyos_write_root }} {{ vyos_install_root }}/boot args: warn: no + +- name: Mount EFI + mount: + src: "{{ vyos_target_drive }}p2" + path: "{{ vyos_install_root }}/boot/efi" + fstype: vfat + state: mounted + - name: Install GRUB in the boot sector of {{ vyos_target_drive }} become: true - command: chroot {{ vyos_install_root }} grub-install --no-floppy --root-directory=/boot {{ vyos_target_drive }} --force --target=i386-pc + command: "chroot {{ vyos_install_root }} grub-install --no-floppy --root-directory=/boot {{ vyos_grub_drive }} --force" args: - creates: "{{ vyos_install_root }}/boot/grub/grubenv" + creates: "{{ vyos_install_root }}/boot/grub/grubenv" + +- name: Install EFI GRUB to {{ vyos_target_drive }}p2 + become: true + command: "chroot {{ vyos_install_root }} grub-install --no-floppy --recheck --target=x86_64-efi --force-extra-removable --root-directory=/boot --efi-directory=/boot/efi --bootloader-id='VyOS' --no-uefi-secure-boot" - name: Configure GRUB become: true @@ -30,3 +43,11 @@ src: templates/boot/grub/grub.cfg.j2 dest: "{{ vyos_write_root }}/boot/grub/grub.cfg" mode: 0644 + +- name: Unmount EFI + mount: + src: "{{ vyos_target_drive }}p2" + path: "{{ vyos_install_root }}/boot/efi" + fstype: vfat + state: absent + diff --git a/roles/install-grub/templates/boot/grub/grub.cfg.j2 b/roles/install-grub/templates/boot/grub/grub.cfg.j2 index 6cfea8f..45aec3b 100644 --- a/roles/install-grub/templates/boot/grub/grub.cfg.j2 +++ b/roles/install-grub/templates/boot/grub/grub.cfg.j2 @@ -7,6 +7,8 @@ set timeout=5 serial --unit=0 terminal_output --append serial terminal_input serial console +insmod efi_gop +insmod efi_uga menuentry "VyOS {{ vyos_version }} for {{ vyos_platform }} (KVM console)" { linux /boot/{{ vyos_version }}/vmlinuz boot=live rootdelay=5 noautologin net.ifnames=0 biosdevname=0 vyos-union=/boot/{{ vyos_version }} console=ttyS0 console=tty0 diff --git a/roles/install-packages/tasks/main.yml b/roles/install-packages/tasks/main.yml index 8d526b5..365d206 100644 --- a/roles/install-packages/tasks/main.yml +++ b/roles/install-packages/tasks/main.yml @@ -3,13 +3,17 @@ apt: update_cache: true name: - - parted + - gdisk + - kpartx + - dosfstools - e2fsprogs - gnupg - qemu-utils - python-lxml - aufs-tools - - grub2 + - grub-efi-amd64 + - grub-efi-amd64-bin + - grub-common - python-requests - unzip - zlib1g-dev diff --git a/roles/setup-root-partition/tasks/main.yml b/roles/setup-root-partition/tasks/main.yml index d6729f2..5ba9cd8 100644 --- a/roles/setup-root-partition/tasks/main.yml +++ b/roles/setup-root-partition/tasks/main.yml @@ -1,27 +1,54 @@ -- name: Partition the target drive +- name: Partition disk become: true - parted: - device: "{{ vyos_target_drive }}" - state: present - label: msdos - number: 1 - part_type: primary - part_start: 0% - part_end: 100% - align: optimal - flags: [boot] + command: + cmd: "sgdisk -a1 -n1:34:2047 -t1:EF02 -n2:2048:+256M -t2:EF00 -n3:0:0:+100% -t3:8300 {{ vyos_raw_img }}" -- name: Create a filesystem on root partition +- name: Create hybrid MBR + become: true + command: + cmd: "sgdisk -h -t1:EF02 -t2:EF00 -t3:8300 {{ vyos_raw_img }}" + +- name: Reread partitions from image and mount to loopback + become: true + command: "kpartx -av {{ vyos_raw_img }}" + +- name: Find the loop device that was used, map to mapper + become: true + shell: "losetup | grep vyos_raw_image.img | head -n1 | awk '{print $1}' | sed 's/dev/dev\\/mapper/g'" + register: result + +- name: Set vyos_target_drive. + set_fact: + vyos_target_drive: "{{ result.stdout }}" + +- name: Pull grub drive + become: true + shell: "losetup | grep vyos_raw_image.img | head -n1 | awk '{print $1}'" + register: result + +- name: Set vyos_grub_drive. + set_fact: + vyos_grub_drive: "{{ result.stdout }}" + +- name: Create a fileystem on EFI partition + become: true + filesystem: + fstype: "vfat" + device: "{{ vyos_target_drive }}p2" + opts: "-n EFI -F 32 -s 1" + + +- name: Create a fileystem on root partition become: true filesystem: fstype: "{{ vyos_root_fstype }}" - device: "{{ vyos_target_drive }}" + device: "{{ vyos_target_drive }}p3" opts: "-L persistence" - name: Mount root partition become: true mount: name: "{{ vyos_write_root }}" - src: "{{ vyos_target_drive }}" + src: "{{ vyos_target_drive }}p3" fstype: "{{ vyos_root_fstype }}" state: mounted diff --git a/roles/unmount-all/tasks/main.yml b/roles/unmount-all/tasks/main.yml index 253ffe9..98d4cdd 100644 --- a/roles/unmount-all/tasks/main.yml +++ b/roles/unmount-all/tasks/main.yml @@ -40,9 +40,9 @@ fstype: "{{ vyos_root_fstype }}" state: absent -- name: Detach {{ vyos_target_drive }} +- name: Remove image partitions become: true - command: "losetup -d {{ vyos_target_drive }}" + command: "kpartx -dv {{ vyos_raw_img }}" - name: Unmount {{ vyos_cd_squash_root }} become: true diff --git a/vagrant-libvirt.yml b/vagrant-libvirt.yml index e5b9f8a..7be24d6 100644 --- a/vagrant-libvirt.yml +++ b/vagrant-libvirt.yml @@ -15,7 +15,6 @@ - mount-iso - get-version - create-disk - - attach-loop-device - setup-root-partition - install-image - mount-root-fs @@ -18,7 +18,6 @@ - mount-iso - get-version - create-disk - - attach-loop-device - setup-root-partition - install-image - mount-root-fs |