用qemu搭建Ubuntu|用qemu搭建Ubuntu Cloud

搭建Ubuntu Cloud qemu启动ubuntu 分两种:uefi和正常启动
https://gist.github.com/george-hawkins/16ee37063213f348a17717a7007d2c79
https://gist.github.com/tpaskhalis/1e601200da499508f9a8502493091f52
【用qemu搭建Ubuntu|用qemu搭建Ubuntu Cloud】默认方式无法登陆的,用ssh有两种方式将公钥传递给vm,一种是mount img再复制,另一种是
在cloud.txt中写入
方法一

$ whoami ghawkins $ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... $ cat > cloud.txt << EOF #cloud-config users: - name: ghawkins ssh-authorized-keys: - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... sudo: ['ALL=(ALL) NOPASSWD:ALL'] groups: sudo shell: /bin/bash EOF $ cloud-localds cloud.img cloud.txt

方法二
# Instructions for working with QEMU image come from # https://www.kumari.net/index.php/system-adminstration/49-mounting-a-qemu-image1. Download image http://cloud-images.ubuntu.com/ 2. Install qemu, nbd-client 3. Load the module sudo modprobe nbd max_part=8 4. Connect image sudo qemu-nbd --connect=/dev/nbd0 Downloads/xenial-server-cloudimg-amd64-disk1.img 5. Mount image sudo mount /dev/nbd0p1 /mnt/cd 6. Add the content of ~/.ssh/id_rsa.pub to /mnt/cd/home/ubuntu/.ssh/authorized_keys 7. Unmount image sudo umount /mnt/cd 8. Disconnect the image sudo nbd-client -d /dev/nbd0

增加img大小 默认的文件系统超级小,所以要增加
https://help.ubuntu.com/community/UEC/Images
## Install a necessary packages $ sudo apt-get install kvm cloud-utils genisoimage ## URL to most recent cloud image of 12.04 $ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release" $ img_url="${img_url}/ubuntu-12.04-server-cloudimg-amd64-disk1.img" ## download the image $ wget $img_url -O disk.img.dist## Create a file with some user-data in it $ cat > my-user-data <

    推荐阅读