Debian 11 (bullseye) Cloud Image Initialization
Linux Cloud Image (fedora/debian/ubuntu) Initialization use guestfs-tools
1. INSTALL GUESTFS TOOLS
# debian
apt install libguestfs-tools
# fedora
dnf install guestfs-tools
2. GET IMAGES
# Debian 11
wget https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2
wget https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
# Ubuntu
wget https://mirrors.ustc.edu.cn/ubuntu-cloud-images/focal/current/focal-server-cloudimg-amd64.img
wget https://mirrors.ustc.edu.cn/ubuntu-cloud-images/focal/current/SHA256SUMS
# Fedora 35
wget https://mirrors.ustc.edu.cn/fedora/releases/35/Cloud/x86_64/images/Fedora-Cloud-Base-35-1.2.x86_64.qcow2
wget https://mirrors.ustc.edu.cn/fedora/releases/35/Cloud/x86_64/images/Fedora-Cloud-35-1.2-x86_64-CHECKSUM
# Capacity expansion images
qemu-img resize debian-12-nocloud-amd64.qcow2 +12G
3. DEBIAN IMAGES
sudo virt-customize -a debian-11-generic-amd64.qcow2 --timezone "Asia/Shanghai" \
--root-password password:debian \
--run-command "ssh-keygen -A" \
--run-command "mkdir -pm 700 /root/.ssh/" \
--upload ~/ssh/id_rsa:/root/.ssh/id_rsa \
--upload ~/ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
--ssh-inject root:file:ssh/id_rsa.pub
sudo virt-customize -a debian-11-generic-amd64.qcow2 \
--run-command "mv /etc/apt/mirrors/debian.list /etc/apt/mirrors/debian.list.bak" \
--run-command "mv /etc/apt/mirrors/debian-security.list /etc/apt/mirrors/debian-security.list.bak" \
--run-command "echo 'https://mirrors.ustc.edu.cn/debian' > /etc/apt/mirrors/debian.list" \
--run-command "echo 'https://mirrors.ustc.edu.cn/debian-security' > /etc/apt/mirrors/debian-security.list"
sudo virt-customize -a debian-11-generic-amd64.qcow2 --install vim-tiny,wget,curl,ifupdown,net-tools,tree
4. UBUNTU IMAGES
sudo virt-customize -a ubuntu-server-cloudimg-amd64.img --run-command "echo 'network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: no
addresses:
- 10.42.0.221/24
gateway4: 10.42.0.1
nameservers:
addresses: [192.168.31.64, 114.114.114.114]' > /etc/netplan/01-netcfg.yaml" \
--run-command "netplan apply" \
--run-command "mv /etc/apt/sources.list /etc/apt/sources.list.bak" \
--run-command "echo 'deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse' > /etc/apt/sources.list "
sudo virt-customize -a ubuntu-server-cloudimg-amd64.img --install vim,wget,curl,net-tools,cloud-initramfs-growroot
sudo virt-customize -a ubuntu-server-cloudimg-amd64.img --firstboot-command "resize2fs /dev/vda1"
5. FEDORA IMAGES
sudo virt-customize -a Fedora-Cloud-Base-35-1.2.x86_64.qcow2 --timezone "Asia/Shanghai" \
--root-password password:debian \
--selinux-relabel \
--run-command "sed -i 's/^SELINUX=enforcing/SELINUX=disable/g' /etc/selinux/config" \
--run-command "sed -i '/^#PermitRootLogin/a PermitRootLogin yes' /etc/ssh/sshd_config" \
--run-command "mkdir -pm 700 /root/.ssh/" \
--ssh-inject root:file:rb2.id_rsa.pub \
--upload ~/ssh/id_rsa:/root/.ssh/id_rsa \
--upload ~/ssh/id_rsa.pub:/root/.ssh/id_rsa.pub
sudo virt-customize -a Fedora-Cloud-Base-35-1.2.x86_64.qcow2 --run-command "
sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.ustc.edu.cn/fedora|g' \
-i.bak \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-modular.repo \
/etc/yum.repos.d/fedora-updates.repo \ji
/etc/yum.repos.d/fedora-updates-modular.repo" \
--run-command "dnf makecache"