https://cloudinit.readthedocs.io/en/latest/topics/modules.htm
https://cloudinit.readthedocs.io/en/latest/topics/examples.html
安装工具:
apt-get install cloud-init
使用cloud-localds命令生成一个seed.img , 然后在virt-install qcow2 image 的时候同时指定这个seed.img
即 把初始化镜像时的自定义修改放到seed.img中, 然后将它作为一个参数传给kvm 。
cloud-localds seed.img user-data meta-data
这个命令是指user-data meta-data 中的配置加载到seed.img ,并生成seed.img 。 所以首先我们要编辑user-data meta-data 。格式与yaml相同。用法参见https://cloudinit.readthedocs.io/en/latest/topics/examples.html
注意,write file 是生成新文件,会覆盖。如要修改已有文件的个别部分,应该修改后的全文贴入对应部分
生成seed.img 之后,virt-install 时加上--disk path=/vob/cloud-init/seed.img,bus=virtio,format=raw
qemu-img resize xxxx.qcow2 +30G virt-install -d --connect qemu:///system --name casa-mobile-a -r 61440 --vcpus 4 --cpu host \ --disk path=/vob/cloud-init/xxxxxxx.qcow2,format=qcow2,bus=virtio --import \ --disk path=/vob/cloud-init/seed.img,bus=virtio,format=raw \ --autostart --noautoconsole
user-data 的一个示例,必须是以#cloud-config 开头
还可用于修改root 密码之类的变更,用passwd 。
写入新文件用write_file
执行命令用run_cmd
各种定义初始化更改,可在https://cloudinit.readthedocs.io/en/latest/topics/examples.html中找到。
#cloud-config # vim: syntax=yaml # # This is the configuration syntax that the write_files module # will know how to understand. encoding can be given b64 or gzip or (gz+b64). # The content will be decoded accordingly and then written to the path that is # provided. # # Note: Content strings here are truncated for example purposes. write_files: - encoding: b64 content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4... owner: root:root path: /etc/sysconfig/selinux permissions: '0644' - content: | # My new /etc/sysconfig/samba file SMBDOPTIONS="-D" path: /etc/sysconfig/samba
No Leanote account? Sign up now.