├── .gitignore ├── README.md ├── kickstarts ├── CentOS-6.4-x86_64-cloud.cfg ├── README.md ├── centos6x-hypervisor-gpt-selinux.cfg ├── centos6x-hypervisor-mbr-selinux.cfg ├── centos6x-i386-vm-gpt-selinux.cfg ├── centos6x-vm-gpt-selinux.cfg ├── fedora17-guest.cfg └── fedora18-guest.cfg └── scripts ├── centoscloud.sh ├── centoskvm.sh └── resizevm.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CentOS KVM Image Tools - README 2 | =============================== 3 | 4 | + Name: CentOS KVM Image Tools 5 | 6 | + Version: 1.0.000 7 | 8 | + Release date: 2013-04-23 9 | 10 | + Author: Nicola Asuni, Paul Maunders, Mark Sutton, Damion Parry 11 | 12 | + Copyright (2012-2013): 13 | 14 | > > Fubra Limited 15 | > > Manor Coach House 16 | > > Church Hill 17 | > > Aldershot 18 | > > Hampshire 19 | > > GU12 4RQ 20 | > > 21 | > > 22 | 23 | 24 | SOFTWARE LICENSE: 25 | ----------------- 26 | 27 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 28 | 29 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License along with this program. If not, see . 32 | 33 | 34 | DESCRIPTION: 35 | ------------ 36 | 37 | This project contains some simple tools, instructions and Kickstart configuration files to assist with creating CentOS KVM virtual machines. 38 | 39 | ## Installation 40 | 41 | The following guide assumes you have virtualization tools such as virt-install, libguestfs and virt-sparsify installed. 42 | 43 | If you don't, then install them: 44 | 45 | yum groupinstall "Virtualization Tools" 46 | yum install virt-manager libvirt libvirt-python python-virtinst virt-top libguestfs-tools 47 | reboot 48 | 49 | You must download this project for the unattended creation script to work correctly: 50 | 51 | git clone git://github.com/fubralimited/CentOS-KVM-Image-Tools.git 52 | 53 | 54 | ## Kickstart configuration scripts 55 | 56 | The Kickstarts directory contains different Kickstart configuration files to create Virtual Machine images. 57 | 58 | * The centos6x-vm-gpt-selinux.cfg is the Kickstart file to create a CentOS 64bit Virtual Machine guest. 59 | * The centos6x-i386-vm-gpt-selinux.cfg is the Kickstart file to create a CentOS 32bit Virtual Machine guest. 60 | * The centos6x-hypervisor-gpt-selinux.cfg is the Kickstart file to create a CentOS 64bit Virtual Machine hypervisor. 61 | 62 | All the Kickstart files contain the following common packages. In addition all the Kickstart configuration files enable the SELinux and the firewall, and do not install the graphic environment X. 63 | 64 | * @core 65 | * @server-policy 66 | * vim-enhanced 67 | * nano 68 | * aide 69 | 70 | Note that by default we install the AIDE (Advanced Intrusion Detection Environment) package, a file and directory integrity checker. 71 | 72 | The CentOS hypervisor Kickstart is the same as the 64bit version, but with the following additional packages included. 73 | 74 | * kvm 75 | * virt-manager 76 | * libvirt 77 | * libvirt-python 78 | * python-virtinst 79 | * virt-top 80 | * libguestfs-tools 81 | 82 | You can learn more about the specific contents of each file by viewing the comments in the files. 83 | 84 | At this point you should note that the default password for the root user is changeme1122 (as defined on the Kickstart configuration file). 85 | 86 | 87 | ## The Creation Script 88 | 89 | In the Centos KVM Image Tools project that you cloned form GitHub in the previous step you will find a scripts directory. Here you will find one called centoskvm.sh. This is the script you need to run to create the Master Image automatically. 90 | 91 | When you run the script a virtual machine will be created with the given settings, and output from the installation will be sent to your terminal rather than a VNC session. This VM will then be compressed and an image will be created from it. 92 | 93 | Run the script on the command line. 94 | 95 | sh centoskvm.sh centos_vm 96 | 97 | Where centos_vm is the name of the virtual machine we want to create. 98 | 99 | By default this script uses the centos6x-vm-gpt-selinux.cfg Kickstart configuration file. You can clone the project on GitHub and change the Kickstart file to change settings in the unattended creation. 100 | 101 | 102 | ### What’s on the inside? 103 | 104 | The following section illustrates the main operations performed by the centoskvm.sh script to better understand the process and provide some tips. 105 | 106 | ####1. Creating the Virtual Machine 107 | 108 | The firt step consist into creating the VM using the virt-install command with the following parameters: 109 | 110 | virt-install \ 111 | --name centos_vm \ 112 | --ram 512 \ 113 | --cpu host \ 114 | --vcpus 1 \ 115 | --nographics \ 116 | --os-type=linux \ 117 | --os-variant=rhel6 \ 118 | --location=http://mirror.catn.com/pub/centos/6/os/x86_64 \ 119 | --initrd-inject=../Kickstarts/centos6x-vm-gpt-selinux.cfg \ 120 | --extra-args="ks=file:/centos6x-vm-gpt-selinux.cfg text console=tty0 utf8 console=ttyS0,115200" \ 121 | --disk path=/var/lib/libvirt/images/centos_vm.qcow2,size=10,bus=virtio,format=qcow2 \ 122 | --force \ 123 | --noreboot 124 | 125 | On the script the Kickstart configuration is a local file injected via the "initrd-inject" parameter. Is it also possible to pass the Kickstart file as URL: 126 | 127 | virt-install \ 128 | --name centos_vm \ 129 | --ram 512 \ 130 | --cpu host \ 131 | --vcpus 1 \ 132 | --nographics \ 133 | --os-type=linux \ 134 | --os-variant=rhel6 \ 135 | --location=http://mirror.catn.com/pub/centos/6/os/x86_64 \ 136 | --extra-args="ks=http://fubralimited.github.com/CentOS-KVM-Image-Tools/kickstarts/centos6x-vm-gpt-selinux.cfg text console=tty0 utf8 console=ttyS0,115200" \ 137 | --disk path=/var/lib/libvirt/images/centos_vm.qcow2,size=10,bus=virtio,format=qcow2 \ 138 | --force \ 139 | --noreboot 140 | 141 | The image created in this way has the default network settings (DHCP), it is fully updated and is not restarted. Please check the Kickstart configuration file source code for more information and options. 142 | 143 | #### 2. Reset the Virtual Machine 144 | 145 | The virt-sysprep command is used to reset and unconfigure the virtual machine so clones can be made. The VM is modified in place, so the guest must be shut down. 146 | 147 | cd /var/lib/libvirt/images/ 148 | virt-sysprep --format=qcow2 --no-selinux-relabel -a centos_vm.qcow2 149 | 150 | The –no-selinux-relabel option is set to avoid automatic SELinux relabeling at boot. Instead we relabel the VM manually on the next step. 151 | 152 | #### 3. SElinux relabelling 153 | 154 | Using the guestfish shell we can manually relabel the entire filesystem using the following options without the need to start the VM. 155 | 156 | guestfish --selinux -i centos_vm.qcow2 < 314 | 315 | 316 | 317 | 318 | 319 | 320 | Now make the following changes: 321 | 322 | Choose a name for the virtual storage image name we will create, in this case “extra_storage.qcow2″. 323 | Ensure you specify a device name (“vdb”) for the virtual block device attributes. 324 | Finally, give the new storage device an alias, in this case “virtio-disk-extra-storage”. 325 | 326 | It is very important that the defined parameters inside the XML file are unique. 327 | 328 | #### 1.2. Create an empty storage image with the desired size 329 | 330 | The following command creates an empty 20GB storage image in qcow2 format. You can change the 20G to any size you require. 331 | 332 | qemu-img create -f qcow2 extra_storage.qcow2 20G 333 | 334 | Please note that the file name should be the same as the one specified in the XML file. 335 | 336 | #### 1.3. Set image file ownership 337 | 338 | chown qemu:qemu extra_storage.qcow2 339 | 340 | #### 1.4. Attach the storage device to an existing Virtual Machine 341 | 342 | Assuming that the virtual machine is named “centos_vm”. You can also see that in the following command we use the XML file from earlier in this article. 343 | 344 | virsh attach-device --persistent centos_vm extra_storage.xml 345 | 346 | The “–persistent” option is added to be sure that this configuration does not get lost when you power off the virtual machine. 347 | 348 | At this point the virtual device is attached and we can configure the logical device on the VM. 349 | 350 | ### 2. Configure the logical device 351 | 352 | Start the Virtual machine if not started already and log into it, then: 353 | 354 | #### 2.1. Label disk 355 | 356 | In this step we set the partition table to the GPT type to support partitions greater than 2TB. 357 | vdb is the target device as defined in the XML file. 358 | 359 | parted /dev/vdb mklabel gpt 360 | 361 | #### 2.2. Resize the partition 362 | 363 | We partition the new volume to the correct size, again using parted. 364 | 365 | parted /dev/vdb -s -a optimal mkpart primary 1 20G 366 | 367 | Replace 20G with the partition size you require up to the limit defined in step 1.2. 368 | 369 | #### 2.3. Align-check 370 | 371 | Determine whether the starting sector of the first partition meets the disk’s selected alignment criteria. 372 | 373 | parted /dev/vdb align-check optimal 1 374 | 375 | #### 2.4. Initialize the partition for use by Logical Volume Manager (LVM) 376 | 377 | pvcreate /dev/vdb1 378 | 379 | #### 2.5. Create volume group 380 | 381 | vgcreate vg_name /dev/vdb1 382 | 383 | #### 2.6. Create logical volume 384 | 385 | lvcreate -l 100%FREE -n lv_name /dev/vg_name 386 | 387 | #### 2.7. Create an EXT4 filesystem 388 | 389 | mkfs.ext4 /dev/vg_name/lv_name 390 | 391 | #### 2.8. Create mount point for the new storage 392 | 393 | mkdir -p /storage 394 | 395 | #### 2.9. Add entry to fstab 396 | 397 | mount src=/dev/mapper/vg_name-lv_name name=/storage fstype=ext4 opts=defaults,noatime,nodiratime state=mounted 398 | 399 | Finally run the "fdisk -l" command and you should see the newly created storage device attached to the VM: 400 | 401 | Disk /dev/vdb: 21.5 GB, 21474836480 bytes 402 | 255 heads, 63 sectors/track, 2610 cylinders 403 | Units = cylinders of 16065 * 512 = 8225280 bytes 404 | Sector size (logical/physical): 512 bytes / 512 bytes 405 | I/O size (minimum/optimal): 512 bytes / 512 bytes 406 | Disk identifier: 0x00000000 407 | 408 | Device Boot Start End Blocks Id System 409 | /dev/vdb1 1 2611 20971519+ ee GPT 410 | 411 | Disk /dev/mapper/vg_name-lv_name: 20.0 GB, 19994247168 bytes 412 | 255 heads, 63 sectors/track, 2430 cylinders 413 | Units = cylinders of 16065 * 512 = 8225280 bytes 414 | Sector size (logical/physical): 512 bytes / 512 bytes 415 | I/O size (minimum/optimal): 512 bytes / 512 bytes 416 | Disk identifier: 0x00000000 417 | 418 | 419 | ## Useful commands 420 | 421 | This section contains a short list of basic useful commands to play with Virtual Machines using virt-tools. For an extensive guide please consult Managing guests with virsh. 422 | 423 | ### List all available virtual machines 424 | 425 | virsh list --all 426 | 427 | The “–all” option lists all domains, whether active or not. This will give you an output similar to the folowing: 428 | 429 | Id Name State 430 | ---------------------------------------------------- 431 | 0 domain0 running 432 | 1 centos_vm running 433 | 2 rheldomain running 434 | 435 | ### Start a virtual machine 436 | 437 | virsh start centos_vm 438 | 439 | ### Shutdown a virtual machine 440 | 441 | virsh shutdown centos_vm 442 | 443 | ### Connect to a virtual machine’s console 444 | 445 | virsh console centos_vm 446 | 447 | To exit the console press CTRL + ] 448 | 449 | ### Completely delete the virtual machine 450 | 451 | virsh destroy centos_vm 452 | virsh undefine centos_vm 453 | rm /var/lib/libvirt/images/centos_vm.qcow2 454 | 455 | * destroy – this forces the VM to shutdown. It will still appear in the virsh list in a shutdown state. 456 | * undefine – this removes the VM from the hypervisor and prevents any further virsh commands being carried out on it. 457 | * The final remove command deletes the virtual machine disk image from the hypervisor storage device. 458 | 459 | ## Creating a new guest using a copy of the Golden Master Image 460 | 461 | This section shows how to create a new VM guest starting from an existing VM image. 462 | 463 | ### Copy the VM image 464 | 465 | cp centos_vm.qcow2 centos_vm_new.qcow2 466 | 467 | Create a new guest using this image with virt-install –import 468 | 469 | virt-install \ 470 | --name "centos_vm_new" \ 471 | --cpu host \ 472 | --vcpus 1 \ 473 | --ram 1024 \ 474 | --os-type=linux \ 475 | --os-variant=rhel6 \ 476 | --disk path=/var/lib/libvirt/images/centos_vm_new.qcow2 \ 477 | --nographics \ 478 | --force \ 479 | --import 480 | 481 | For other virt-install options please consult the virt-install manual. 482 | 483 | ## Create a new guest using the Golden Master as a backing image 484 | 485 | Create a new image using qemu-img that specifies the master as the backing image 486 | 487 | cd /var/lib/libvirt/images/ 488 | qemu-img create -f qcow2 -b centos_vm.qcow2 centos_vm_backed.qcow2 489 | 490 | Create a new guest using this image with virt-install –import 491 | 492 | virt-install \ 493 | --name "centos_vm_backed" \ 494 | --cpu host \ 495 | --vcpus 1 \ 496 | --ram 1024 \ 497 | --os-type=linux \ 498 | --os-variant=rhel6 \ 499 | --disk path=/var/lib/libvirt/images/centos_vm_backed.qcow2 \ 500 | --nographics \ 501 | --force \ 502 | --import 503 | 504 | ## Adding VNC graphics 505 | 506 | If you want to add a graphical VNC console to an existing guest that doesn’t currently have one set up, you can do so by editing the domain XML file and adding a graphics line. Any time you change the XML config, you need to run the virsh define command again. 507 | 508 | Shutdown the guest 509 | 510 | virsh shutdown centos_vm 511 | 512 | Edit the XML file 513 | 514 | vim /etc/libvirt/qemu/centos_vm.xml 515 | 516 | Add the following line in the devices section 517 | 518 | 519 | 520 | Import the updated guest XML configuration 521 | 522 | virsh define /etc/libvirt/qemu/centos_vm.xml 523 | 524 | Start the guest 525 | 526 | virsh start centos_vm 527 | 528 | Connect to the VNC graphical console 529 | 530 | If you are connected over SSH, make sure you have X11 installed on your client machine, and that you connected with X11 forwarding enabled (e.g. ssh -x). 531 | 532 | virt-viewer centos_vm 533 | -------------------------------------------------------------------------------- /kickstarts/CentOS-6.4-x86_64-cloud.cfg: -------------------------------------------------------------------------------- 1 | # text mode (no graphical mode) 2 | text 3 | 4 | # do not configure X 5 | skipx 6 | 7 | # non-interactive command line mode 8 | cmdline 9 | 10 | # install 11 | install 12 | 13 | # installation path 14 | url --url=http://mirror.catn.com/pub/centos/6/os/x86_64/ 15 | 16 | # repository 17 | repo --name="CentOS Repo" --baseurl=http://mirror.catn.com/pub/centos/6/os/x86_64 18 | repo --name="CentOS Updates" --baseurl=http://mirror.catn.com/pub/centos/6/updates/x86_64 19 | repo --name="epel" --baseurl=http://download.fedoraproject.org/pub/epel/6/x86_64 20 | 21 | # Language support 22 | lang en_GB 23 | 24 | # keyboard 25 | keyboard uk 26 | 27 | # network 28 | network --onboot=on --bootproto=dhcp 29 | 30 | # root password 31 | rootpw ChAnGeMe 32 | 33 | # firewall 34 | firewall --enabled --service=ssh 35 | 36 | # auth config 37 | authconfig --enableshadow --passalgo=sha512 --enablefingerprint 38 | 39 | # SElinux 40 | selinux --enforcing 41 | 42 | # timezone 43 | timezone --utc Europe/London 44 | 45 | # bootloader 46 | bootloader --location=mbr --append="console=tty0 rhgb quiet" 47 | 48 | # clear the MBR (Master Boot Record) 49 | zerombr yes 50 | 51 | # the Setup Agent is not started the first time the system boots 52 | firstboot --disable 53 | 54 | # power off after installation 55 | poweroff 56 | 57 | # disk partitioning 58 | clearpart --all --initlabel 59 | part / --fstype=ext4 --size=1 --grow 60 | 61 | %pre 62 | 63 | %packages –nobase 64 | @core 65 | @server-policy 66 | cloud-init 67 | dracut-modules-growroot 68 | vim-enhanced 69 | screen 70 | aide 71 | 72 | %post 73 | yum clean all 74 | 75 | # install epel repo permanently 76 | yum -y install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 77 | 78 | # run aide to generate initial database and move into place 79 | /usr/sbin/aide -i 80 | mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz 81 | 82 | %end 83 | 84 | -------------------------------------------------------------------------------- /kickstarts/README.md: -------------------------------------------------------------------------------- 1 | # Kickstart configuration files 2 | 3 | This directory contains kickstart configuration files used to create virtual machine. 4 | -------------------------------------------------------------------------------- /kickstarts/centos6x-hypervisor-gpt-selinux.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : centos6x-hypervisor-gpt-selinux.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # CentOS 64 bit hypervisor 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders, Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # NOTES: 46 | # * This configuration uses parted to create a GUID partition table (GPT), which 47 | # allows for > 2TB partitions, unlike the standard fdisk based partitions that 48 | # anaconda uses. 49 | # * Parted command must go in pre section. 50 | # * You must have clearpart --none, otherwise it wipes the GPT partition table! 51 | # * If writing your own kickstart, double check your kickstart file to make sure there are not multiple clearparts. 52 | 53 | # text mode (no graphical mode) 54 | text 55 | 56 | # do not configure X 57 | skipx 58 | 59 | # non-interactive command line mode 60 | cmdline 61 | 62 | # install 63 | install 64 | 65 | # installation path 66 | url --url=http://mirror.catn.com/pub/centos/6/os/x86_64 67 | 68 | # repository 69 | repo --name="CatN CentOS Repo" --baseurl=http://mirror.catn.com/pub/centos/6/os/x86_64 70 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 71 | repo --name="CatN CentOS Repo Update" --baseurl=http://mirror.catn.com/pub/centos/6/updates/x86_64 72 | 73 | # Language support 74 | lang en_GB 75 | 76 | # keyboard 77 | keyboard uk 78 | 79 | # network 80 | network --onboot=on --bootproto=dhcp 81 | 82 | # root password 83 | rootpw changeme1122 84 | 85 | # firewall 86 | firewall --enabled 87 | 88 | # auth config 89 | auth --useshadow --enablemd5 90 | 91 | # SElinux 92 | selinux --enforcing 93 | 94 | # timezone 95 | timezone --utc UTC 96 | 97 | # bootloader 98 | bootloader --location=mbr 99 | 100 | # clear the MBR (Master Boot Record) 101 | zerombr 102 | 103 | # the Setup Agent is not started the first time the system boots 104 | firstboot --disable 105 | 106 | # power off after installation 107 | poweroff 108 | 109 | ################################################################################ 110 | # LVM partitions 111 | 112 | # do not remove any partition (preserve the gpt label) 113 | clearpart --none 114 | 115 | # creates a partition on the system 116 | part /boot --fstype=ext4 --size=500 117 | part pv.00 --grow --asprimary --size=1 118 | 119 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 120 | # Keep 20% of volgroup reserved for future use 121 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 122 | 123 | # adjust the required swap size or use "--recommended" 124 | logvol swap --name=lv_swap --vgname=vg_main --size=1024 125 | 126 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=20480 127 | 128 | logvol /var/lib/libvirt --fstype=ext4 --name=lv_libvirt --vgname=vg_main --size=1 --grow --percent=50 129 | 130 | ################################################################################ 131 | 132 | %pre 133 | parted -s /dev/sda mklabel gpt 134 | 135 | %packages –nobase 136 | @core 137 | @server-policy 138 | vim-enhanced 139 | nano 140 | aide 141 | kvm 142 | virt-manager 143 | libvirt 144 | libvirt-python 145 | python-virtinst 146 | virt-top 147 | libguestfs-tools 148 | 149 | ################################################################################ 150 | 151 | %post 152 | # cleanup the installation 153 | yum clean all 154 | # create default ssh keys 155 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 156 | # create default authorized_keys file 157 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 158 | chmod 600 /root/.ssh/authorized_keys 159 | # run Aide to generate initial database 160 | aide -i 161 | %end 162 | 163 | ################################################################################ 164 | -------------------------------------------------------------------------------- /kickstarts/centos6x-hypervisor-mbr-selinux.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : centos6x-hypervisor-gpt-selinux.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # CentOS 64 bit hypervisor 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders, Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # NOTES: 46 | # * This configuration uses parted to create a GUID partition table (GPT), which 47 | # allows for > 2TB partitions, unlike the standard fdisk based partitions that 48 | # anaconda uses. 49 | # * Parted command must go in pre section. 50 | # * You must have clearpart --none, otherwise it wipes the GPT partition table! 51 | # * If writing your own kickstart, double check your kickstart file to make sure there are not multiple clearparts. 52 | 53 | # text mode (no graphical mode) 54 | text 55 | 56 | # do not configure X 57 | skipx 58 | 59 | # non-interactive command line mode 60 | cmdline 61 | 62 | # install 63 | install 64 | 65 | # installation path 66 | url --url=http://mirror.catn.com/pub/centos/6/os/x86_64 67 | 68 | # repository 69 | repo --name="CatN CentOS Repo" --baseurl=http://mirror.catn.com/pub/centos/6/os/x86_64 70 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 71 | repo --name="CatN CentOS Repo Update" --baseurl=http://mirror.catn.com/pub/centos/6/updates/x86_64 72 | 73 | # Language support 74 | lang en_GB 75 | 76 | # keyboard 77 | keyboard uk 78 | 79 | # network 80 | network --onboot=on --bootproto=dhcp 81 | 82 | # root password 83 | rootpw changeme1122 84 | 85 | # firewall 86 | firewall --enabled 87 | 88 | # auth config 89 | auth --useshadow --enablemd5 90 | 91 | # SElinux 92 | selinux --enforcing 93 | 94 | # timezone 95 | timezone --utc UTC 96 | 97 | # bootloader 98 | bootloader --location=mbr 99 | 100 | # clear the MBR (Master Boot Record) 101 | zerombr 102 | 103 | # the Setup Agent is not started the first time the system boots 104 | firstboot --disable 105 | 106 | # power off after installation 107 | poweroff 108 | 109 | ################################################################################ 110 | # LVM partitions 111 | 112 | # Remove all partitions (for disks bigger than 2TB - use the GPT kickstart instead) 113 | clearpart --all 114 | 115 | # creates a partition on the system 116 | part /boot --fstype=ext4 --size=500 117 | part pv.00 --grow --asprimary --size=1 118 | 119 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 120 | # Keep 20% of volgroup reserved for future use 121 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 122 | 123 | # adjust the required swap size or use "--recommended" 124 | logvol swap --name=lv_swap --vgname=vg_main --size=1024 125 | 126 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=20480 127 | 128 | logvol /var/lib/libvirt --fstype=ext4 --name=lv_libvirt --vgname=vg_main --size=1 --grow --percent=50 129 | 130 | ################################################################################ 131 | 132 | %packages –nobase 133 | @core 134 | @server-policy 135 | vim-enhanced 136 | nano 137 | aide 138 | kvm 139 | virt-manager 140 | libvirt 141 | libvirt-python 142 | python-virtinst 143 | virt-top 144 | libguestfs-tools 145 | 146 | ################################################################################ 147 | 148 | %post 149 | # cleanup the installation 150 | yum clean all 151 | # create default ssh keys 152 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 153 | # create default authorized_keys file 154 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 155 | chmod 600 /root/.ssh/authorized_keys 156 | # run Aide to generate initial database 157 | aide -i 158 | %end 159 | 160 | ################################################################################ 161 | -------------------------------------------------------------------------------- /kickstarts/centos6x-i386-vm-gpt-selinux.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : centos6x-i386-vm-gpt-selinux.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # CentOS 32 bit guest 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # NOTES: 46 | # * This configuration uses parted to create a GUID partition table (GPT), which 47 | # allows for > 2TB partitions, unlike the standard fdisk based partitions that 48 | # anaconda uses. 49 | # * Parted command must go in pre section. 50 | # * You must have clearpart --none, otherwise it wipes the GPT partition table! 51 | # * If writing your own kickstart, double check your kickstart file to make sure there are not multiple clearparts. 52 | 53 | # text mode (no graphical mode) 54 | text 55 | 56 | # do not configure X 57 | skipx 58 | 59 | # non-interactive command line mode 60 | cmdline 61 | 62 | # install 63 | install 64 | 65 | # installation path 66 | url --url=http://mirror.catn.com/pub/centos/6/os/x86_64 67 | 68 | # repository 69 | repo --name="CatN CentOS Repo" --baseurl=http://mirror.catn.com/pub/centos/6/os/i386 70 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 71 | repo --name="CatN CentOS Repo Update" --baseurl=http://mirror.catn.com/pub/centos/6/updates/i386 72 | 73 | # Language support 74 | lang en_GB 75 | 76 | # keyboard 77 | keyboard uk 78 | 79 | # network 80 | network --onboot=on --bootproto=dhcp 81 | 82 | # root password 83 | rootpw changeme1122 84 | 85 | # firewall 86 | firewall --enabled 87 | 88 | # auth config 89 | auth --useshadow --enablemd5 90 | 91 | # SElinux 92 | selinux --enforcing 93 | 94 | # timezone 95 | timezone --utc UTC 96 | 97 | # bootloader 98 | bootloader --location=mbr 99 | 100 | # clear the MBR (Master Boot Record) 101 | zerombr 102 | 103 | # the Setup Agent is not started the first time the system boots 104 | firstboot --disable 105 | 106 | # power off after installation 107 | poweroff 108 | 109 | ################################################################################ 110 | # LVM partitions 111 | 112 | # do not remove any partition (preserve the gpt label) 113 | clearpart --none 114 | 115 | # creates a partition on the system 116 | part /boot --fstype=ext4 --size=500 117 | part pv.00 --grow --asprimary --size=1 118 | 119 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 120 | # Keep 20% of volgroup reserved for future use 121 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 122 | 123 | # Use default swap size 124 | logvol swap --name=lv_swap --vgname=vg_main --recommended 125 | 126 | # Allocate the rest to / 127 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=1 --grow 128 | 129 | ################################################################################ 130 | 131 | %pre 132 | parted -s /dev/vda mklabel gpt 133 | 134 | %packages –nobase 135 | @core 136 | @server-policy 137 | vim-enhanced 138 | nano 139 | aide 140 | 141 | ################################################################################ 142 | 143 | %post 144 | # cleanup the installation 145 | yum clean all 146 | # create default ssh keys 147 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 148 | # create default authorized_keys file 149 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 150 | chmod 600 /root/.ssh/authorized_keys 151 | # run Aide to generate initial database 152 | aide -i 153 | %end 154 | 155 | ################################################################################ 156 | -------------------------------------------------------------------------------- /kickstarts/centos6x-vm-gpt-selinux.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : centos6x-vm-gpt-selinux.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # CentOS 64 bit guest 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders, Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # NOTES: 46 | # * This configuration uses parted to create a GUID partition table (GPT), which 47 | # allows for > 2TB partitions, unlike the standard fdisk based partitions that 48 | # anaconda uses. 49 | # * Parted command must go in pre section. 50 | # * You must have clearpart --none, otherwise it wipes the GPT partition table! 51 | # * If writing your own kickstart, double check your kickstart file to make sure there are not multiple clearparts. 52 | 53 | # text mode (no graphical mode) 54 | text 55 | 56 | # do not configure X 57 | skipx 58 | 59 | # non-interactive command line mode 60 | cmdline 61 | 62 | # install 63 | install 64 | 65 | # installation path 66 | url --url=http://mirror.catn.com/pub/centos/6/os/x86_64 67 | 68 | # repository 69 | repo --name="CatN CentOS Repo" --baseurl=http://mirror.catn.com/pub/centos/6/os/x86_64 70 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 71 | repo --name="CatN CentOS Repo Update" --baseurl=http://mirror.catn.com/pub/centos/6/updates/x86_64 72 | 73 | # Language support 74 | lang en_GB 75 | 76 | # keyboard 77 | keyboard uk 78 | 79 | # network 80 | network --onboot=on --bootproto=dhcp 81 | 82 | # root password 83 | rootpw changeme1122 84 | 85 | # firewall 86 | firewall --enabled 87 | 88 | # auth config 89 | auth --useshadow --enablemd5 90 | 91 | # SElinux 92 | selinux --enforcing 93 | 94 | # timezone 95 | timezone --utc UTC 96 | 97 | # bootloader 98 | bootloader --location=mbr 99 | 100 | # clear the MBR (Master Boot Record) 101 | zerombr 102 | 103 | # the Setup Agent is not started the first time the system boots 104 | firstboot --disable 105 | 106 | # power off after installation 107 | poweroff 108 | 109 | ################################################################################ 110 | # LVM partitions 111 | 112 | # do not remove any partition (preserve the gpt label) 113 | clearpart --none 114 | 115 | # creates a partition on the system 116 | part /boot --fstype=ext4 --size=500 117 | part pv.00 --grow --asprimary --size=1 118 | 119 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 120 | # Keep 20% of volgroup reserved for future use 121 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 122 | 123 | # Use default swap size 124 | logvol swap --name=lv_swap --vgname=vg_main --recommended 125 | 126 | # Allocate the rest to / 127 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=1 --grow 128 | 129 | ################################################################################ 130 | 131 | %pre 132 | parted -s /dev/vda mklabel gpt 133 | 134 | %packages –nobase 135 | @core 136 | @server-policy 137 | vim-enhanced 138 | nano 139 | aide 140 | 141 | ################################################################################ 142 | 143 | %post 144 | # cleanup the installation 145 | yum clean all 146 | # create default ssh keys 147 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 148 | # create default authorized_keys file 149 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 150 | chmod 600 /root/.ssh/authorized_keys 151 | # run Aide to generate initial database 152 | aide -i 153 | %end 154 | 155 | ################################################################################ 156 | -------------------------------------------------------------------------------- /kickstarts/fedora17-guest.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : fedora17-guest.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # Fedora 17 64 bit guest 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders, Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # text mode (no graphical mode) 46 | text 47 | 48 | # do not configure X 49 | skipx 50 | 51 | # non-interactive command line mode 52 | cmdline 53 | 54 | # install 55 | install 56 | 57 | # installation path 58 | url --url=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/releases/17/Fedora/x86_64/os/ 59 | 60 | # repository 61 | repo --name="Fedora Repo" --baseurl=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/releases/17/Fedora/x86_64/os/ 62 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 63 | repo --name="Fedora Repo Update" --baseurl=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/updates/17/x86_64/ 64 | 65 | # Language support 66 | lang en_GB 67 | 68 | # keyboard 69 | keyboard uk 70 | 71 | # network 72 | network --onboot=on --bootproto=dhcp 73 | 74 | # root password 75 | rootpw changeme1122 76 | 77 | # firewall 78 | firewall --enabled 79 | 80 | # auth config 81 | auth --useshadow --enablemd5 82 | 83 | # SElinux 84 | selinux --enforcing 85 | 86 | # timezone 87 | timezone --utc UTC 88 | 89 | # bootloader 90 | bootloader --location=mbr 91 | 92 | # clear the MBR (Master Boot Record) 93 | zerombr 94 | 95 | # the Setup Agent is not started the first time the system boots 96 | firstboot --disable 97 | 98 | # power off after installation 99 | poweroff 100 | 101 | ################################################################################ 102 | # LVM partitions 103 | 104 | # do not remove any partition (preserve the gpt label) 105 | clearpart --none 106 | 107 | # creates a partition on the system 108 | part /boot --fstype=ext4 --size=500 109 | part pv.00 --grow --asprimary --size=1 110 | 111 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 112 | # Keep 20% of volgroup reserved for future use 113 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 114 | 115 | # Use default swap size 116 | logvol swap --name=lv_swap --vgname=vg_main --recommended 117 | 118 | # Allocate the rest to / 119 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=1 --grow 120 | 121 | ################################################################################ 122 | 123 | %pre 124 | parted -s /dev/vda mklabel gpt 125 | 126 | %packages –nobase 127 | @core 128 | @server-policy 129 | vim-enhanced 130 | nano 131 | aide 132 | 133 | ################################################################################ 134 | 135 | %post 136 | # cleanup the installation 137 | yum clean all 138 | # create default ssh keys 139 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 140 | # create default authorized_keys file 141 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 142 | chmod 600 /root/.ssh/authorized_keys 143 | # run Aide to generate initial database 144 | aide -i 145 | %end 146 | 147 | ################################################################################ 148 | -------------------------------------------------------------------------------- /kickstarts/fedora18-guest.cfg: -------------------------------------------------------------------------------- 1 | #==============================================================================+ 2 | # File name : fedora17-guest.cfg 3 | # Begin : 2012-08-28 4 | # Last Update : 2013-04-25 5 | # Version : 1.0.0 6 | # 7 | # Description : This script contains kickstart extra-args options to be passed 8 | # to virt-install command to create a CentOS virtual image. 9 | # Fedora 17 64 bit guest 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Nicola Asuni, Paul Maunders, Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # text mode (no graphical mode) 46 | text 47 | 48 | # do not configure X 49 | skipx 50 | 51 | # non-interactive command line mode 52 | cmdline 53 | 54 | # install 55 | install 56 | 57 | # installation path 58 | url --url=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/releases/18/Fedora/x86_64/os/ 59 | 60 | # repository 61 | repo --name="Fedora Repo" --baseurl=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/releases/18/Fedora/x86_64/os/ 62 | # by specifying the update Repo the install process will automatically update to the latest version. If you wish to stay at the initial release version, comment the following line. 63 | repo --name="Fedora Repo Update" --baseurl=http://mirror.ox.ac.uk/sites/download.fedora.redhat.com/pub/fedora/linux/updates/18/x86_64/ 64 | 65 | # Language support 66 | lang en_GB 67 | 68 | # keyboard 69 | keyboard uk 70 | 71 | # network 72 | network --onboot=on --bootproto=dhcp 73 | 74 | # root password 75 | rootpw changeme1122 76 | 77 | # firewall 78 | firewall --enabled 79 | 80 | # auth config 81 | auth --useshadow --enablemd5 82 | 83 | # SElinux 84 | selinux --enforcing 85 | 86 | # timezone 87 | timezone --utc UTC 88 | 89 | # bootloader 90 | bootloader --location=mbr 91 | 92 | # clear the MBR (Master Boot Record) 93 | zerombr 94 | 95 | # the Setup Agent is not started the first time the system boots 96 | firstboot --disable 97 | 98 | # power off after installation 99 | poweroff 100 | 101 | ################################################################################ 102 | # LVM partitions 103 | 104 | # do not remove any partition (preserve the gpt label) 105 | clearpart --none 106 | 107 | # creates a partition on the system 108 | part /boot --fstype=ext4 --size=500 109 | part pv.00 --grow --asprimary --size=1 110 | 111 | # Increased pesize from 4096 KB to 262144 KB (0.25GB) to allow bigger logvols 112 | # Keep 20% of volgroup reserved for future use 113 | volgroup vg_main --pesize=262144 pv.00 --reserved-percent=20 114 | 115 | # Use default swap size 116 | logvol swap --name=lv_swap --vgname=vg_main --recommended 117 | 118 | # Allocate the rest to / 119 | logvol / --fstype=ext4 --name=lv_root --vgname=vg_main --size=1 --grow 120 | 121 | ################################################################################ 122 | 123 | %pre 124 | parted -s /dev/vda mklabel gpt 125 | 126 | %packages –nobase 127 | @core 128 | @server-policy 129 | vim-enhanced 130 | nano 131 | aide 132 | 133 | ################################################################################ 134 | 135 | %post 136 | # cleanup the installation 137 | yum clean all 138 | # create default ssh keys 139 | ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 140 | # create default authorized_keys file 141 | cp -p -f --context=system_u:object_r:ssh_home_t:s0 /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 142 | chmod 600 /root/.ssh/authorized_keys 143 | # run Aide to generate initial database 144 | aide -i 145 | %end 146 | 147 | ################################################################################ 148 | -------------------------------------------------------------------------------- /scripts/centoscloud.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #==============================================================================+ 4 | # File name : centoscloud.sh 5 | # Begin : 2013-07-09 6 | # Last Update : 2013-07-09 7 | # Version : 1.0.0 8 | # 9 | # Description : Shell script used to generate a CentOS cloud image. 10 | # 11 | # Website : https://github.com/fubralimited/CentOS-KVM-Image-Tools 12 | # 13 | # Author: Mark Sutton 14 | # 15 | # (c) Copyright: 16 | # Fubra Limited 17 | # Manor Coach House 18 | # Church Hill 19 | # Aldershot 20 | # Hampshire 21 | # GU12 4RQ 22 | # UK 23 | # http://www.fubra.com 24 | # support@fubra.com 25 | # 26 | # License: 27 | # Copyright (C) 2012-2013 Fubra Limited 28 | # 29 | # This program is free software: you can redistribute it and/or modify 30 | # it under the terms of the GNU Affero General Public License as 31 | # published by the Free Software Foundation, either version 3 of the 32 | # License, or (at your option) any later version. 33 | # 34 | # This program is distributed in the hope that it will be useful, 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | # GNU Affero General Public License for more details. 38 | # 39 | # You should have received a copy of the GNU Affero General Public License 40 | # along with this program. If not, see . 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # USAGE EXAMPLE: 46 | # sh centoskvm.sh centos-gold-master 47 | 48 | # ensure script is being run as root 49 | if [ `whoami` != root ]; then 50 | echo "ERROR: This script must be run as root" 1>&2 51 | exit 1 52 | fi 53 | 54 | # check for image name 55 | if [ -z "$1" ]; then 56 | echo "ERROR: No argument supplied. Please provide the image name." 57 | exit 1 58 | fi 59 | 60 | # name of the image 61 | IMGNAME=$1 62 | 63 | # default kickstart file 64 | KICKSTART="CentOS-6.4-x86_64-cloud.cfg" 65 | 66 | # VM image file extension 67 | EXT="qcow2" 68 | 69 | echo "Generating VM ..." 70 | 71 | # create image file 72 | virt-install \ 73 | --name $IMGNAME \ 74 | --ram 1024 \ 75 | --cpu host \ 76 | --vcpus 1 \ 77 | --nographics \ 78 | --os-type=linux \ 79 | --os-variant=rhel6 \ 80 | --location=http://mirror.catn.com/pub/centos/6/os/x86_64 \ 81 | --initrd-inject=../kickstarts/$KICKSTART \ 82 | --extra-args="ks=file:/$KICKSTART text console=tty0 utf8 console=ttyS0,115200" \ 83 | --network bridge=virbr0 \ 84 | --disk path=/var/lib/libvirt/images/$IMGNAME.$EXT,size=10,bus=virtio,format=qcow2 \ 85 | --force \ 86 | --noreboot 87 | 88 | # change directory 89 | cd /var/lib/libvirt/images/ 90 | 91 | # reset, unconfigure a virtual machine so clones can be made 92 | virt-sysprep --format=qcow2 --no-selinux-relabel -a $IMGNAME.$EXT 93 | 94 | # SELinux: relabelling all filesystem 95 | guestfish --selinux -i $IMGNAME.$EXT <. 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # USAGE EXAMPLE: 46 | # sh centoskvm.sh centos-gold-master 47 | 48 | # ensure script is being run as root 49 | if [ `whoami` != root ]; then 50 | echo "ERROR: This script must be run as root" 1>&2 51 | exit 1 52 | fi 53 | 54 | # check for image name 55 | if [ -z "$1" ]; then 56 | echo "ERROR: No argument supplied. Please provide the image name." 57 | exit 1 58 | fi 59 | 60 | # name of the image 61 | IMGNAME=$1 62 | 63 | # default kickstart file 64 | KICKSTART="centos6x-vm-gpt-selinux.cfg" 65 | 66 | # VM image file extension 67 | EXT="qcow2" 68 | 69 | echo "Generating VM ..." 70 | 71 | # create image file 72 | virt-install \ 73 | --name $IMGNAME \ 74 | --ram 512 \ 75 | --cpu host \ 76 | --vcpus 1 \ 77 | --nographics \ 78 | --os-type=linux \ 79 | --os-variant=rhel6 \ 80 | --location=http://mirror.catn.com/pub/centos/6/os/x86_64 \ 81 | --initrd-inject=../kickstarts/$KICKSTART \ 82 | --extra-args="ks=file:/$KICKSTART text console=tty0 utf8 console=ttyS0,115200" \ 83 | --disk path=/var/lib/libvirt/images/$IMGNAME.$EXT,size=10,bus=virtio,format=qcow2 \ 84 | --force \ 85 | --noreboot 86 | 87 | # change directory 88 | cd /var/lib/libvirt/images/ 89 | 90 | # reset, unconfigure a virtual machine so clones can be made 91 | virt-sysprep --format=qcow2 --no-selinux-relabel -a $IMGNAME.$EXT 92 | 93 | # SELinux: relabelling all filesystem 94 | guestfish --selinux -i $IMGNAME.$EXT <. 41 | # 42 | # See LICENSE.TXT file for more information. 43 | #==============================================================================+ 44 | 45 | # USAGE EXAMPLE: 46 | # sh resizevm.sh VM_NAME VM_SIZE 47 | # sh resizevm.sh centosvm 20G 48 | 49 | # NOTE: This script assume that the VM images are created using the centoskvm.sh 50 | # script and located at /var/lib/libvirt/images 51 | 52 | # ensure script is being run as root 53 | if [ `whoami` != root ]; then 54 | echo "ERROR: This script must be run as root" 1>&2 55 | exit 1 56 | fi 57 | 58 | # check for vm name 59 | if [ -z "$1" ]; then 60 | echo "ERROR: No argument supplied. Please provide the Virtual machine name." 61 | exit 1 62 | fi 63 | 64 | # name of the image 65 | VMNAME=$1 66 | 67 | # check for new size 68 | if [ -z "$2" ]; then 69 | echo "ERROR: Missing size argument. Please provide the Virtual machine name new size." 70 | exit 1 71 | fi 72 | 73 | echo "Resizing VM ..." 74 | 75 | # name of the image 76 | VMSIZE=$2 77 | 78 | # extract VM file name 79 | VMFILE=$(virsh dumpxml $VMNAME | grep "//") 80 | 81 | # shut the virtual machine down 82 | virsh shutdown $VMNAME 83 | 84 | # change directory 85 | cd /var/lib/libvirt/images 86 | 87 | # clone VM image 88 | cp -f $VMFILE $VMFILE.tmp 89 | 90 | # resize the cloned image (i.e. 20 GB) 91 | qemu-img resize $VMFILE.tmp $VMSIZE 92 | 93 | # resize the partitions 94 | virt-resize --expand /dev/vda2 --LV-expand /dev/vg_main/lv_root $VMFILE $VMFILE.tmp 95 | 96 | # make a backup of the VM for any evenience: 97 | mv -f $VMFILE $VMFILE.backup 98 | 99 | # sparsify image 100 | virt-sparsify --format qcow2 --compress $VMFILE.tmp $VMFILE 101 | 102 | # remove the resized image 103 | rm -f $VMFILE.tmp 104 | 105 | # set file ownership 106 | chown qemu:qemu $VMFILE 107 | 108 | # restart the virtual machine 109 | virsh start $VMNAME 110 | 111 | # if the new image works fine, then we can delete the backup image: 112 | #rm -rf $VMFILE.backup 113 | 114 | echo "Process Completed. Please try the new image and delete the backup file if everything is OK." 115 | 116 | #==============================================================================+ 117 | # END OF FILE 118 | #==============================================================================+ 119 | --------------------------------------------------------------------------------