I share some internal scripts of mine... look out for more threads. Sorry for formating if it makes not much sense, i'm not good at writing tutorials and can hardly concentrate currently at anything.
I was not happy with virt-install alone but did not want a full panel, so i wrote the middle way myself. My bash is good but not the best and i did not really put too much work into these scripts when they were working fully - Don't touch working scripts. No guarantees/liability for anything, not my problem.
For links william.si is interchangeable with william.su (SSL cert does not match then though) - No SSL check is done because it seems to fail for my certs, no idea why.
>>>Copyright William Weber/The Liechtenstein Limited 2014 / reshare of scripts only allowed without removing nameswhere in the script.
If you are not happy with this please don't use/modify them and leave this thread
Requirements are:
* A Webserver, prefferably internal (i use br1 as int and thus have it internal and no auth) or with auth (requires script edit)
* A KVM node based on Debian, Ubuntu or a derivate of them (not guaranteed to work outside of Debian 7, which i use)
* Libvirt with virt-install
* A free (permanent or NAT) IPv4 for the setup process
* Basic knowledge of bash
* Time to install one KVM of each OS you want as template
Pro:
* Contains also ISO install function to mount a local ISO and start a normal, non copied install with VNC access, loads automatically correct ENV based on ISO and Windows VirtIO drivers if Windows.
* It works. This never fails. Image copy does. not. fail. Unlike netinstall or preseed.
* It's fast, no need to install the OS - One reboot is enough. Average time for a Debian 7 install on my SSDs is 2min until it runs fully with new IP/hostname.
* You can already implement your SSH keys in the image and disable PW auth, or do other mods you need on all systems (like i preinstall Nagios and Munin in each template)
* Very easy to use once templates are created
* Custom configuration/scripts etc. possible by adding simply to the webserved file on case by case
* Scriptable (rpl and alike) for even more automatic cmd installer (like, hostname, OS, IP, done)
* Can be removed at any time, does not interfere with libvirt or anything else, no modifications on Libvirt XMLs
* Can resize partiton by simply providing larger zvol/lvm/rawfile (requires edits due to size check of the source image) and later use xfs/ext4 (recommended) expanding inside the VM (Warning: Place SWAP *BEFORE* / in your template installs, or this won't work)
Con:
* It does not provide actual apt packages, this can be implemented by a apt-get update && apt-get upgrade -y in rc.local/auto-install.sh but it is not adviseable to do it automatic. This is no concern for me looking at how old most OVZ templates with most providers are.
* Cannot resize / partition later, OS image is always the same size (see "Create template section, can be avoided form start)
* Not flexible partition/fs wise with image copy
* Cannot run 2+ installs at the same time (IP conflict)
This version is based on ZFS ZVols, you can edit it for LVM (lvcreate or something, i don't use LVM) - I also provide a rawfile (qemu-img) edition that can be modified for qcow2 etc. if desired.
It installs any Debian based distro automatically by copying a premade image that contains a rc.local line that loads the config, replaces IP, sets hostname and reboots after removing the script.
Some parts of the scripts, like the eth check in autoinstall.sh might seem useless - This is because, as said, i use internal networking for the setup which requires to check if eth1/INT is available.
---
Step 1.: Image creation
Setup a KVM with any RAM size and a diskfile/volume as you want it it later for the image (i use 10GB), install the OS as usual (hostname "master" or alike, you need to remember it later), static IPv4 with the setup IP (will be always used on each image copy) and make sure to partition in this layout (or with whatever partition you want to be able to resize last):
A - Boot
B - SWAP
(.. other partitions here, if any)
C - /
This is required to be later able to resize the / partition inside a new VM.
After installation set up packages (if any, like munin/nagios) - It is required to install the "rpl" and "wget" packages unless you modify the scripts to use sed/curl or something else (then obviously install curl).
I also add SSH keys and set openssh to not allow password login, up to your needs.
Make sure to set a root password you remember in case you ever need to use VNC (or hack it then, but this is easier).
Now edit /etc/rc.local and add this line:
/bin/bash /root/autoinstall.sh &
And download this script to /root (obviously edit where required, download url only required) - This downloads the install file later. Also edit for HTTP auth if you use external network with static/easy to guess urls.
wget --no-check-certificate https://william.si/code/autoinstall.sh -O /root/autoinstall.sh
And this as well (can be combined also if you want) - This removes the autostart line from rc.local:
wget --no-check-certificate https://william.si/code/add.sh -O /root/add.sh
If you want the ability to start my autoinstaller locally on the VM when you first login (so without downloaded file) (asks for hostname, IP etc. then, very easy as well) you can add this to the /root/.bashrc - The webfile based installer will automatically remove this file once it ran if it exists, the bashrc will stil lcontain the line but i doubt this is an issue.
if [ -f /root/setup.sh ]; then
bash /root/setup.sh
fi
Remove udev file (if you restart the KVM afterwards you have to remove it again, you could also just remove the eth line):
rm /etc/udev/rules.d/70-persistent-net.rules
Now, the most important part - Place the setup.sh in /root - This is the script that does IP replacement, sets hostname, regenerates SSH keys and finally restarts. It is tested on Debian 6, Debian 7, Ubuntu 10, Ubuntu 11, Ubuntu 12(.04|.10) and Ubuntu 13. It should be portable to any non-Debian distro with few modifications (paths for IP for CentOS and others mainly) and to any Debian based distro without *any* modifications.
If your hostname is not "master" you need to edit this, you should also change my IP to your install one to get a correct /etc/hosts file automatically.
wget --no-check-certificate https://william.si/code/setup.sh -O /root/setup.sh
That's it. Image complete.
Shutdown the KVM, Save the image as master_debian6/7.img or master_ubuntu12 (or any other name, this one works with my non modified script, else edit later)
Step 2.: Install files on Webserver
i precreated scripts for Ubuntu and Debian, these are very similar anyway so i only provide the Debian one - It should work 1:1 on Ubuntu just fine.
Download this script into your webdir and edit it where required.
wget --no-check-certificate https://william.si/code/auto-install.sh
Step done, no more required - If you want you could also limit access to this file by htaccess/nginx directive to only your setup IP(s).
I run this in my webserver KVM and mount the webdir by NFS as /kvm/deploy/ on each KVM node so i can easily modify the scripts when i need a new KVM. This can be further scripted easily which i will do at one point.
Step 3.: Install script on KVM node
Now we get to the funny part - The installer itself. It is *nowhere* near perfect but works very, very well since nearly a year for me. Modify where required. It is pretty self explanatory if you know some bash, the VNC port thing is unrealiable though if you edit XMLs manually or by libvirt sometimes. It has some failsafe checks but... i would not trust them too much.
----
PLEASE DO NOT SIMPLY RUN THIS - YOU NEED TO EDIT IT AND AT LEAST FIX ISO/IMG DIR OR ZPOOL NAME
----
Example usage (from -h) - Args ARE case sensitive!
newkvm NAME(unique) CPUS MB-RAM ISO(deb6,deb7,ub12,ub12d,ub13,w12r2,none) VNCPORT(AUTO,PORT) DISK(NEW,EXISTING,COPY,NODEVICE) DISKSIZE/PATH(size GB,Full path,NODEVICE) NET(INT,EXT,ALL)
/usr/bin/newkvm vpsboard 4 2048 none 5210 COPY /kvm/img/debian7_master.img EXT
ZFS/ZVOL Edition:
wget --no-check-certificate https://william.si/code/newkvm.raw
RAW/qemu-img diskfile Edition:
wget --no-check-certificate https://william.si/code/newkvm.zvol
LVM Edition (mostly untested, but i LVM is easier than ZFS pools, i just changed to lvcreate and fixed the dev paths based on a test LVM i set up, works):
wget --no-check-certificate https://william.si/code/newkvm.lvm
Comments? Aything?
I was not happy with virt-install alone but did not want a full panel, so i wrote the middle way myself. My bash is good but not the best and i did not really put too much work into these scripts when they were working fully - Don't touch working scripts. No guarantees/liability for anything, not my problem.
For links william.si is interchangeable with william.su (SSL cert does not match then though) - No SSL check is done because it seems to fail for my certs, no idea why.
>>>Copyright William Weber/The Liechtenstein Limited 2014 / reshare of scripts only allowed without removing nameswhere in the script.
If you are not happy with this please don't use/modify them and leave this thread
Requirements are:
* A Webserver, prefferably internal (i use br1 as int and thus have it internal and no auth) or with auth (requires script edit)
* A KVM node based on Debian, Ubuntu or a derivate of them (not guaranteed to work outside of Debian 7, which i use)
* Libvirt with virt-install
* A free (permanent or NAT) IPv4 for the setup process
* Basic knowledge of bash
* Time to install one KVM of each OS you want as template
Pro:
* Contains also ISO install function to mount a local ISO and start a normal, non copied install with VNC access, loads automatically correct ENV based on ISO and Windows VirtIO drivers if Windows.
* It works. This never fails. Image copy does. not. fail. Unlike netinstall or preseed.
* It's fast, no need to install the OS - One reboot is enough. Average time for a Debian 7 install on my SSDs is 2min until it runs fully with new IP/hostname.
* You can already implement your SSH keys in the image and disable PW auth, or do other mods you need on all systems (like i preinstall Nagios and Munin in each template)
* Very easy to use once templates are created
* Custom configuration/scripts etc. possible by adding simply to the webserved file on case by case
* Scriptable (rpl and alike) for even more automatic cmd installer (like, hostname, OS, IP, done)
* Can be removed at any time, does not interfere with libvirt or anything else, no modifications on Libvirt XMLs
* Can resize partiton by simply providing larger zvol/lvm/rawfile (requires edits due to size check of the source image) and later use xfs/ext4 (recommended) expanding inside the VM (Warning: Place SWAP *BEFORE* / in your template installs, or this won't work)
Con:
* It does not provide actual apt packages, this can be implemented by a apt-get update && apt-get upgrade -y in rc.local/auto-install.sh but it is not adviseable to do it automatic. This is no concern for me looking at how old most OVZ templates with most providers are.
* Cannot resize / partition later, OS image is always the same size (see "Create template section, can be avoided form start)
* Not flexible partition/fs wise with image copy
* Cannot run 2+ installs at the same time (IP conflict)
This version is based on ZFS ZVols, you can edit it for LVM (lvcreate or something, i don't use LVM) - I also provide a rawfile (qemu-img) edition that can be modified for qcow2 etc. if desired.
It installs any Debian based distro automatically by copying a premade image that contains a rc.local line that loads the config, replaces IP, sets hostname and reboots after removing the script.
Some parts of the scripts, like the eth check in autoinstall.sh might seem useless - This is because, as said, i use internal networking for the setup which requires to check if eth1/INT is available.
---
Step 1.: Image creation
Setup a KVM with any RAM size and a diskfile/volume as you want it it later for the image (i use 10GB), install the OS as usual (hostname "master" or alike, you need to remember it later), static IPv4 with the setup IP (will be always used on each image copy) and make sure to partition in this layout (or with whatever partition you want to be able to resize last):
A - Boot
B - SWAP
(.. other partitions here, if any)
C - /
This is required to be later able to resize the / partition inside a new VM.
After installation set up packages (if any, like munin/nagios) - It is required to install the "rpl" and "wget" packages unless you modify the scripts to use sed/curl or something else (then obviously install curl).
I also add SSH keys and set openssh to not allow password login, up to your needs.
Make sure to set a root password you remember in case you ever need to use VNC (or hack it then, but this is easier).
Now edit /etc/rc.local and add this line:
/bin/bash /root/autoinstall.sh &
And download this script to /root (obviously edit where required, download url only required) - This downloads the install file later. Also edit for HTTP auth if you use external network with static/easy to guess urls.
wget --no-check-certificate https://william.si/code/autoinstall.sh -O /root/autoinstall.sh
And this as well (can be combined also if you want) - This removes the autostart line from rc.local:
wget --no-check-certificate https://william.si/code/add.sh -O /root/add.sh
If you want the ability to start my autoinstaller locally on the VM when you first login (so without downloaded file) (asks for hostname, IP etc. then, very easy as well) you can add this to the /root/.bashrc - The webfile based installer will automatically remove this file once it ran if it exists, the bashrc will stil lcontain the line but i doubt this is an issue.
if [ -f /root/setup.sh ]; then
bash /root/setup.sh
fi
Remove udev file (if you restart the KVM afterwards you have to remove it again, you could also just remove the eth line):
rm /etc/udev/rules.d/70-persistent-net.rules
Now, the most important part - Place the setup.sh in /root - This is the script that does IP replacement, sets hostname, regenerates SSH keys and finally restarts. It is tested on Debian 6, Debian 7, Ubuntu 10, Ubuntu 11, Ubuntu 12(.04|.10) and Ubuntu 13. It should be portable to any non-Debian distro with few modifications (paths for IP for CentOS and others mainly) and to any Debian based distro without *any* modifications.
If your hostname is not "master" you need to edit this, you should also change my IP to your install one to get a correct /etc/hosts file automatically.
wget --no-check-certificate https://william.si/code/setup.sh -O /root/setup.sh
That's it. Image complete.
Shutdown the KVM, Save the image as master_debian6/7.img or master_ubuntu12 (or any other name, this one works with my non modified script, else edit later)
Step 2.: Install files on Webserver
i precreated scripts for Ubuntu and Debian, these are very similar anyway so i only provide the Debian one - It should work 1:1 on Ubuntu just fine.
Download this script into your webdir and edit it where required.
wget --no-check-certificate https://william.si/code/auto-install.sh
Step done, no more required - If you want you could also limit access to this file by htaccess/nginx directive to only your setup IP(s).
I run this in my webserver KVM and mount the webdir by NFS as /kvm/deploy/ on each KVM node so i can easily modify the scripts when i need a new KVM. This can be further scripted easily which i will do at one point.
Step 3.: Install script on KVM node
Now we get to the funny part - The installer itself. It is *nowhere* near perfect but works very, very well since nearly a year for me. Modify where required. It is pretty self explanatory if you know some bash, the VNC port thing is unrealiable though if you edit XMLs manually or by libvirt sometimes. It has some failsafe checks but... i would not trust them too much.
----
PLEASE DO NOT SIMPLY RUN THIS - YOU NEED TO EDIT IT AND AT LEAST FIX ISO/IMG DIR OR ZPOOL NAME
----
Example usage (from -h) - Args ARE case sensitive!
newkvm NAME(unique) CPUS MB-RAM ISO(deb6,deb7,ub12,ub12d,ub13,w12r2,none) VNCPORT(AUTO,PORT) DISK(NEW,EXISTING,COPY,NODEVICE) DISKSIZE/PATH(size GB,Full path,NODEVICE) NET(INT,EXT,ALL)
/usr/bin/newkvm vpsboard 4 2048 none 5210 COPY /kvm/img/debian7_master.img EXT
ZFS/ZVOL Edition:
wget --no-check-certificate https://william.si/code/newkvm.raw
RAW/qemu-img diskfile Edition:
wget --no-check-certificate https://william.si/code/newkvm.zvol
LVM Edition (mostly untested, but i LVM is easier than ZFS pools, i just changed to lvcreate and fixed the dev paths based on a test LVM i set up, works):
wget --no-check-certificate https://william.si/code/newkvm.lvm
Comments? Aything?
Last edited by a moderator: