Giter Site home page Giter Site logo

giovtorres / kvm-install-vm Goto Github PK

View Code? Open in Web Editor NEW
327.0 13.0 157.0 159 KB

Bash script to build local virtual machines using KVM/libvirt and cloud-init.

License: MIT License

Shell 100.00%
kvm libvirt cloud-init virt-install centos debian fedora ubuntu centos-atomic fedora-atomic

kvm-install-vm's Introduction

kvm-install-vm

A bash wrapper around virt-install to build virtual machines on a local KVM hypervisor. You can run it as a normal user which will use qemu:///session to connect locally to your KVM domains.

Tested on the latest Fedora.

Prerequisites

You need to have the KVM hypervisor installed, along with a few other packages (naming of packages can differ on other distributions):

  • genisoimage or mkisofs
  • virt-install
  • libguestfs-tools-c
  • qemu-img
  • libvirt-client
  • libosinfo

To install the dependencies, run:

  • Fedora example:
sudo dnf -y install genisoimage virt-install libguestfs-tools-c qemu-img libvirt-client wget libosinfo
  • Ubuntu example:
sudo apt install -y genisoimage virtinst libguestfs-tools qemu-utils libvirt-clients wget libosinfo-bin

If you want to resolve guests by their hostnames, install the libvirt-nss package:

  • Fedora example:
sudo dnf -y install libvirt-nss
  • Ubuntu example:
sudo apt install -y libnss-libvirt

Then, add libvirt and libvirt_guest to list of hosts databases in /etc/nsswitch.conf. See here for more information.

Usage

$ kvm-install-vm help
NAME
    kvm-install-vm - Install virtual guests using cloud-init on a local KVM
    hypervisor.

SYNOPSIS
    kvm-install-vm COMMAND [OPTIONS]

DESCRIPTION
    A bash wrapper around virt-install to build virtual machines on a local KVM
    hypervisor. You can run it as a normal user which will use qemu:///session
    to connect locally to your KVM domains.

COMMANDS
    help    - show this help or help for a subcommand
    create  - create a new guest domain
    list    - list all domains, running and stopped
    remove  - delete a guest domain

Creating Guest VMs

$ kvm-install-vm help create
NAME
    kvm-install-vm create [COMMANDS] [OPTIONS] VMNAME

DESCRIPTION
    Create a new guest domain.

COMMANDS
    help - show this help

OPTIONS
    -a          Autostart             (default: false)
    -b          Bridge                (default: virbr0)
    -c          Number of vCPUs       (default: 1)
    -d          Disk Size (GB)        (default: 10)
    -D          DNS Domain            (default: example.local)
    -f          CPU Model / Feature   (default: host)
    -g          Graphics type         (default: spice)
    -h          Display help
    -i          Custom QCOW2 Image
    -k          SSH Public Key        (default: $HOME/.ssh/id_rsa.pub)
    -l          Location of Images    (default: $HOME/virt/images)
    -L          Location of VMs       (default: $HOME/virt/vms)
    -m          Memory Size (MB)      (default: 1024)
    -M          Mac address           (default: auto-assigned)
    -p          Console port          (default: auto)
    -s          Custom shell script
    -t          Linux Distribution    (default: centos8)
    -T          Timezone              (default: US/Eastern)
    -u          Custom user           (default: $USER)
    -y          Assume yes to prompts (default: false)
    -n          Assume no to prompts  (default: false)
    -v          Be verbose

DISTRIBUTIONS
    NAME            DESCRIPTION                         LOGIN
    amazon2         Amazon Linux 2                      ec2-user
    centos8         CentOS 8                            centos
    centos7         CentOS 7                            centos
    centos7-atomic  CentOS 7 Atomic Host                centos
    centos6         CentOS 6                            centos
    debian9         Debian 9 (Stretch)                  debian
    debian10        Debian 10 (Buster)                  debian
    fedora29        Fedora 29                           fedora
    fedora29-atomic Fedora 29 Atomic Host               fedora
    fedora30        Fedora 30                           fedora
    fedora31        Fedora 31                           fedora
    fedora32        Fedora 32                           fedora
    opensuse15      OpenSUSE Leap 15.2                  opensuse
    ubuntu1604      Ubuntu 16.04 LTS (Xenial Xerus)     ubuntu
    ubuntu1804      Ubuntu 18.04 LTS (Bionic Beaver)    ubuntu
    ubuntu2004      Ubuntu 20.04 LTS (Focal Fossa)      ubuntu

EXAMPLES
    kvm-install-vm create foo
        Create VM with the default parameters: CentOS 8, 1 vCPU, 1GB RAM, 10GB
        disk capacity.

    kvm-install-vm create -c 2 -m 2048 -d 20 foo
        Create VM with custom parameters: 2 vCPUs, 2GB RAM, and 20GB disk
        capacity.

    kvm-install-vm create -t debian9 foo
        Create a Debian 9 VM with the default parameters.

    kvm-install-vm create -T UTC foo
        Create a default VM with UTC timezone.

Deleting a Guest Domain

$ kvm-install-vm help remove
NAME
    kvm-install-vm remove [COMMANDS] VMNAME

DESCRIPTION
    Destroys (stops) and undefines a guest domain.  This also remove the
    associated storage pool.

COMMANDS
    help - show this help

EXAMPLE
    kvm-install-vm remove foo
        Remove (destroy and undefine) a guest domain.  WARNING: This will
        delete the guest domain and any changes made inside it!

Attaching a new disk

$ kvm-install-vm help attach-disk
NAME
    kvm-install-vm attach-disk [OPTIONS] [COMMANDS] VMNAME

DESCRIPTION
    Attaches a new disk to a guest domain.

COMMANDS
    help - show this help

OPTIONS
    -d SIZE     Disk size (GB)
    -f FORMAT   Disk image format       (default: qcow2)
    -s IMAGE    Source of disk device
    -t TARGET   Disk device target

EXAMPLE
    kvm-install-vm attach-disk -d 10 -s example-5g.qcow2 -t vdb foo
        Attach a 10GB disk device named example-5g.qcow2 to the foo guest
        domain.

Setting Custom Defaults

Copy the .kivrc file to your $HOME directory to set custom defaults. This is convenient if you find yourself repeatedly setting the same options on the command line, like the distribution or the number of vCPUs.

Options are evaluated in the following order:

  • Default options set in the script
  • Custom options set in .kivrc
  • Option flags set on the command line

Notes

  1. This script will download a qcow2 cloud image from the respective distribution's download site. See script for URLs.

  2. If using libvirt-nss, keep in mind that DHCP leases take some time to expire, so if you create a VM, delete it, and recreate another VM with the same name in a short period of time, there will be two DHCP leases for the same host and its hostname will likely not resolve until the old lease expires.

  3. The Operating System information database (osinfo-db) provides Operating System specific information needed to create guests for the various systems supported by kvm-install-vm. The database files provided by your package manager may be out of date and not provide definitions for recent Operating System versions. If you encounter the following error message, you may need to update the database files: ERR: Unknown OS variant '<name>'. Please update your osinfo-db. If you have already updated your system, and the osinfo-db is still to old, then you can use the osinfo-db-import tool with the --local option, to install an up-to-date database in your home directory which will not conflict with your package manager files. The osinfo-db-import tool is provided by the rpm/deb packages osinfo-db-tools. See https://libosinfo.org/download for more information.

Testing

Tests are written using Bats. To execute the tests, run ./test.sh in the root directory of the project.

Use Cases

If you don't need to use Docker or Vagrant, don't want to make changes to a production machine, or just want to spin up one or more VMs locally to test things like:

  • high availability
  • clustering
  • package installs
  • preparing for exams
  • checking for system defaults
  • anything else you would do with a VM

...then this wrapper could be useful for you.

Troubleshooting

If you will encounter something similar:

ERR: Unknown OS variant 'fedora31'. Please update your osinfo-db.  See https://libosinfo.org/download for more information.

Then you need to update the DB in libosinfo. Check the url and select the latest date ( https://releases.pagure.org/libosinfo/ )

wget -O "/tmp/osinfo-db.tar.xz" https://releases.pagure.org/libosinfo/osinfo-db-20200515.tar.xz
sudo osinfo-db-import --local "/tmp/osinfo-db.tar.xz"

kvm-install-vm's People

Contributors

atomicbeecz avatar bahorn avatar beelzetron avatar berkutta avatar biyiklioglu avatar coopernurse avatar eklitzke avatar frostman avatar giovtorres avatar h--o-l avatar jmcfarlane avatar meffie avatar mmatczuk avatar panic1 avatar pegasusprime avatar pselge-daparto avatar seocam avatar sthaha avatar zasdaym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kvm-install-vm's Issues

Debian 10 cloud-init not properly intializing

I'm facing the issue that debian9 is working perfectly, but debian10 is not working. On debian10 the hostname is not set and also logging in via ssh is not working/enabled. I'm not sure if this is an issue with this script/debian butt image or my local setup.

I'm using Arch Linux with QEMU 4.2.0 / virt-install 2.2.1

Screenshot from 2020-04-13 22-13-29

Beyond spinning up

Thanks for this tool, it seems pretty handy.

I'm not that familiar with using kvm, qemu, and virsh. On Fedora 26 I'm used to having VMs show up in virt-manager for an easy GUI experience. Do you know a way to get VMs created by this tool to show up there?

Also, I'm finding that after shutting them down, when I restart them (virsh start) they don't seem to come up successfully. I can't connect to them via ssh, though a screenshot doesn't show any obvious problems. If they came up with a different IP I'm not sure how to find out what that is. Any advice you can offer?

cloud-init not removed -- runcmd

Hi first off all i love this little script, use it for all my vm creations on kvm.

In your script there is the runcmd which supposedly should remove cloud-init but on my system it does not. When i shutdown the vm and start it again, i see cloud-init is starting all over again. And the boot time is very long.

This is the output from: /var/log/cloud-init.log

2017-11-06 08:05:25,660 - helpers.py[DEBUG]: Running config-runcmd using lock (<FileLock using file '/var/lib/cloud/instances/luckyme/sem/config_runcmd'>)
Cloud-init v. 0.7.9 running 'modules:config' at Mon, 06 Nov 2017 13:05:24 +0000. Up 13.55 seconds.
2017-11-06 08:05:25,660 - util.py[WARNING]: Failed to shellify [['apt-get', '-y', 'remove', 'cloud-init'], None] into file /var/lib/cloud/instances/luckyme/scripts/runcmd
2017-11-06 08:05:25,660 - util.py[WARNING]: Failed to shellify [['apt-get', '-y', 'remove', 'cloud-init'], None] into file /var/lib/cloud/instances/luckyme/scripts/runcmd
2017-11-06 08:05:25,660 - util.py[DEBUG]: Failed to shellify [['apt-get', '-y', 'remove', 'cloud-init'], None] into file /var/lib/cloud/instances/luckyme/scripts/runcmd
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_runcmd.py", line 55, in handle
content = util.shellify(cmd)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1889, in shellify
% (type_utils.obj_name(args)))
RuntimeError: Unable to shellify type NoneType which is not a list or string

How to get root on created instance

