Nov 262021
 

这里记录一下简单的过程,后续再完善,已经知道如何操作。

export LIBGUESTFS_BACKEND=direct
export image_name='focal-server-cloudimg-amd64.img' 

virt-customize -a $image_name --run-command 'sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.bak'

virt-customize -a $image_name --run-command 'sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list'

virt-customize -a $image_name --run-command 'sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list'

virt-customize -a $image_name --install qemu-guest-agent
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent'
virt-customize -a $image_name --timezone "Asia/Shanghai" 

virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/PasswordAuthentication no/PasswordAuthentication yes/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#PermitRootLogin prohibit-password/PermitRootLogin yes/'

#zstack
virt-customize -a $image_name --firstboot-command 'sudo /bin/bash -c "$(curl -s -S http://169.254.169.254/vm-tools.sh)"'
virt-customize -a $image_name --firstboot-command "sudo sed -i 's/9100/9104/g' /usr/local/zstack/zwatch-vm-agent/conf.yaml"
virt-customize -a $image_name --firstboot-command "sudo /bin/systemctl restart zwatch-vm-agent.service"
virt-customize -a $image_name --run-command 'mv /usr/lib/virt-sysprep/scripts/0001-sudo--bin-systemctl-restart-zwatch-vm-agent-service /usr/lib/virt-sysprep/scripts/0002-sudo--bin-systemctl-restart-zwatch-vm-agent-service'

#DIB 部分需要调整
export image_name='ubuntu-20.04.qcow2'
export DIB_RELEASE=focal
disk-image-create -a amd64 -o  $image_name -x --image-size 80 vm ubuntu dhcp-all-interfaces

#extend disk
qemu-img info focal-server-cloudimg-amd64.img
virt-filesystems --long --parts --blkdevs -h -a focal-server-cloudimg-amd64.img 
qemu-img resize focal-server-cloudimg-amd64.img +78g
qemu-img info focal-server-cloudimg-amd64.img

 Leave a Reply

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.