Support for installing grub into the Ubuntu image

Added support to make partition images that already contain
kernels/ramdisks, bootable via grub.
This commit is contained in:
Julia Kreger 2015-03-06 11:23:38 -05:00
parent a09d4ab15c
commit 47af80f5fa
3 changed files with 52 additions and 0 deletions

View File

@ -14,6 +14,8 @@ deploy_kernel_url: "http://{{ hostvars[inventory_hostname]['ansible_' + network_
deploy_ramdisk_url: "http://{{ hostvars[inventory_hostname]['ansible_' + network_interface]['ipv4']['address'] }}:8080/coreos_production_pxe_image-oem.cpio.gz"
deploy_image_filename: "trusty-server-cloudimg-amd64.img"
deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}"
# Transform boot image is intended for use with the Ubuntu trusty image. It makes the image bootable by ihnstalling Grub.
transform_boot_image: true
node_default_network_interface: eth0
# ipv4_subnet_mask is intended for the static ipv4 address assignments.
ipv4_subnet_mask: 255.255.255.0

View File

@ -0,0 +1,45 @@
---
- name: "Copying Image however with 32k of empty space at the beginning of the file."
command: dd if="{{http_boot_folder}}/{{boot_image}}" of="{{http_boot_folder}}/{{boot_image}}.bootimg" seek=64
- name: "Creating Partition Table lining up with the copied file's contents."
shell: echo '32;' | sfdisk ./test2.img -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}}/{{boot_image}}.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: lopsetup "{{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: "Place grub device file map"
template: src=templates/device.map.j2 of=/mnt/bootimg/boot/grub/device.map
- name: "Binding /dev into /mnt/bootimg/dev"
command: mount --bind /dev /mnt/bootimg/dev
- name: "Make grub configuration"
command: chroot /mnt/bootimg/ grub-mkconfig -o /boot/grub/grub.cfg
- name: "Run the grub-install tool"
command: grub-install --grub-mkdevicemap=/mnt/bootimg/boot/grub/grub.cfg --root-directory=/mnt/bootimg "{{stored_value_loopback_alpha.stdout}}"
- name: "Unlink /dev/bootimg/dev"
command: umount /dev/bootimg/dev
- name: "Unmounting image"
command: umount /dev/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}}/{{boot_image}}" "{{http_boot_folder}}/{{boot_image}}.oldimg"
- name: "Moving new image into place"
command: mv "{{http_boot_folder}}/{{boot_image}}.bootimg" "{{http_boot_folder}}/{{boot_image}}"

View File

@ -250,8 +250,13 @@
- name: "Test if Ubuntu 14.04 server cloud amd64 is present"
local_action: stat path={{ deploy_image }}
register: test_os_image_present
# TODO(Julia) This needs to be entirely variablized and made a toggable setting, or auto-discovered?
# Anything better!
- name: "Download Ubuntu image"
local_action: get_url url=http://cloud-images.ubuntu.com/releases/trusty/release/ubuntu-14.04-server-cloudimg-amd64.tar.gz dest={{ deploy_image }}
when: test_os_image_present.stat.exists == false
- name: "Extract Ubuntu image"
local_action: command tar -xvzf ubuntu-14.04-server-cloudimg-amd64.tar.gz chdir=/httpboot creates=/httpboot/trusty-server-cloudimg-amd64.img
when: test_os_image_present.stat.exists == false
- include: create_bootable_image.yaml
when: when: test_os_image_present.stat.exists == false and transform_boot_image == true