5

I am booting cirros VMs outside of an Openstack environment using libvirt. At boot, the VM checks for metadata twenty times, which adds a lot of latency to the boot time.

cirros-ds 'net' up at 6.14
checking http://169.254.169.254/2009-04-04/instance-id failed 1/20: up 6.18. request failed failed 2/20: up 18.32. request failed failed 3/20: up 30.38. request failed failed 4/20: up 42.44. request failed [snip]

I'm using cirros-0.3.3.

Can I use cloud-init or some other mechanism to disable the metadata lookup?

2
  • Please do keep in mind that if this question is considered to be concerning a non-Production use case, it will likely end up closed as off-topic here on ServerFault.
    – Magellan
    Nov 22, 2014 at 15:30
  • I understand how some might view this as a development/test question. Let me provide an example of a production use case. Using cirros as a "pinger VM" to measure VM to VM, host to host, or rack to rack latency/jitter/packet delivery. If these VMs are spun up dynamically to obtain a measurement ASAP, you wouldn't need the metadata service and you probably wouldn't want to set-up an HTTP server to send metadata. The VM's boot time is vital and any optimizations are helpful. Nov 24, 2014 at 18:46

4 Answers 4

2

I was able to answer my own question after a few days of research. You must pass "ds=nocloud" as a kernel option to the VM.

Here's how I did it.


#!/bin/sh

export VM_NAME=cirros$$
IMAGES_BASE=/var/lib/libvirt/images
cp $IMAGES_BASE/cirros/cirros-0.3.0-i386-blank.img $IMAGES_BASE/$VM_NAME.img

virt-install -r 256 \
  -n $VM_NAME \
  --vcpus=1 \
  --import \
  --autostart \
  --memballoon virtio \
  --network bridge=virbr0 \
  --boot kernel=$IMAGES_BASE/cirros/cirros-0.3.0-i386-vmlinuz,initrd=$IMAGES_BASE/cirros/cirros-0.3.0-i386-initrd,kernel_args="console=/dev/ttyS0 ds=nocloud" \
  --disk $IMAGES_BASE/$VM_NAME.img \
  --noautoconsole

The kernel, initrd, and blank image are contained in the UEC versions of cirros on the download page.

UPDATE - Another method is to edit /etc/cirros-init/config. Change the DATASOURCE_LIST variable. This method requires updating the VM image so I prefer using the kernel args method. The file /etc/cirros-init/config exists in cirros-0.3.3 but not cirros-0.3.0. I didn't check other versions.

1

One option will be to start the VM -> Set DATASOURCE_LIST="nocloud" in /etc/cirros-init/config -> Stop the VM and use the new image file as a reference for future VMs to be deployed.

0

I find the way here:proxmox-cirros

root@node1:/var/lib/libvirt/images/cirros01# cat cirros.meta 
{
"instance-id": "10",
"local-hostname": "cirrabc"
}
root@node1:/var/lib/libvirt/images/cirros01# cat cirros.user 
#!/bin/sh
echo DATASOURCE_LIST="nocloud" > /etc/cirros-init/config
root@node1:/var/lib/libvirt/images/cirros01# 

install vm

virt-install \
  --name cirros01 \
  --vcpus 1 \
  --memory 256 \
  --disk path=/var/lib/libvirt/images/cirros01/cirros-0.6.2-x86_64-disk.img \
  --os-variant cirros0.5.2 \
  --import \
  --autostart \
  --noautoconsole \
  --cloud-init user-data="cirros.user",meta-data="cirros.meta"
root@node1:/var/lib/libvirt/images/cirros01# virt-install \
  --name cirros01 \
  --vcpus 1 \
  --memory 256 \
  --disk path=/var/lib/libvirt/images/cirros01/cirros-0.6.2-x86_64-disk.img \
  --os-variant cirros0.5.2 \
  --import \
  --autostart \
  --noautoconsole \
  --cloud-init user-data="cirros.user",meta-data="cirros.meta"

