summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim <kim.sidney@gmail.com>2020-09-17 21:55:56 +0200
committerGitHub <noreply@github.com>2020-09-17 21:55:56 +0200
commit347544107d1cfede98eee4e816e74a9a724a36de (patch)
tree70b14e66826515320bee99fc2f2b28613fdb3fb9
parente025218641378434864f73cf0b7354ce5b97c6a9 (diff)
parent93879fe015cd9a60a94becd923c609376edf777d (diff)
downloadvyos-vm-images-347544107d1cfede98eee4e816e74a9a724a36de.tar.gz
vyos-vm-images-347544107d1cfede98eee4e816e74a9a724a36de.zip
Merge pull request #8 from zdc/bugfixes
Fixes for the images building process
-rw-r--r--roles/install-grub/tasks/main.yml4
-rw-r--r--roles/setup-root-partition/tasks/main.yml30
-rw-r--r--roles/unmount-all/tasks/main.yml11
3 files changed, 18 insertions, 27 deletions
diff --git a/roles/install-grub/tasks/main.yml b/roles/install-grub/tasks/main.yml
index f9cc772..a711b5e 100644
--- a/roles/install-grub/tasks/main.yml
+++ b/roles/install-grub/tasks/main.yml
@@ -1,4 +1,3 @@
-
- name: Create GRUB directory
become: true
file:
@@ -19,7 +18,6 @@
args:
warn: no
-
- name: Mount EFI
mount:
src: "{{ vyos_target_drive }}p2"
@@ -29,7 +27,7 @@
- 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_grub_drive }} --force"
+ command: "chroot {{ vyos_install_root }} grub-install --no-floppy --target=i386-pc --root-directory=/boot {{ loop_device.stdout }} --force"
args:
creates: "{{ vyos_install_root }}/boot/grub/grubenv"
diff --git a/roles/setup-root-partition/tasks/main.yml b/roles/setup-root-partition/tasks/main.yml
index 5ba9cd8..308cf10 100644
--- a/roles/setup-root-partition/tasks/main.yml
+++ b/roles/setup-root-partition/tasks/main.yml
@@ -1,34 +1,21 @@
- name: Partition disk
become: true
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 hybrid MBR
- become: true
- command:
- cmd: "sgdisk -h -t1:EF02 -t2:EF00 -t3:8300 {{ vyos_raw_img }}"
+ cmd: "sgdisk -a1 -n1:34:2047 -t1:EF02 -n2:2048:+256M -t2:EF00 -n3:0:0:+100% -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 }}"
+ shell: "kpartx -av {{ vyos_raw_img }} | awk '{ print $3 }'"
+ register: loop_partitions
-- name: Pull grub drive
+- name: Find loop device path
become: true
- shell: "losetup | grep vyos_raw_image.img | head -n1 | awk '{print $1}'"
- register: result
+ shell: "losetup -l -O NAME,BACK-FILE | awk '{ if (match($2, \"{{ vyos_raw_img }}\")) print $1}'"
+ register: loop_device
-- name: Set vyos_grub_drive.
+- name: Set vyos_target_drive fact
set_fact:
- vyos_grub_drive: "{{ result.stdout }}"
+ vyos_target_drive: "{{ loop_device.stdout | regex_replace('^/dev/(loop.*)$', '/dev/mapper/\\1') }}"
- name: Create a fileystem on EFI partition
become: true
@@ -37,7 +24,6 @@
device: "{{ vyos_target_drive }}p2"
opts: "-n EFI -F 32 -s 1"
-
- name: Create a fileystem on root partition
become: true
filesystem:
diff --git a/roles/unmount-all/tasks/main.yml b/roles/unmount-all/tasks/main.yml
index 98d4cdd..24dfc8c 100644
--- a/roles/unmount-all/tasks/main.yml
+++ b/roles/unmount-all/tasks/main.yml
@@ -36,14 +36,21 @@
become: true
mount:
name: "{{ vyos_write_root }}"
- src: "{{ vyos_target_drive }}"
- fstype: "{{ vyos_root_fstype }}"
state: absent
- name: Remove image partitions
become: true
command: "kpartx -dv {{ vyos_raw_img }}"
+- name: Remove /dev/mapper entries
+ become: true
+ command: "dmsetup remove {{ item }}"
+ with_items: "{{ loop_partitions.stdout_lines }}"
+
+- name: Detach {{ loop_device.stdout }}
+ become: true
+ command: "losetup -d {{ loop_device.stdout }}"
+
- name: Unmount {{ vyos_cd_squash_root }}
become: true
mount: