qemu 启动 debian 虚拟机
debian linux env:
- insatll qemu:
apt install qemu-utils qemu-system-x86
- install cloud-image-utils
apt-get install cloud-image-utils
- doload debian qcow2: wiki.debian.org/DebianStabl...
1. 创建 秘钥对
bash
ssh-keygen -t rsa -b 4096 -f id_rsa -C test1 -N "" -q
2. 创建 cloud config 种子镜像
bash
▶ cat cloud_init.cfg #cloud-config
hostname: test1
fqdn: test1.example.com
manage_etc_hosts: true
users:
- name: debian
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users, admin
home: /home/debian
shell: /bin/bash
lock_passwd: false
ssh_pwauth: false
disable_root: false
chpasswd:
list: |
debian:linux
expire: False
chpasswd:
list: |
root:root
expire: False
packages:
- qemu-guest-agent
# written to /var/log/cloud-init-output.log
final_message: "The system is finally up, after $UPTIME seconds"
生成 cloud config 镜像
bash
cloud-localds -v cloud-cfg.img cloud_init.cfg
3. 启动 vm
bash
qemu-system-x86_64 \
-name test1 \
-m 2048 \
-smp 2 \
-boot menu=on \
-drive file=debian.qcow2,format=qcow2,if=virtio \
-drive file=cloud-cfg.img,format=raw,if=virtio,media=cdrom \
-nographic \
-vnc :0 \
-netdev user,id=tap0 \
-device virtio-net-pci,netdev=tap0