Starting install...
Creating domain...                                                                                                                                                                   |    0 B  00:00:00     
Domain creation completed.
(reverse-i-search)`console': virt-install   --name cirros01   --vcpus 1   --memory 256   --disk path=/var/lib/libvirt/images/cirros01/cirros-0.6.2-x86_64-disk.img   --os-variant cirros0.5.2   --import   --autostart   --noauto^Cnsole   --cloud-init user-data="cirros.user",meta-data="cirros.meta"
root@node1:/var/lib/libvirt/images/cirros01# virsh console cirros01 
Connected to domain 'cirros01'
Escape character is ^] (Ctrl + ])
[    3.883621] rtc_cmos 00:04: alarms up to one day, y3k, 242 bytes nvram
[    3.891612] i2c_dev: i2c /dev entries driver
[    3.894729] device-mapper: core: CONFIG_IMA_DISABLE_HTABLE is disabled. Duplicate IMA measurements will not be recorded in the IMA log.
[    3.904391] device-mapper: uevent: version 1.0.3
[    3.907886] device-mapper: ioctl: 4.45.0-ioctl (2021-03-22) initialised: [email protected]
[    3.913469] usb 1-1: New USB device found, idVendor=0627, idProduct=0001, bcdDevice= 0.00
[    3.918911] usb 1-1: New USB device strings: Mfr=1, Product=3, SerialNumber=10
[    3.924587] usb 1-1: Product: QEMU USB Tablet
[    3.927905] usb 1-1: Manufacturer: QEMU
[    3.930852] usb 1-1: SerialNumber: 28754-0000:00:05.7-1
[    3.936825] platform eisa.0: Probing EISA bus 0
[    3.940526] platform eisa.0: EISA: Cannot allocate resource for mainboard
[    3.945545] platform eisa.0: Cannot allocate resource for EISA slot 1
[    3.949802] platform eisa.0: Cannot allocate resource for EISA slot 2
[    3.954222] platform eisa.0: Cannot allocate resource for EISA slot 3
[    3.959725] platform eisa.0: Cannot allocate resource for EISA slot 4
[    3.965202] platform eisa.0: Cannot allocate resource for EISA slot 5
[    3.972678] platform eisa.0: Cannot allocate resource for EISA slot 6
[    3.976898] platform eisa.0: Cannot allocate resource for EISA slot 7
[    3.981760] platform eisa.0: Cannot allocate resource for EISA slot 8
[    3.986244] platform eisa.0: EISA: Detected 0 cards
[    3.989781] intel_pstate: CPU model not supported
[    3.993428] ledtrig-cpu: registered to indicate activity on CPUs
[    3.998071] drop_monitor: Initializing network drop monitor service
[    4.003633] NET: Registered PF_INET6 protocol family
[    4.017224] Segment Routing with IPv6
[    4.019896] In-situ OAM (IOAM) with IPv6
[    4.022853] NET: Registered PF_PACKET protocol family
[    4.026170] Key type dns_resolver registered
[    4.030568] IPI shorthand broadcast: enabled
[    4.033565] sched_clock: Marking stable (3583548280, 446449499)->(4467855208, -437857429)
[    4.039047] registered taskstats version 1
[    4.042058] Loading compiled-in X.509 certificates
[    4.046995] Loaded X.509 cert 'Build time autogenerated kernel key: 2f86ddc308e15dc6b50c79b07e2324bbca0a5704'
[    4.054843] Loaded X.509 cert 'Canonical Ltd. Live Patch Signing: 14df34d1a87cf37625abec039ef2bf521249b969'
[    4.066323] Loaded X.509 cert 'Canonical Ltd. Kernel Module Signing: 88f752e560a1e0737e31163a466ad7b70a850c19'
[    4.072650] blacklist: Loading compiled-in revocation X.509 certificates
[    4.077137] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing: 61482aa2830d0ab2ad5af10b7250da9033ddcef0'
[    4.083946] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (2017): 242ade75ac4a15e50d50c84b0d45ff3eae707a03'
[    4.091586] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (ESM 2018): 365188c1d374d6b07c3c8f240f8ef722433d6a8b'
[    4.098433] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (2019): c0746fd6c5da3ae827864651ad66ae47fe24b3e8'
[    4.105031] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (2021 v1): a8d54bbb3825cfb94fa13c9f8a594a195c107b8d'
[    4.112289] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (2021 v2): 4cf046892d6fd3c9a5b03f98d845f90851dc6a8c'
[    4.120229] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (2021 v3): 100437bb6de6e469b581e61cd66bce3ef4ed53af'
[    4.127329] Loaded X.509 cert 'Canonical Ltd. Secure Boot Signing (Ubuntu Core 2019): c1d57b8f6b743f23ee41f4f7ee292f06eecadfb9'
[    4.134997] zswap: loaded using pool lzo/zbud
[    4.138334] Key type .fscrypt registered
[    4.141358] Key type fscrypt-provisioning registered
[    4.147730] Key type encrypted registered
[    4.151612] AppArmor: AppArmor sha1 policy hashing enabled
[    4.155251] ima: No TPM chip found, activating TPM-bypass!
[    4.158924] Loading compiled-in module X.509 certificates
[    4.163577] Loaded X.509 cert 'Build time autogenerated kernel key: 2f86ddc308e15dc6b50c79b07e2324bbca0a5704'
[    4.170045] ima: Allocated hash algorithm: sha1
[    4.173455] ima: No architecture policies found
[    4.176689] evm: Initialising EVM extended attributes:
[    4.181014] evm: security.selinux
[    4.183438] evm: security.SMACK64
[    4.185775] evm: security.SMACK64EXEC
[    4.188320] evm: security.SMACK64TRANSMUTE
[    4.191121] evm: security.SMACK64MMAP
[    4.193678] evm: security.apparmor
[    4.196189] evm: security.ima
[    4.198477] evm: security.capability
[    4.201035] evm: HMAC attrs: 0x1
[    4.204308] PM:   Magic number: 0:746:744
[    4.207692] RAS: Correctable Errors collector initialized.
[    4.217577] Freeing unused decrypted memory: 2036K
[    4.228177] Freeing unused kernel image (initmem) memory: 3244K
[    4.232435] Write protecting the kernel read-only data: 30720k
[    4.248257] Freeing unused kernel image (text/rodata gap) memory: 2036K
[    4.252972] Freeing unused kernel image (rodata/data gap) memory: 1448K
[    4.326937] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[    4.331177] x86/mm: Checking user space page tables
[    4.400597] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[    4.404726] Run /init as init process

info: initramfs: up at 3.97
[    4.535137] virtio_blk virtio2: [vda] 229376 512-byte logical blocks (117 MB/112 MiB)
currently loaded modules: 8021q 8139cp 8390 9pnet 9pnet_virtio ahci cec drm drm_kms_helper e1000 e1000e failover fb_sys_fops garp hid hid_generic ip6_udp_tunnel ip_tables isofs libahci libcrc32c llc mii mrp ne2k_pci net_failover nls_ascii nls_iso8859_1 nls_utf8 pcnet32 qemu_fw_cfg rc_core sctp stp syscopyarea sysfillrect sysimgblt udp_tunnel usbhid virtio_blk virtio_dma_buf virtio_gpu virtio_input virtio_net virtio_rng virtio_scsi x_tables 
info: copying initramfs to /dev/vda1
info: initramfs loading root from /dev/vda1
info: /etc/init.d/rc.sysinit: up at 5.04
info: container: none
Starting syslogd: OK
currently loaded modules: 8021q 8139cp 8390 9pnet 9pnet_virtio ahci cec drm drm_kms_helper e1000 e1000e failover fb_sys_fops garp hid hid_generic ip6_udp_tunnel ip_tables isofs libahci libcrc32c llc mii mrp ne2k_pci net_failover nls_ascii nls_iso8859_1 nls_utf8 pcnet32 qemu_fw_cfg rc_core sctp stp syscopyarea sysfillrect sysimgblt udp_tunnel usbhid virtio_blk virtio_dma_buf virtio_gpu virtio_input virtio_net virtio_rng virtio_scsi x_tables 
Saving random seed: OK
Starting acpid: OK
mcb [info=/dev/sr0 dev=/dev/sr0 target=tmp unmount=true callback=mcu_drop_dev_arg]: mount '/dev/sr0' '-o,ro' '/tmp/nocloud.mp.tY5JDe'
mcudda: fn=cp dev=/dev/sr0 mp=/tmp/nocloud.mp.tY5JDe : -a /tmp/cirros-ds.W93FYn/nocloud/raw
Starting network: dhcpcd-9.4.1 starting
DUID 00:04:89:58:df:f5:1d:d0:44:2b:86:be:92:d7:ef:55:1d:52
forked to background, child pid 272
OK
Top of dropbear init script
Starting dropbear sshd: OK
GROWROOT: NOCHANGE: partition 1 is size 210911. it cannot be grown
/dev/root resized successfully [took 0.06s]
=== system information ===
Platform: QEMU Standard PC (i440FX + PIIX, 1996)
Container: none
Arch: x86_64
CPU(s): 1 @ na MHz
Cores/Sockets/Threads: 1/1/1
Virt-type: VT-x
RAM Size: 214MB
Disks:
NAME  MAJ:MIN      SIZE LABEL         MOUNTPOINT
sr0    11:0      378880 cidata        
vda   252:0   117440512               
vda1  252:1   107986432 cirros-rootfs /
vda15 252:15    8388608               
=== sshd host keys ===
-----BEGIN SSH HOST KEY KEYS-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCIDBgjq7p1/YBQMkTMkJuzjMB2ZexBqq0IfvwloGk2DTmlum635sY0qwhgkg6YkIr9LcCMFj4CjuDjzDl9Ap8+2rJRR62HV2A1mU9RfGa5tM/62Q0w49F/wkh5k6GKw3uYOBVfpbckEMEC2SUx07m0O4DPT6rn3VXBGwLk+w5cKDOeMvm/IrW/qzvH9NwAmZKrnB6aOunhItUHpErJCMObRB9VQfog83MHMsA2qcnyeqI10uoCCYqmOGv5CTHJMVIEEQUQ2dk2gixFde/hDy4dOM56aO4J4Q/vs3nSqym5FbQHcOdGnnPEJqV4HcGNvYnAlEFamda+421hw8AJ+4DP root@cirrabc
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIhLwkp2lWB4M0s2Iy7oGzAa/0w1lCn9jr7szInA+hLMeSVs3fAZWoK/dElOXq7gtHMIf//M8eWwQL5SVLkujvU= root@cirrabc
-----END SSH HOST KEY KEYS-----
=== network info ===
if-info: lo,up,127.0.0.1,8,,
if-info: eth0,up,,8,fe80::5054:ff:fe90:5bf6/64,
ip-route6:fe80::/64 dev eth0  metric 256 
ip-route6:multicast ff00::/8 dev eth0  metric 256 
=== datasource: nocloud local ===
instance-id: 10
name: N/A
availability-zone: N/A
local-hostname: cirrabc
launch-index: N/A
=== cirros: current=0.6.2 uptime=6.28 ===
=== pinging gateway failed, debugging connection ===
############ debug start ##############
### /etc/init.d/sshd start
Top of dropbear init script
Starting dropbear sshd: remove-dropbear-host-keys already run per instance
FAIL
### ifconfig -a
eth0      Link encap:Ethernet  HWaddr 52:54:00:90:5B:F6  
          inet6 addr: fe80::5054:ff:fe90:5bf6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:798 (798.0 B)  TX bytes:522 (522.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1020 (1020.0 B)  TX bytes:1020 (1020.0 B)

### route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
### cat /etc/resolv.conf
# Generated by dhcpcd
# /etc/resolv.conf.head can replace this line
# /etc/resolv.conf.tail can replace this line
### gateway not found
### pinging nameservers
### uname -a
Linux cirrabc 5.15.0-71-generic #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023 x86_64 GNU/Linux
### lsmod
Module                  Size  Used by    Not tainted
ahci                   45056  0 
libahci                45056  1 ahci
sctp                  393216  2 
libcrc32c              16384  1 sctp
ip6_udp_tunnel         16384  1 sctp
udp_tunnel             20480  1 sctp
ip_tables              32768  0 
x_tables               53248  1 ip_tables
8021q                  36864  0 
garp                   20480  1 8021q
stp                    16384  1 garp
llc                    16384  2 garp,stp
mrp                    20480  1 8021q
nls_utf8               16384  0 
nls_iso8859_1          16384  0 
nls_ascii              16384  0 
isofs                  53248  0 
hid_generic            16384  0 
usbhid                 65536  0 
hid                   151552  2 hid_generic,usbhid
virtio_rng             16384  0 
virtio_gpu             73728  0 
virtio_dma_buf         16384  1 virtio_gpu
drm_kms_helper        311296  1 virtio_gpu
syscopyarea            16384  1 drm_kms_helper
sysfillrect            20480  1 drm_kms_helper
sysimgblt              16384  1 drm_kms_helper
fb_sys_fops            16384  1 drm_kms_helper
cec                    61440  1 drm_kms_helper
rc_core                65536  1 cec
drm                   622592  2 virtio_gpu,drm_kms_helper
virtio_scsi            24576  0 
virtio_net             61440  0 
net_failover           20480  1 virtio_net
failover               16384  1 net_failover
virtio_input           20480  0 
virtio_blk             20480  1 
qemu_fw_cfg            20480  0 
9pnet_virtio           20480  0 
9pnet                  90112  1 9pnet_virtio
pcnet32                45056  0 
8139cp                 40960  0 
mii                    16384  2 pcnet32,8139cp
ne2k_pci               20480  0 
8390                   24576  1 ne2k_pci
e1000e                299008  0 
e1000                 159744  0 
### dmesg | tail
[    4.797275] EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
[    4.803105] EXT4-fs (vda1): mounting ext3 file system using the ext4 subsystem
[    4.826148] EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
[    5.455071] EXT4-fs (vda1): re-mounted. Opts: (null). Quota mode: none.
[    5.492786] EXT4-fs (vda1): re-mounted. Opts: (null). Quota mode: none.
[    5.692271] ISO 9660 Extensions: Microsoft Joliet Level 3
[    5.693523] ISO 9660 Extensions: RRIP_1991A
[    5.798172] 8021q: adding VLAN 0 to HW filter on device eth0
[    6.462167] EXT4-fs (vda1): resizing filesystem from 25600 to 26363 blocks
[    6.462209] EXT4-fs (vda1): resized filesystem to 26363
### tail -n 25 /var/log/messages
Mar 17 18:43:15 cirros syslog.info syslogd started: BusyBox v1.35.0
Mar 17 18:43:15 cirros daemon.info dhcpcd[270]: dhcpcd-9.4.1 starting
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: DUID 00:04:89:58:df:f5:1d:d0:44:2b:86:be:92:d7:ef:55:1d:52
Mar 17 18:43:15 cirros daemon.warn dhcpcd[273]: no interfaces have a carrier
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: eth0: waiting for carrier
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: eth0: carrier acquired
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: eth0: IAID 00:90:5b:f6
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: eth0: adding address fe80::5054:ff:fe90:5bf6
Mar 17 18:43:15 cirros daemon.info dhcpcd[273]: eth0: soliciting an IPv6 router
Mar 17 18:43:16 cirros authpriv.info dropbear[314]: Running in background
Mar 17 18:43:16 cirros daemon.info dhcpcd[273]: eth0: soliciting a DHCP lease
############ debug end   ##############
  ____               ____  ____
 / __/ __ ____ ____ / __ \/ __/
/ /__ / // __// __// /_/ /\ \ 
\___//_//_/  /_/   \____/___/ 
   http://cirros-cloud.net


login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
cirrabc login: 
-1

You might interested in : https://github.com/eprasad/virt-cirros . Virtualization platform friendly cirros image

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .