xref: /cloud-hypervisor/test_data/cloud-init/ubuntu/ci/user-data (revision 07d1208dd53a207a65b649b8952780dfd0ca59d9)
1#cloud-config
2users:
3  - name: cloud
4    passwd: $6$7125787751a8d18a$sHwGySomUA1PawiNFWVCKYQN.Ec.Wzz0JtPPL1MvzFrkwmop2dq7.4CYf03A5oemPQ4pOFCCrtCelvFBEle/K.
5    sudo: ALL=(ALL) NOPASSWD:ALL
6    lock_passwd: False
7    inactive: False
8    shell: /bin/bash
9
10ssh_pwauth: True
11
12runcmd:
13  - [ systemctl, daemon-reload]
14  - [ systemctl, enable, notify-booted.service]
15  - [ systemctl, start, --no-block, notify-booted.service ]
16
17write_files:
18  -
19    path: /etc/systemd/system/vfio.service
20    permissions: 0644
21    content: |
22        [Unit]
23        Description=VFIO test systemd service
24
25        [Service]
26        Type=simple
27        ExecStart=/bin/bash /usr/bin/cloud-hypervisor-vfio.sh
28
29        [Install]
30        WantedBy=multi-user.target
31
32  -
33    path: /usr/bin/cloud-hypervisor-vfio.sh
34    permissions: 0755
35    content: |
36        #!/bin/bash
37
38        mount /dev/vdc /mnt
39        bash -c "echo 1af4 1042 > /sys/bus/pci/drivers/vfio-pci/new_id"
40        bash -c "echo 0000:00:05.0 > /sys/bus/pci/devices/0000\:00\:05.0/driver/unbind"
41        bash -c "echo 0000:00:05.0 > /sys/bus/pci/drivers/vfio-pci/bind"
42        bash -c "echo 1af4 1041 > /sys/bus/pci/drivers/vfio-pci/new_id"
43        bash -c "echo 0000:00:07.0 > /sys/bus/pci/devices/0000\:00\:07.0/driver/unbind"
44        bash -c "echo 0000:00:07.0 > /sys/bus/pci/drivers/vfio-pci/bind"
45        bash -c "echo 0000:00:08.0 > /sys/bus/pci/devices/0000\:00\:08.0/driver/unbind"
46        bash -c "echo 0000:00:08.0 > /sys/bus/pci/drivers/vfio-pci/bind"
47        # 1G ram requires 512 pages
48        echo 512 | sudo tee /proc/sys/vm/nr_hugepages
49        sudo chmod a+rwX /dev/hugepages
50        /mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules root=/dev/vda1 VFIOTAG" --disk path=/mnt/focal-server-cloudimg-amd64-custom-20210609-0.raw --disk path=/mnt/cloudinit.img --cpus boot=1 --memory size=512M,hotplug_size=1G,hugepages=on --device path=/sys/bus/pci/devices/0000:00:05.0/ --device path=/sys/bus/pci/devices/0000:00:07.0/ --device path=/sys/bus/pci/devices/0000:00:08.0/ --api-socket /tmp/ch_api.sock
51
52  -
53    path: /etc/systemd/system/notify-booted.service
54    permissions: 0644
55    content: |
56        [Unit]
57        Description=Notify the tcp listener on the host that the guest is booted
58        After=sshd.service
59
60        [Service]
61        Type=simple
62        ExecStart=/usr/bin/cloud-hypervisor-notify-booted.sh
63        Restart=on-failure
64        RestartSec=2
65
66        [Install]
67        WantedBy=multi-user.target
68
69  -
70    path: /usr/bin/cloud-hypervisor-notify-booted.sh
71    permissions: 0755
72    content: |
73        #!/bin/bash
74        set -e
75
76        echo -n "@DEFAULT_TCP_LISTENER_MESSAGE" > /dev/tcp/@HOST_IP/@TCP_LISTENER_PORT
77