bifrost/setup/create_bootable_image.yaml
Julia Kreger 5f9e976598 Fixing bootable image creation steps
Corrected steps so an image boots as expected with the grub boot
loader.
2015-03-07 03:30:28 +00:00

63 lines
3.4 KiB
YAML

---
- name: "Extracting the raw disk image"
command: qemu-img convert -O raw "{{http_boot_folder}}/{{deploy_image_filename}}" "{{http_boot_folder}}/{{deploy_image_filename}}.raw"
- name: "Copying Image however with 32k of empty space at the beginning of the file."
command: dd if="{{http_boot_folder}}/{{deploy_image_filename}}.raw" of="{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" seek=64
- name: "Creating Partition Table lining up with the copied file's contents."
shell: echo '32;' | sfdisk "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" -uB -f
- name: "Allocating one of two loopbacks"
command: losetup -f
register: stored_value_loopback_alpha
- name: "Creating loopback connetion to new image file"
command: losetup "{{stored_value_loopback_alpha.stdout}}" "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg"
- name: "Forcing partition table to be re-read"
command: kpartx -v -a "{{stored_value_loopback_alpha.stdout}}"
# Using second loopback as for some reason /dev/mapper does not translate into a chroot cleanly when devfs is mounted
- name: "Allocating second loopback pointing to the initial partition"
command: losetup -f
register: stored_value_loopback_beta
- name: "Binding second loopback to the first partition"
shell: losetup "{{stored_value_loopback_beta.stdout}}" /dev/mapper/$(echo "{{stored_value_loopback_alpha.stdout}}"|cut -f3 -d '/')p1
# TODO parameterize folder name/location
- name: "Ensuring we have a location to mount the disk to"
file: path=/mnt/bootimg state=directory
- name: "Mounting volume on /mnt/bootimg"
command: mount "{{stored_value_loopback_beta.stdout}}" /mnt/bootimg
- name: "Binding /sys into /mnt/bootimg/sys"
command: mount -t sysfs sysfs /mnt/bootimg/sys
- name: "Binding /proc into /mnt/bootimg/proc"
command: mount -t proc proc /mnt/bootimg/proc
- name: "Binding /dev into /mnt/bootimg/dev"
command: mount --bind /dev /mnt/bootimg/dev
# Attempt to identify kernel
#- name: "Identify kernel"
# shell: ls vmlinuz* |cut -f 1 -d ' ' chdir=/mnt/bootimg/boot/
# register: kernel_filename
#- name: "Identify initrd"
# shell: ls initrd* |cut -f 1 -d ' ' chdir=/mnt/bootimg/boot/
# register: initrd_filename
- name: "Disable Grub Prober"
shell: echo "GRUB_DISABLE_OS_PROBER=true" >>/etc/default/grub
- name: "Disable Grub Prober"
shell: echo 'GRUB_TERMIAL="serial console"' >>/etc/default/grub
- name: "Run the grub-install tool"
command: chroot /mnt/bootimg grub-install --boot-directory=/boot --modules="biosdisk part_msdos" "{{stored_value_loopback_alpha.stdout}}"
- name: "Unlink /dev/bootimg/dev"
command: umount /mnt/bootimg/dev
- name: "Unlink /dev/bootimg/proc"
command: umount /mnt/bootimg/proc
- name: "Unlink /dev/bootimg/sys"
command: umount /mnt/bootimg/sys
- name: "Unmounting image"
command: umount /mnt/bootimg
- name: "Detaching second loop device"
command: losetup -d "{{stored_value_loopback_beta.stdout}}"
- name: "Removing partition map"
command: kpartx -v -d "{{stored_value_loopback_alpha.stdout}}"
- name: "Detaching first loop device"
command: losetup -d "{{stored_value_loopback_alpha.stdout}}"
- name: "Moving image to .oldimg"
command: mv "{{http_boot_folder}}/{{deploy_image_filename}}" "{{http_boot_folder}}/{{deploy_image_filename}}.oldimg"
- name: "Moving new image into place"
command: mv "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" "{{http_boot_folder}}/{{deploy_image_filename}}"