Looking through the script, it seems that the default user is supposed to have nopasswd sudo set, but when logging in and issuing any sudo commands, it prompts for a password and does not accept anything (as I'm assuming none have been set). I can get SSHd through root but it displays a warning telling me to log in as centos instead. Seems like I'm probably missing something obvious here, but I just don't get how to get root.

cloud init custom user-data script not picked up

Platform

Hypervisor OS: Ubuntu-18.04
Guest OS: Ubuntu-18.04
kvm-install-vm: latest github version

Goal

I want to add an additional user with a specified password and without NOPASSWD in sudoers. By default kvm-install-vm uses ALL=(ALL) NOPASSWD:ALL for additional users.

Attempt

I tried to create a user-data.sh and run kvm-install-vm create -s "$HOME/user-data.sh" my-vm01, but it seems to have no effect. I can't login with ssh, nor through tty with virt-manager's graphical interface.

My guess is the config is not picked up. What might I be missing?

user-data.sh

# Users
users:
    - default
    - name: my-user
      groups: ['sudo']
      shell: /bin/bash
      sudo: ALL=(ALL) ALL
      ssh-authorized-keys:
        - ssh-ed25519 <my-pub-key>
      lock-passwd: false
      passwd: <my-salted-password-hash>

.kivrc

AUTOSTART=true
CPUS=1
MEMORY=1024
DISK_SIZE=20
IMAGEDIR="/mnt/500g01/virtualbox/image"
VMDIR="/mnt/500g01/virtualbox"
BRIDGE=br2
PUBKEY="${HOME}/.ssh/user01_ed25519.pub"
DISTRO=ubuntu1804
MACADDRESS=$(printf '%02x' $((0x$(od /dev/urandom -N1 -t x1 -An | cut -c 2-) & 0xFE | 0x02)); od /dev/urandom -N5 -t x1 -An | sed 's/ /:/g')
TIMEZONE=Berlin/Europe
VERBOSE=1

Add support to custom list of distros

My use case for kvm-install-vm is to perform test run in multiple versions of a given distro (centos, fedora and rhel). While I don't think it would make sense to create a PR to add centos-1611, centos1811, centos1907, etc., those names are meaningful and helpful in my tests.

For that reason I'd like to suggest that the mapping of distros could be customized in .kvirc or somewhere else.

Thanks!

Disk size default to only 2.1 GB?

New install without specifying disk size and I get a ubuntu instance with only 2.1 GB.

Filesystem      Size  Used Avail Use% Mounted on
udev            238M     0  238M   0% /dev
tmpfs            49M  1.9M   47M   4% /run
/dev/vda1       2.1G  1.5G  574M  73% /
tmpfs           245M     0  245M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           245M     0  245M   0% /sys/fs/cgroup
tmpfs            49M     0   49M   0% /run/user/1000

Can not get an IP address.

Hi,

After run the kvm-install-vm script, it stopped at following step for few hours.

 ⚡ root@fedora  ~/kvm-install-vm   master   ./kvm-install-vm -n kvm0
[03:21:43 PM]----> Copying cloud image (CentOS-7-x86_64-GenericCloud.qcow2)...
[03:22:18 PM]----> Generating ISO for cloud-init...
[03:22:18 PM]----> Creating Storage Pool with the following command:
    virsh pool-create-as \
      --name kvm0 \
      --type dir \
      --target /root/virt/images/kvm0
Pool kvm0 created

[03:22:18 PM]----> Installing the domain and adjusting the configuration...
[03:22:18 PM]----> Installing with the following command:
    virt-install \
      --import \
      --name kvm0 \
      --ram 1024 \
      --vcpus 1 \
      --cpu host \
      --disk kvm0.qcow2,format=qcow2,bus=virtio \
      --disk kvm0-cidata.iso,device=cdrom \
      --network bridge=virbr0,model=virtio \
      --os-type=linux \
      --os-variant=centos7.0 \
      --graphics spice \
      --noautoconsole

Starting install...
Domain creation completed.
[03:22:49 PM]----> Cleaning up cloud-init...
[03:22:49 PM]----> Waiting for domain to get an IP address ...

The additional info:

 ⚡ root@fedora  ~  uname -a
Linux fedora 4.12.9-300.fc26.x86_64 #1 SMP Fri Aug 25 13:09:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
 ⚡ root@fedora  ~  virsh dominfo kvm0
Id:             1
Name:           kvm0
UUID:           0a267f80-c3a4-4e9e-88a0-1530ef03f0a7
OS Type:        hvm
State:          running
CPU(s):         1
CPU time:       1575.5s
Max memory:     1048576 KiB
Used memory:    1048576 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0

 ⚡ root@fedora  ~  virsh domiflist kvm0
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      bridge     virbr0     virtio      52:54:00:93:62:d9

 ⚡ root@fedora  ~  systemctl status dnsmasq.service
● dnsmasq.service - DNS caching server.
   Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-09-09 15:09:24 CST; 33min ago
 Main PID: 861 (dnsmasq)
    Tasks: 1 (limit: 19660)
   CGroup: /system.slice/dnsmasq.service
           └─861 /usr/sbin/dnsmasq -k

Sep 09 15:09:24 fedora systemd[1]: Started DNS caching server..
Sep 09 15:09:24 fedora dnsmasq[861]: started, version 2.76 cachesize 150
Sep 09 15:09:24 fedora dnsmasq[861]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth DNSSEC loop-detect inotify
Sep 09 15:09:24 fedora dnsmasq[861]: read /etc/hosts - 6 addresses
Sep 09 15:09:28 fedora dnsmasq[861]: failed to access /etc/resolv.conf: No such file or directory
Sep 09 15:09:35 fedora dnsmasq[861]: reading /etc/resolv.conf
Sep 09 15:09:35 fedora dnsmasq[861]: using nameserver 192.168.10.2#53
 ⚡ root@fedora  ~ 

vm hostname cant be resolved

Hi Giovanni,

I have create vm by using command "kvm-install-vm create foo", the vm was created, but the host "foo" cant be extracted:

$ ./kvm-install-vm list
 Id    Name                           State
----------------------------------------------------
 6     foo                            running

$ ping foo                                                   
ping: unknown host foo

$cat /etc/nsswitch.conf |grep hosts
hosts:          files libvirt libvirt_guest mdns4_minimal [NOTFOUND=return] dns

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"

I have set the "hosts" options in file /etc/nsswitch.conf as the guide in README.md .

Thanks,
Ayakashi

Could not create domain with virt-install

This is what I try:

[root@lab1 ~]# kvm-install-vm create -c 2 -m 2048 -d 20 -v foo4
- Copying cloud image (CentOS-8-GenericCloud-8.1.1911-20200113.3.x86_64.qcow2) ... OK
- Resizing the disk to 20G ... OK
- Generating ISO for cloud-init ... OK
- Creating storage pool with the following command
    virsh  \
     pool-create-as  \
     --name=foo4  \
     --type=dir  \
     --target=/data/virt/vms/foo4
OK
- Installing the domain with the following command
    virt-install  \
     --import  \
     --name=foo4  \
     --memory=2048  \
     --vcpus=2  \
     --cpu=host  \
     --disk=foo4.qcow2,format=qcow2,bus=virtio  \
     --disk=foo4-cidata.iso  \
     --network=bridge=bridge99,model=virtio  \
     --os-type=linux  \
     --os-variant=centos8  \
     --noautoconsole  \
     --graphics=spice,port=-1,listen=localhost
ERR: Could not create domain with virt-install.

Even with -v, not that much of information. Let's try it manually by copying the command from above:

[root@lab1 ~]#     virt-install  \
>      --import  \
>      --name=foo4  \
>      --memory=2048  \
>      --vcpus=2  \
>      --cpu=host  \
>      --disk=foo4.qcow2,format=qcow2,bus=virtio  \
>      --disk=foo4-cidata.iso  \
>      --network=bridge=bridge99,model=virtio  \
>      --os-type=linux  \
>      --os-variant=centos8  \
>      --noautoconsole  \
>      --graphics=spice,port=-1,listen=localhost
ERROR    Fehler: --disk foo4.qcow2,format=qcow2,bus=virtio: Size must be specified for non existent volume 'foo4.qcow2'

Is it me, using it wrong or is it a bug?

Adding Rocky Linux

Rocky Linux is missing.

I tried to add it myself, to make a pull request. As far as I can tell, it may work, but it's not in the osinfo-db:

ERR: Unknown OS variant 'rocky84'. Please update your osinfo-db.  See https://libosinfo.org/download for more information.

Question: How to proceed? Add an exception?

No need to remove cloud-init

Instead of remove cloud-init, what about disable the cloud-init service only @giovtorres ?

Something like

ln-sf /dev/null /etc/systemd/system/cloud-init.service
#or
systemctl disable cloud-init

Amazon Linux 2 doesn't boot if disk resized

I think this may be the same issue as #20 but for the Amazon Linux 2 image.

If I create a vm with the default disk options it works fine.

If I create a vm with the -d option then it hangs waiting for the IP address. Looking at the console I see:

error: unknown filesystem.
Entering rescue mode...
grub rescue>

I was able to repro this manually by creating a vm with the disk defaults, stopping it, and running virt-resize. After running virt-resize the vm fails to boot with the above error.

I'll try the qemu-img resize workaround and see if that does the trick. If so maybe we should change the if test to include Amazon Linux 2.

ubuntu1804 cannot boot

Hello there,

The ubuntu1804 image does not seem to work. I think it's because the downloaded image is not a drop-in replacement for ubuntu1604. I'm not quite familiar enough with all this to fix - as I attempted to work toward a pull request a few months ago, but ran into this issue (the image for 1804 has extra partitions I think compared to 1604?)

Here is creating a new machine:

$ ./kvm-install-vm create -c 2 -m 2048 -d 10 -t ubuntu1804 -T UTC u1804-test1
- Copying cloud image (ubuntu-18.04-server-cloudimg-amd64.img) ... OK
- Resizing the disk to 10G ... OK
- Generating ISO for cloud-init ... OK
- Creating storage pool ... OK
- Installing the domain ... OK
- Enabling autostart ... OK
- Cleaning up cloud-init files ... OK
- Waiting for domain to get an IP address ... 

This where the failure occurs because the machine cannot boot, here is the console output from the machine:

Booting from Hard Disk...
error: unknown filesystem.
Entering rescue mode...
grub rescue>

I will attempt to add more info in an edit, looking at the u1604 vs u1804 images being used.

Thanks!

start created vm upon reboot

Any way to start the shut off vm through kvm-install-vm command? currently i am starting it by accessing my gnome-boxes...

"kvm-install-vm delete" doesn't work if the VM has snapshots

Steps to reproduce:

  1. Create a vm
  2. Shutshow the vm
  3. Create a snapshot using virsh
  4. Try to remove the vm

Result:

  • The remove command fails with message "ERR: Could not undefine domain."

Expected Result:

  • The VM should be removed.
  • Alternatively: the alert is raised saying that you need to erase snapshots before removing a vm.

Logs:

scampos@cetus:~/src/kvm-install-vm (master)$ ./kvm-install-vm create -i /home/scampos/os-images/cloud/centos7.6/CentOS-7-x86_64-GenericCloud-1811.qcow2 centos7.6
- Using custom QCOW2 image: /home/scampos/os-images/cloud/centos7.6/CentOS-7-x86_64-GenericCloud-1811.qcow2.
- Copying cloud image (CentOS-7-x86_64-GenericCloud-1811.qcow2) ... OK
- Generating ISO for cloud-init ... OK
- Creating storage pool ... OK
- Installing the domain ... OK
- Cleaning up cloud-init files ... OK
- Waiting for domain to get an IP address ... OK

- Checking for 192.168.124.115 in known_hosts file
- No entries found for 192.168.124.115

- SSH to centos7.6: 'ssh <use the default account in your custom image>@192.168.124.115' or 'ssh <use the default account in your custom image>@centos7.6'
- Console at spice://localhost:5901
- DONE

scampos@cetus:~/src/kvm-install-vm (master)$ virsh shutdown centos7.6 
Domain centos7.6 is being shutdown

scampos@cetus:~/src/kvm-install-vm (master)$ virsh snapshot-create-as centos7.6 --name test-snapshot
Domain snapshot test-snapshot created

scampos@cetus:~/src/kvm-install-vm (master)$ ./kvm-install-vm remove centos7.6
- Destroying centos7.6 domain ... (Domain is not running.)
- Undefining centos7.6 domain ... ERR: Could not undefine domain.

scampos@cetus:~/src/kvm-install-vm (master)$ virsh snapshot-delete centos7.6 --children --current
Domain snapshot test-snapshot deleted

scampos@cetus:~/src/kvm-install-vm (master)$ ./kvm-install-vm remove centos7.6
- Destroying centos7.6 domain ... (Domain is not running.)
- Undefining centos7.6 domain ... OK
- Deleting centos7.6 files ... OK
- Destroying centos7.6 storage pool ... OK

Network config alternative

Hi,

First of all, thanks for your work, really nice assembled, (however i'm trying master on a debian host, as a non root user, with all permissions given to libvirt, some vars fail to get assigned properly; i'll open a separate issue for that).
So in the light of the above, i had to cut down to a working solution and also solve static networking.

Wrt networking:

i'm using centos-atomic which at this moment has cloud-init version 18.2 https://cloudinit.readthedocs.io/en/18.2/

I'm adding to the ISO cloud-init image the following yaml file named network-config which gets picked up. Be aware that in cloud-init NoCloud this should NOT be under YAML node networking:
just the: version:1 config: .... works perfectly fine.
Again this is Cloud-Init dependent and works fine in my ATM latest centos atomic.

export NETWORK_CONFIG=/opt/kvm/ci/${VMNAME}/network-config
export CI_ISO=/opt/kvm/images/${VMNAME}-cidata.iso

sudo rm -rf ${NETWORK_CONFIG}
sync
sudo cat > ${NETWORK_CONFIG} << _EOF_
version: 1
config:
    - type: physical
      name: eth0
      mac_address: "${MAC}"
      subnets:
         - type: static
           address: 192.168.0.101
           netmask: 255.255.255.0
           gateway: 192.168.0.1
           network: 192.168.0.0
    - type: nameserver
      address: 
         - 192.168.0.254
      search:
         - mylocaldnsname.dev
_EOF_

sudo genisoimage -output ${CI_ISO} -volid cidata -joliet -rock ${USER_DATA} ${META_DATA} ${NETWORK_CONFIG}

Could not resize disk

I'll try and figure this out myself, but I was wondering if you've encountered an issue with a failure on disk resizing? Here's what I'm seeing:

./kvm-install-vm create ovirtnode2
- Copying cloud image (CentOS-7-x86_64-GenericCloud.qcow2) ... OK
- Resizing the disk to 50 ... ERR: Could not resize disk.

The logfile shows this:

Formatting 'ovirtnode2.qcow2.new', fmt=qcow2 size=50 cluster_size=65536 preallocation=metadata lazy_refcounts=off refcount_bits=16
virt-resize: error: ovirtnode2.qcow2.new: file is too small to be a disk 
image (512 bytes)

If reporting bugs, run virt-resize with debugging enabled and include the 
complete output:

  virt-resize -v -x [...]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.