制作Ubuntu-16.04-amd64 OpenStack镜像cloud-init注意事项




  1. 安装cloud-init
  2. 配置合适的数据源,配置文件位于/etc/cloud/cloud.cfg.d/90_dpkg.cfg,一般配置为[ConfigDrive, Ec2],也就是通过ConfigDrive盘或者Ec2(nova metadata api或者说169.254.169.254接口)数据源来获取云主机配置信息
  3. 根据需要修改cloud-init的配置文件,位于/etc/cloud/cloud.cfg,一般是为了打开root用户的用户名密码登录功能,比如如下配置:
  4. users:
     - default
    disable_root: 0
    apt_preserve_sources_list: true
    ssh_pwauth: 0
    preserve_hostname: False
    # datasource_list: ["NoCloud", "ConfigDrive", "OVF", "MAAS", "Ec2", "CloudStack"]
    
    cloud_init_modules:
     - bootcmd
     - resizefs
     - write-files
     - set_hostname
     - update_hostname
     - update_etc_hosts
     - ca-certs
     - rsyslog
     - ssh
    
    system_info:
       distro: ubuntu
       default_user:
        name: root
        lock_passwd: 0
       paths:
        cloud_dir: /var/lib/cloud
        templates_dir: /etc/cloud/templates
       package_mirrors:
         - arches: [i386, amd64]
           failsafe:
             primary: http://archive.ubuntu.com/ubuntu
             security: http://security.ubuntu.com/ubuntu
           search:
             primary:
               - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
               - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
             security: []
         - arches: [armhf, armel, default]
           failsafe:
             primary: http://ports.ubuntu.com/ubuntu-ports
             security: http://ports.ubuntu.com/ubuntu-ports
    
  5. 修改cloud-init服务启动依赖,这一步是为了防止/etc/network/interfaces里面有多张网卡的dhcp配置,而启动networking服务的时候如果只有一张网卡,就会报服务启动Failed,导致依赖networking服务的cloud-init服务无法启动,修改方式为:注释掉/lib/systemd/system/cloud-init.service文件中的Requires=networking.service这行,也即改为:#Requires=networking.service
  6. /etc/default/grub中GRUB_CMDLINE_LINUX_DEFAULT加上console=tty0 console=ttyS0,115200,用来生成console.log(nova console-log可以获取到)
  7. 网卡名称ensX重置为老版本ethX方法是在上面的配置中继续增加net.ifnames=0 biosdevname=0