Cloud-init 主要提供实例首次初始化时自定义配置的能力。在导入 Linux 系统镜像前,请确保您的镜像内部已正确安装了 cloud-init 服务。
https://cloud.tencent.com/document/product/213/12587
yum install -y cloud-init vi /etc/cloud/cloud.cfg |
users:
- default
disable_root: 0
ssh_pwauth: 1
datasource_list: [ ConfigDrive, TencentCloud ]
datasource:
ConfigDrive:
dsmode: local
TencentCloud:
metadata_urls: ['http://metadata.tencentyun.com']
cloud_init_modules:
- migrator
- bootcmd
- write-files
- growpart
- resizefs
- set_hostname
- update_hostname
- ['update_etc_hosts', 'once-per-instance']
- rsyslog
- users-groups
- ssh
cloud_config_modules:
- mounts
- locale
- set-passwords
- rh_subscription
- yum-add-repo
- package-update-upgrade-install
- ntp
- timezone
- resolv_conf
- puppet
- chef
- salt-minion
- mcollective
- disable-ec2-metadata
- runcmd
unverified_modules: ['resolv_conf']
cloud_final_modules:
- rightscale_userdata
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message
- power-state-change
system_info:
default_user:
name: root
lock_passwd: false
gecos: Cloud User
groups: [wheel, adm, systemd-journal]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd
cloud-init init --local rm -rf /var/lib/cloud |
清理删除文件后依然在磁盘上对应block块数据 (在分区表中把文件的索引给删除了,物理数据还是依然占用着磁盘上对应的block块的)。
创建一个全0的大文件,占满所有的剩余磁盘空间,再删除达到清理。
dd if=/dev/zero of=/null.dat rm -f /null.dat |
使用qemu-img制作 Linux 镜像qcow2格式
https://cloud.tencent.com/document/product/213/17814
yum install -y qemu-img /usr/local/bin/qemu-img convert -f raw -O qcow2 /dev/vda /data/test.qcow2 |
注意:/data是另一个存储盘(不能是 /dev/vda )
编外:把镜像存储在腾讯云对象存储COS存储桶中
https://cloud.tencent.com/document/product/436/6883
CentOS6.5 wget https://github.com/tencentyun/cosfs/releases/download/v1.0.19/cosfs-1.0.19-centos6.5.x86_64.rpm #CentOS7.0 wget https://github.com/tencentyun/cosfs/releases/download/v1.0.19/cosfs-1.0.19-centos7.0.x86_64.rpm rpm -ivh cosfs-1.0.19-centos7.0.x86_64.rpm #echo BucketName-APPID:SecretId:SecretKey > /etc/passwd-cosfs echo examplebucket-1250000000:AKIDHTVVaVR6e3:PdkhT9e2rZCfy6 > /etc/passwd-cosfs chmod 640 /etc/passwd-cosfs #cosfs BucketName-APPID MountPoint -ourl=http://cos.Region.myqcloud.com -odbglevel=info -oallow_other mkdir -p /mnt/cosfs cosfs examplebucket-1250000000 /mnt/cosfs -ourl=http://cos.ap-guangzhou.myqcloud.com -odbglevel=info -onoxattr -oallow_other cp /data/test.qcow2 /mnt/cosfs/ |
原创文章,作者:cy,如若转载,请注明出处:https://www.cygzs.net/