Skip to content

Instantly share code, notes, and snippets.

@shettyg
Created May 14, 2018 17:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shettyg/455ff78605ea4c45febe7b5aa345c87d to your computer and use it in GitHub Desktop.
Save shettyg/455ff78605ea4c45febe7b5aa345c87d to your computer and use it in GitHub Desktop.
Ubuntu cloud images and virt-manager
* How to create a Ubuntu VM on your local Ubuntu KVM from Ubuntu cloud images.
1. Get the ubuntu cloud image (.img file from)
mkdir temp; cd temp;
wget http://cloud-images.ubuntu.com/trusty/20140101.55/trusty-server-cloudimg-amd64-disk1.img
2. Create a file "seed"
cat seed
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True
ssh_import_id: kirkland # what is this? kirkland comes from the blog I copied this from
3. Create a "seed.img" from the above
cloud-localds seed.img seed
4. sudo cp trusty-server-cloudimg-amd64-disk1.img /var/lib/libvirt/images/
5. sudo cp seed.img /var/lib/libvirt/images/
sudo apt-get install virt-manager -y
6. tell libvirt to re-scan for new files
virsh pool-refresh default
7. Create a copy of your img.
sudo virsh vol-clone --pool default trusty-server-cloudimg-amd64-disk1.img test.img
virsh pool-refresh default
8. sudo virt-manager
a) New -> Give a name
b) Choose "local install media" (iso or cdrom)
c) Locate your install media -> "use iso image" -> "seed.img"
d) select mem and cpu.
e) enable storage for this VM -> choose existing storage -> test.img
finish
9. username: ubuntu ; password = passw0rd
10. After a reboot, the seed.img is no longer in cdrom, so you will not be able to login
So you need to edit the VM config to add a CDROM and then add seed.img in it.
This will makesure that a reboot will let you login.
@JanSoderback
Copy link

Since this is the first google result for "virt-manager install ubuntu cloud image" I feel like I should point out what the ssh_import_id parameter is for: it imports one or more public SSH keys from a Launchpad.net (default or with "lp:" prefix) or Github.com (with "gh:" prefix) user account. You can log in via ssh using those keys instead of a password.

So if you set ssh_import_id to "kirkland" it will add the public keys of Launchpad user kirkland (who is an Ubuntu developer) to the default user's $HOME/.ssh/authorized_keys file. This allows him to log in to your VM without a password. Probably not what you want!

Note: only guaranteed to work with official Ubuntu images. Also supposed to work with some Debian, Alpine, and Google Container OS images, but I haven't tried. The ssh-import-id command has to be installed in the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment