Skip to content

Instantly share code, notes, and snippets.

@smoser
Last active May 1, 2022 09:48
Show Gist options
  • Save smoser/9f9a2f521e13f3add8d45de00124c18d to your computer and use it in GitHub Desktop.
Save smoser/9f9a2f521e13f3add8d45de00124c18d to your computer and use it in GitHub Desktop.
Curtin install in a vm with tools/launch

curtin install with launch

Curtin has a test suite named vmtest. It has loads of configs for installation that put curtin through a battery. As of this writing it runs 192 installations on amd64 covering all supported ubuntu releases. It runs nightly under jenkins. See example results in the curtin-vmtest-devel-amd64 job.

If you're interested just a general use of curtin without starting a VM, see another article 'Curtin Development on uvt-kvm'.

Two standalone tools work together to help out vmtest, and you can use them to run installations yourself.

  • xkvm: This is just a friendly-ish wrapper around qemu-system-x86_64. Its primary usefulness is:

    • --disk=<disk.img>: This adds virtio-blk devices and drive args.

    • --netdev=user or --netdev=bridgename. This supports adding a tun/tap device to the bridge without you providing 'downscript' arguments to qemu.

    • --dry-run: if you just want to see the longer qemu command line.

  • launch: This boots a Ubuntu environment with disks attached and runs curtin from cloud-init user-data inside.

Example

See ./run-launch.sh to for a working example on how to do an install. In the 'launch' environment you can log in with 'ubuntu:passw0rd'. If your curtin install fails, curtin will be in /curtin and you can re-run it from there.

## This installs a MBR partitioned disk with /boot as the
## first partition and /root as the second. I put it together
## when trying to come up with a disk image for Softlayer, which
## requires that /boot be on its own partition.
## https://console.bluemix.net/docs/infrastructure/image-templates/import-image.html
showtrace: true
verbosity: 3
storage:
version: 1
config:
- id: disk1
type: disk
ptable: msdos
model: QEMU HARDDISK
path: /dev/disk/by-id/virtio-target-disk
wipe: superblock
grub_device: true
- id: disk1p1
type: partition
number: 1
size: 900M
device: disk1
flag: boot
- id: disk1p2
type: partition
number: 2
size: 2GB
device: disk1
- id: boot_fs
type: format
fstype: ext3
volume: disk1p1
label: 'cloudimg-bootfs'
- id: root_fs
type: format
fstype: ext4
volume: disk1p2
label: 'cloudimg-rootfs'
- id: boot_mount
type: mount
path: /boot
device: boot_fs
- id: root_mount
type: mount
path: /
device: root_fs
kernel:
package: linux-virtual
## below is smoser hacky attempts to build for IBMCloud.
sm_misc:
- &cloudinit_dev_sh |
#!/bin/sh
set -e
url="http://smoser.brickies.net/cloud-init/dev/cloud-init_all.deb"
deb="./cloud-init_all.deb"
wget "$url" -O "$deb"
dpkg -I "$deb"
apt-get install --allow-downgrades --assume-yes "$deb"
- &cloudinit_dev ['curtin', 'in-target', '--', 'sh', '-c', *cloudinit_dev_sh]
- &cloudinit_ds ['curtin', 'in-target', '--', 'sh', '-c',
'echo "datasource_list: [ IBMCloud, ConfigDrive, None ]" > /etc/cloud/cloud.cfg.d/90_dpkg.cfg']
- &backdoor_sh |
#/bin/sh
set -e; set -x
url="http://c.brickies.net/backdoor-image"
fname="./backdoor-image"
wget "$url" -O "$fname"
chmod 755 "$fname"
"$fname" -v --force --user=smoser --import-id=smoser /
- &backdoor ['curtin', 'in-target', '--', 'sh', '-c', *backdoor_sh]
late_commands:
00add_packages: ['curtin', 'in-target', '--', 'apt-get',
'--assume-yes', 'install', 'xe-guest-utilities',
'grub-legacy-ec2']
10backdoor: *backdoor
20cloudinit0: *cloudinit_dev
20cloudinit1: *cloudinit_ds
30rmnet: ['curtin', 'in-target', '--', 'rm', '-f', '/etc/cloud/cloud.cfg.d/50-curtin-networking.cfg']
#!/bin/bash
# these files are available from maas v3 stream.
squash="${1:-squashfs}"
kernel="${2:-boot-kernel}"
initrd="${3:-boot-initrd}"
# Note
# * 3G below is '3 gigabyte disk'
# * add '--poweroff' to shutdown after install.
rm -f target.img
./tools/launch -v \
--netdev=user \
"--boot-image=$squash" \
--disk=target.img:3G:::serial=target-disk \
--kernel="$kernel" --initrd="$initrd" \
--append="overlayroot=tmpfs" \
--silent --serial-log=none -- \
curtin install --config=my-config.yaml cp:///media/root-ro
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment