diff --git a/Documentation/config-drive.md b/Documentation/config-drive.md new file mode 100644 index 0000000..ef4c9bf --- /dev/null +++ b/Documentation/config-drive.md @@ -0,0 +1,30 @@ +# Distribution via Config Drive + +CoreOS supports providing configuration data via [config drive][config-drive] +disk images. Currently only providing a single script or cloud config file is +supported. + +[config-drive]: http://docs.openstack.org/user-guide/content/enable_config_drive.html#config_drive_contents + +## Contents and Format + +The image should be a single FAT or ISO9660 file system with the label +`config-2` and the configuration data should be located at +`openstack/latest/user_data`. + +For example, to wrap up a config named `user_data` in a config drive image: + + mkdir -p /tmp/new-drive/openstack/latest + cp user_data /tmp/new-drive/openstack/latest/user_data + mkisofs -R -V config-2 -o configdrive.iso /tmp/new-drive + rm -r /tmp/new-drive + +## QEMU virtfs + +One exception to the above, when using QEMU it is possible to skip creating an +image and use a plain directory containing the same contents: + + qemu-system-x86_64 \ + -fsdev local,id=conf,security_model=none,readonly,path=/tmp/new-drive \ + -device virtio-9p-pci,fsdev=conf,mount_tag=config-2 \ + [usual qemu options here...] diff --git a/units/90-configdrive.rules b/units/90-configdrive.rules new file mode 100644 index 0000000..3bfea06 --- /dev/null +++ b/units/90-configdrive.rules @@ -0,0 +1,11 @@ +# Automatically trigger configdrive mounting. + +ACTION!="add|change", GOTO="coreos_configdrive_end" + +# A normal config drive. Block device formatted with iso9660 or fat +SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="iso9660|vfat", ENV{ID_FS_LABEL}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="configdrive-block.service" + +# Addtionally support virtfs from QEMU +SUBSYSTEM=="virtio", DRIVER=="9pnet_virtio", ATTR{mount_tag}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="configdrive-virtfs.service" + +LABEL="coreos_configdrive_end" diff --git a/units/configdrive-block.service b/units/configdrive-block.service new file mode 100644 index 0000000..1d5dc94 --- /dev/null +++ b/units/configdrive-block.service @@ -0,0 +1,15 @@ +[Unit] +Description=Mount config drive +Conflicts=configdrive-virtfs.service umount.target +ConditionPathIsMountPoint=!/media/configdrive +# Only mount config drive block devices automatically in virtual machines +ConditionVirtualization=vm + +# OpenStack defined config drive so they get to stick their name in it +Wants=user-cloudinit@media-configdrive-openstack-latest-user_data.service +Before=user-cloudinit@media-configdrive-openstack-latest-user_data.service + +[Service] +Type=oneshot +RemainAfterExit=no +ExecStart=/bin/mount -t auto -o ro,x-mount.mkdir LABEL=config-2 /media/configdrive diff --git a/units/configdrive-virtfs.service b/units/configdrive-virtfs.service new file mode 100644 index 0000000..1654c24 --- /dev/null +++ b/units/configdrive-virtfs.service @@ -0,0 +1,18 @@ +[Unit] +Description=Mount config drive from virtfs +Conflicts=configdrive-block.service umount.target +ConditionPathIsMountPoint=!/media/configdrive +ConditionVirtualization=vm + +# OpenStack defined config drive so they get to stick their name in it +Wants=user-cloudinit@media-configdrive-openstack-latest-user_data.service +Before=user-cloudinit@media-configdrive-openstack-latest-user_data.service + +# Support old style setup for now +Wants=addon-run@media-configdrive.service addon-config@media-configdrive.service +Before=addon-run@media-configdrive.service addon-config@media-configdrive.service + +[Service] +Type=oneshot +RemainAfterExit=no +ExecStart=/bin/mount -t 9p -o trans=virtio,version=9p2000.L,x-mount.mkdir config-2 /media/configdrive diff --git a/units/system-cloudinit@.service b/units/system-cloudinit@.service new file mode 100644 index 0000000..4788272 --- /dev/null +++ b/units/system-cloudinit@.service @@ -0,0 +1,11 @@ +[Unit] +Description=Load cloud-config from %f +Requires=dbus.service +After=dbus.service +Before=system-config.target +ConditionFileNotEmpty=%f + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/coreos-cloudinit --from-file=%f diff --git a/units/system-config.target b/units/system-config.target new file mode 100644 index 0000000..a510959 --- /dev/null +++ b/units/system-config.target @@ -0,0 +1,10 @@ +[Unit] +Description=Load system-provided cloud configs + +# Generate /etc/environment +Requires=coreos-setup-environment.service +After=coreos-setup-environment.service + +# Load OEM cloud-config.yml +Requires=system-cloudinit@usr-share-oem-cloud\x2dconfig.yml.service +After=system-cloudinit@usr-share-oem-cloud\x2dconfig.yml.service diff --git a/units/user-cloudinit@.service b/units/user-cloudinit@.service new file mode 100644 index 0000000..1bd49a1 --- /dev/null +++ b/units/user-cloudinit@.service @@ -0,0 +1,12 @@ +[Unit] +Description=Load cloud-config from %f +Requires=system-config.target +After=system-config.target +Before=user-config.target +ConditionFileNotEmpty=%f + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=-/etc/environment +ExecStart=/usr/bin/coreos-cloudinit --from-file=%f diff --git a/units/user-config.target b/units/user-config.target new file mode 100644 index 0000000..4f86d4b --- /dev/null +++ b/units/user-config.target @@ -0,0 +1,8 @@ +[Unit] +Description=Load user-provided cloud configs +Requires=system-config.target +After=system-config.target + +# Load user_data placed by coreos-install +Requires=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service +After=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service