前言
debian官网的qcow2镜像不设置便无法登录,且根分区只有2G的大小,这里扩容到10G 默认需要使用cloud-init来设置账户密码,这里提供几种其他修改root账号密码的方法
1 2 3 4 sudo apt install qemu-utils libguestfs-toolswget https://cloud.debian.org/images/cloud/buster/20200511-260/debian-10-generic-arm64-20200511-260.qcow2 qemu-img resize debian-10-generic-arm64-20200511-260.qcow2 +8G
QEMU方案 1 2 3 4 5 6 7 8 9 10 11 modprobe nbd max_part=8 qemu-nbd -c /dev/nbd0 /home/pi/debian-10-generic-arm64-20200511-260.qcow2 mount /dev/nbd0p1 /mnt/ chroot /mnt/ /bin/bash -l passwd root systemctl disable cloud-init-local cloud-init cloud-config cloud-final umount /mnt/ qemu-nbd -d /dev/nbd0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 virt-customize -a debian-10-generic-arm64-20200511-260.qcow2 --root-password password:root openssl passwd -1 YouPassword guestfish --rw -a debian-10-generic-arm64-20200511-260.qcow2 ><fs> run ><fs> list-filesystems /dev/sda1: ext4 ><fs> mount /dev/sda1 / ><fs> vi /etc/shadow
Cloud-init方案 1 2 3 4 5 6 7 8 9 10 11 12 13 default_user: name: debian lock_passwd: False plain_text_passwd: 'debian' gecos: Debian groups : [adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo , video] sudo : ["ALL=(ALL) NOPASSWD:ALL" ] shell: /bin/bash ssh_pwauth: 1
启动镜像 1 2 3 4 5 6 7 8 9 10 11 12 sudo apt install qemu-system-arm qemu-efi-aarch64 seabios vgabiossudo qemu-system-aarch64 \-M virt -smp 4 -m 1024 -cpu host -enable-kvm \ -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd \ -device ramfb -device qemu-xhci,id =xhci \ -device usb-kbd -device usb-tablet -k en-us \ -device virtio-blk,drive=system \ -drive if =none,id =system,cache=unsafe,media=disk,file=debian.qcow2 \ -device virtio-net,disable-legacy=on,netdev=net0 \ -netdev user,id =net0,hostfwd=tcp::2222-:22 -vnc :0