SlideShare a Scribd company logo
Customizing Virtual Machine
Images
Javier Fontán - OpenNebula Developer
qcow2 Format
$ qemu-img create -f qcow2 image.qcow2 10G
Metadata
Cluster Map
Cluster Data
qcow2 Image With Parent
$ qemu-img create -f qcow2 -o backing_file=base.qcow2 image.qcow2
Metadata
Cluster Map
Cluster Data
Metadata
Cluster Map
Cluster Data
Parent
● There are other ways to create your images:
○ virt-install
○ packer.io
○ foreman
○ etc...
● Sometimes modifying already created images is convenient
● Even if you use other image formats you can convert them
Mount Image
➔ Convert to raw and use mount -o loop
◆ mount -o loop,offset=32256 image.raw /mnt
➔ Convert to raw and use losetup
◆ losetup /dev/loop0 image.raw
◆ kpartx -a /dev/loop0
◆ mount /dev/loop0p1 /mnt
➔ Use nbd
◆ modprobe nbd
◆ qemu-nbd -c /dev/nbd0 image.qcow2
◆ mount /dev/nbd0p1 /mnt
libguestfs
From its webpage http://libguestfs.org:
libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk
images. You can use this for viewing and editing files inside guests, scripting
changes to VMs, monitoring disk used/free statistics, creating guests, P2V, V2V,
performing backups, cloning VMs, building VMs, formatting disks, resizing disks,
and much more.
guestfish - Read or Edit Files
$ guestfish -ia image.qcow2
><fs> cat /var/log/service/error.log
><fs> vi /etc/service.conf
$ guestfish -ia image.qcow2 <<EOF
upload service.conf /etc/service.conf
tar-in ssh-configuration.tar /etc/sshd
EOF
$ guestfish --ro -i -c qemu:///system -d vm-name
><fs> cat /var/log/service/error.log
virt-customize
● Starts custom VM and attach disks and connects to network
● Change passwords, create users
● Move files
● Install packages
● Execute scripts
virt-customize [--options]
[ -d domname | -a disk.img [-a disk.img ...] ] [--chmod PERMISSIONS:FILE] [--commands-from-file FILENAME]
[--copy SOURCE:DEST] [--copy-in LOCALPATH:REMOTEDIR] [--delete PATH] [--edit FILE:EXPR] [--firstboot SCRIPT]
[--firstboot-command 'CMD+ARGS'] [--firstboot-install PKG,PKG..] [--hostname HOSTNAME] [--install PKG,PKG..]
[--link TARGET:LINK[:LINK..]] [--mkdir DIR] [--move SOURCE:DEST] [--password USER:SELECTOR] [--root-password SELECTOR]
[--run SCRIPT] [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR] [--sm-register] [--sm-remove]
[--sm-unregister] [--ssh-inject USER[:SELECTOR]] [--truncate FILE] [--truncate-recursive PATH] [--timezone TIMEZONE] [--touch FILE]
[--update] [--upload FILE:DEST] [--write FILE:CONTENT] [--no-logfile] [--password-crypto md5|sha256|sha512]
[--selinux-relabel] [--sm-credentials SELECTOR]
OpenNebula Marketplace Images
● Download CentOS images
● Create CDROM with OpenNebula context packages
● Create script to modify the image
○ Mount CDROM
○ Install context packages
○ Remove cloud-init and NetworkManager packages
○ Install EPEL repository
○ Install growpart packages
OpenNebula Images - Create CDROM
# Download context packages from github
curl -s https://api.github.com/repos/OpenNebula/addon-context-
linux/releases | jq -r '.[0].assets[].browser_download_url' |
xargs -L1 wget -P repo
# Create ISO image with label “EXTRA”
genisoimage -o extra-packages.iso -R -J -V EXTRA repo/
OpenNebula Images - Prepare Script
mkdir /tmp/mount
mount LABEL=EXTRA /tmp/mount
# Install opennebula context package
rpm -Uvh /tmp/mount/one-context*rpm
# Remove cloud-init and NetworkManager
yum remove -y NetworkManager cloud-init
# Install growpart and upgrade util-linux
yum install -y epel-release --nogpgcheck
yum install -y cloud-utils-growpart --nogpgcheck
yum upgrade -y util-linux --nogpgcheck
OpenNebula Images - Calling virt-customize
# Create an overlay to preserve original image
$ qemu-img create -f qcow2 -b $orig $image
# Run customization
$ virt-customize --attach $ISO_IMAGE --run $script --format qcow2
-v -a $image --root-password disabled
Optimizing Images
● qemu-img does not know anything about filesystems
● Blocks not allocated (sparse files) or that contain zeroes are not copied
● Normal file deletion does not zero or deallocate blocks
● Swap partitions contain information if used
● This information can be stripped to make the images smaller
● virt-sparsify to the rescue!
Optimizing Images - virt-sparsify
There are two ways of doing sparsification:
● Normal Sparsification:
○ Occupies the maximum space of the image
● In Place Sparsification:
○ Create an sparse qcow2 file
Optimizing Images - Normal Sparsification
● Create overlay of the image
● Create a file in all filesystems and fill it with zeroes until there is not more space
and delete file
● Fill swap partitions with zeroes
● Convert it to a new qcow2 file skipping zero blocks
$ TMPDIR=/var/tmp virt-sparsify original.qcow2 new.qcow2
Optimizing Images - In Place Sparsification
● Uses trim command, normally used for SSD disks
● Deallocates blocks from filesystem
● Does not require the total amount of disk space
● The qcow2 file contains holes and is not the best one for distribution
● Can be converted to a non sparse qcow2 file
● Can not be used with compression
$ virt-sparsify --in-place original.qcow2 new.qcow2
Optimizing Images - Compression
● qcow2 images can have the blocks compressed
● Compression rate is less that xz or bzip2
● Is more convenient as it can be directly used as is
● Use of these images trades disk space for CPU consumption
● Can be done directly in virt-sparsify with --compress (not In Place)
qemu-img tips
● There are two qcow2 file formats, pre version 0.10 and newer
○ CentOS 6 does not support post 0.10 version
○ On conversion or creation it can be specified with -o compat=0.10
● qemu-img < 2.4 does not support creation of delta images with compression
○ This tool can be easily compiled manually
○ Download qemu 2.4 code
○ ./configure
○ make qemu-img
Cangallo!
https://github.com/jfontan/cangallo
Thank You!
Consolidate qcow2 Image
$ qemu-img convert -O qcow2 image.qcow2 new_image.qcow2
Metadata
Cluster Map
Cluster Data
Parent
Metadata
Cluster Map
Cluster Data
Convert
qcow2 Image After Copy
$ cp base.qcow2 image.qcow2
Metadata
Cluster Map
Cluster Data
Metadata
Cluster Map
Cluster Data
Copy
Create Delta From 2 qcow2 Images
$ qemu-img rebase -b base.qcow2 image.qcow2
$ qemu-img convert -O qcow2 -o backing_file=base.qcow2 image.qcow2
new_image.qcow2
Metadata
Cluster Map
Cluster Data
Metadata
Cluster Map
Cluster Data
Copy
Metadata
Cluster Map
Cluster Data
Convert

More Related Content

PDF
Customizing Virtual Machine Images - Javier Fontán
PDF
TechDay - Cambridge 2016 - OpenNebula at Harvard Univerity
PDF
OpenNebulaConf 2016 - Storage Hands-on Workshop by Javier Fontán, OpenNebula
PDF
TechDay - April - OpenNebula and Docker
PDF
OpenNebulaConf2015 2.03 Docker-Machine and OpenNebula - Jaime Melis
PDF
OpenNebulaConf2015 2.02 Backing up your VM’s with Bacula - Alberto García
PPTX
Docker Machine and Swarm on OpenNebula - Jaime Melis
PDF
Optimization_of_Virtual_Machines_for_High_Performance
Customizing Virtual Machine Images - Javier Fontán
TechDay - Cambridge 2016 - OpenNebula at Harvard Univerity
OpenNebulaConf 2016 - Storage Hands-on Workshop by Javier Fontán, OpenNebula
TechDay - April - OpenNebula and Docker
OpenNebulaConf2015 2.03 Docker-Machine and OpenNebula - Jaime Melis
OpenNebulaConf2015 2.02 Backing up your VM’s with Bacula - Alberto García
Docker Machine and Swarm on OpenNebula - Jaime Melis
Optimization_of_Virtual_Machines_for_High_Performance

What's hot (20)

PDF
OpenNebula - OpenNebula and tips for CentOS 7
PDF
OpenNebulaconf2017US: Multi-Site Hyperconverged OpenNebula with DRBD9
PDF
OpenNebulaConf 2013 - Hands-on Tutorial: 2. Installing and Basic Usage
PDF
OpenNebulaConf 2013 - Hands-on Tutorial: 1. Introduction and Architecture
PDF
Build a private cloud – prototype and test with open nebula
PDF
OpenNebula TechDay Waterloo 2015 - Open nebula hands on workshop
PDF
OpenNebula TechDay Waterloo 2015 - OpenNebula is Evolving Fast
PDF
OpenNebulaConf 2016 - ONEDock: Docker as a hypervisor in ONE by Carlos de Alf...
PDF
OpenNebula 4.14 Hands-on Tutorial
PDF
OpenNebulaConf2017EU: Rudder by Florian, Heigl
PDF
OpenNebulaConf 2016 - Hypervisors and Containers Hands-on Workshop by Jaime M...
PDF
Open nebula is evolving paris techday 2015
PDF
OpenNebula 5.4 Hands-on Tutorial
PPTX
TECNIRIS@: OpenNebula Tutorial
PDF
An OpenNebula Private Cloud
PDF
OpenNebula Conf 2014 | OpenNebula and MooseFS for disaster recovery: real clo...
PDF
TechDay - Toronto 2016 - OpenNebula @ Fuze
PDF
Open nebula froscon
PDF
OpenNebulaConf2015 2.14 Cloud Service Experience in TeideHPC Infrastructure -...
PDF
TechDay - Toronto 2016 - Hyperconvergence and OpenNebula
OpenNebula - OpenNebula and tips for CentOS 7
OpenNebulaconf2017US: Multi-Site Hyperconverged OpenNebula with DRBD9
OpenNebulaConf 2013 - Hands-on Tutorial: 2. Installing and Basic Usage
OpenNebulaConf 2013 - Hands-on Tutorial: 1. Introduction and Architecture
Build a private cloud – prototype and test with open nebula
OpenNebula TechDay Waterloo 2015 - Open nebula hands on workshop
OpenNebula TechDay Waterloo 2015 - OpenNebula is Evolving Fast
OpenNebulaConf 2016 - ONEDock: Docker as a hypervisor in ONE by Carlos de Alf...
OpenNebula 4.14 Hands-on Tutorial
OpenNebulaConf2017EU: Rudder by Florian, Heigl
OpenNebulaConf 2016 - Hypervisors and Containers Hands-on Workshop by Jaime M...
Open nebula is evolving paris techday 2015
OpenNebula 5.4 Hands-on Tutorial
TECNIRIS@: OpenNebula Tutorial
An OpenNebula Private Cloud
OpenNebula Conf 2014 | OpenNebula and MooseFS for disaster recovery: real clo...
TechDay - Toronto 2016 - OpenNebula @ Fuze
Open nebula froscon
OpenNebulaConf2015 2.14 Cloud Service Experience in TeideHPC Infrastructure -...
TechDay - Toronto 2016 - Hyperconvergence and OpenNebula
Ad

Viewers also liked (20)

PDF
TechDay - April - Introduction to OpenNebula
PDF
TechDay - April - Tutorial
PDF
TechDay - Cambridge 2016 - OpenNebula Corona
PDF
TechDay - Cambridge 2016 - OpenNebula at Knight Point Systems
PDF
OpenNebula TechDay Boston 2015 - Bringing Private Cloud Computing to HPC and ...
PDF
OpenNebula TechDay Boston 2015 - introduction and architecture
PDF
OpenNebula TechDay Boston 2015 - HA HPC with OpenNebula
PDF
OpenNebula TechDay Boston 2015 - An introduction to OpenNebula
PDF
OpenNebula TechDay Boston 2015 - Future of Information Storage with ISS Super...
PDF
OpenNebula TechDay Boston 2015 - Hyperconvergence and OpenNebula
PDF
OpenNebula TechDay Boston 2015 - installing and basic usage
DOCX
Open stack vs open nebula
PPTX
Disk Image!...and then what? Strategies for sustainable long-term storage an...
PDF
Jenkins & OpenNebula a CD History - Alberto García
PDF
Introduction to OpenNebula - Ignacio M. Llorente
PPTX
OpenNebula Networking - Rubén S. Montero
PPTX
Customizing Sunstone Provisioning and Admin Portal - Daniel Molina
ODP
Storage best practices
PDF
Virtualization with KVM (Kernel-based Virtual Machine)
PDF
Clash of Titans in SDN: OpenDaylight vs ONOS - Elisa Rojas
TechDay - April - Introduction to OpenNebula
TechDay - April - Tutorial
TechDay - Cambridge 2016 - OpenNebula Corona
TechDay - Cambridge 2016 - OpenNebula at Knight Point Systems
OpenNebula TechDay Boston 2015 - Bringing Private Cloud Computing to HPC and ...
OpenNebula TechDay Boston 2015 - introduction and architecture
OpenNebula TechDay Boston 2015 - HA HPC with OpenNebula
OpenNebula TechDay Boston 2015 - An introduction to OpenNebula
OpenNebula TechDay Boston 2015 - Future of Information Storage with ISS Super...
OpenNebula TechDay Boston 2015 - Hyperconvergence and OpenNebula
OpenNebula TechDay Boston 2015 - installing and basic usage
Open stack vs open nebula
Disk Image!...and then what? Strategies for sustainable long-term storage an...
Jenkins & OpenNebula a CD History - Alberto García
Introduction to OpenNebula - Ignacio M. Llorente
OpenNebula Networking - Rubén S. Montero
Customizing Sunstone Provisioning and Admin Portal - Daniel Molina
Storage best practices
Virtualization with KVM (Kernel-based Virtual Machine)
Clash of Titans in SDN: OpenDaylight vs ONOS - Elisa Rojas
Ad

Similar to TechDay - April - Customizing VM Images (20)

PPTX
Optimizing VM images for OpenStack with KVM/QEMU
PDF
AnsibleFest 2021 - DevSecOps with Ansible, OpenShift Virtualization, Packer a...
ODP
Locally run a FIWARE Lab Instance In another Hypervisors
PDF
Ericas-Linux-Plus-Study-Guide
PDF
Dev ops
PDF
Development platform virtualization using qemu
PDF
Building a cloud ready linux image locally using KVM
PDF
Big Data Step-by-Step: Infrastructure 1/3: Local VM
PDF
Startup guide for kvm on cent os 6
PDF
Virtual Infrastructure
PDF
Kvm optimizations
KEY
Linux beginner's Workshop
PDF
Snapshots, Replication, and Boot-Environments by Kris Moore
PDF
Lpreservereurobsd2014
PDF
VMware compute driver for OpenStack
PDF
eurobsd2013
PDF
KVM tools and enterprise usage
PPT
Qemu - Raspberry | while42 Singapore #2
PPT
Vmware Command Line
DOCX
List command linux fidora
Optimizing VM images for OpenStack with KVM/QEMU
AnsibleFest 2021 - DevSecOps with Ansible, OpenShift Virtualization, Packer a...
Locally run a FIWARE Lab Instance In another Hypervisors
Ericas-Linux-Plus-Study-Guide
Dev ops
Development platform virtualization using qemu
Building a cloud ready linux image locally using KVM
Big Data Step-by-Step: Infrastructure 1/3: Local VM
Startup guide for kvm on cent os 6
Virtual Infrastructure
Kvm optimizations
Linux beginner's Workshop
Snapshots, Replication, and Boot-Environments by Kris Moore
Lpreservereurobsd2014
VMware compute driver for OpenStack
eurobsd2013
KVM tools and enterprise usage
Qemu - Raspberry | while42 Singapore #2
Vmware Command Line
List command linux fidora

More from OpenNebula Project (20)

PDF
OpenNebulaConf2019 - Welcome and Project Update - Ignacio M. Llorente, Rubén ...
PDF
OpenNebulaConf2019 - Building Virtual Environments for Security Analyses of C...
PDF
OpenNebulaConf2019 - CORD and Edge computing with OpenNebula - Alfonso Aureli...
PDF
OpenNebulaConf2019 - 6 years (+) OpenNebula - Lessons learned - Sebastian Man...
PDF
OpenNebulaConf2019 - Performant and Resilient Storage the Open Source & Linux...
PDF
OpenNebulaConf2019 - Image Backups in OpenNebula - Momčilo Medić - ITAF
PDF
OpenNebulaConf2019 - How We Use GOCA to Manage our OpenNebula Cloud - Jean-Ph...
PDF
OpenNebulaConf2019 - Crytek: A Video gaming Edge Implementation "on the shoul...
PDF
Replacing vCloud with OpenNebula
PDF
NTS: What We Do With OpenNebula - and Why We Do It
PDF
OpenNebula from the Perspective of an ISP
PDF
NTS CAPTAIN / OpenNebula at Julius Blum GmbH
PDF
Performant and Resilient Storage: The Open Source & Linux Way
PDF
NetApp Hybrid Cloud with OpenNebula
PPTX
NSX with OpenNebula - upcoming 5.10
PDF
Security for Private Cloud Environments
PDF
CheckPoint R80.30 Installation on OpenNebula
PDF
DE-CIX: CloudConnectivity
PDF
PDF
Cloud Disaggregation with OpenNebula
OpenNebulaConf2019 - Welcome and Project Update - Ignacio M. Llorente, Rubén ...
OpenNebulaConf2019 - Building Virtual Environments for Security Analyses of C...
OpenNebulaConf2019 - CORD and Edge computing with OpenNebula - Alfonso Aureli...
OpenNebulaConf2019 - 6 years (+) OpenNebula - Lessons learned - Sebastian Man...
OpenNebulaConf2019 - Performant and Resilient Storage the Open Source & Linux...
OpenNebulaConf2019 - Image Backups in OpenNebula - Momčilo Medić - ITAF
OpenNebulaConf2019 - How We Use GOCA to Manage our OpenNebula Cloud - Jean-Ph...
OpenNebulaConf2019 - Crytek: A Video gaming Edge Implementation "on the shoul...
Replacing vCloud with OpenNebula
NTS: What We Do With OpenNebula - and Why We Do It
OpenNebula from the Perspective of an ISP
NTS CAPTAIN / OpenNebula at Julius Blum GmbH
Performant and Resilient Storage: The Open Source & Linux Way
NetApp Hybrid Cloud with OpenNebula
NSX with OpenNebula - upcoming 5.10
Security for Private Cloud Environments
CheckPoint R80.30 Installation on OpenNebula
DE-CIX: CloudConnectivity
Cloud Disaggregation with OpenNebula

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx

TechDay - April - Customizing VM Images

  • 1. Customizing Virtual Machine Images Javier Fontán - OpenNebula Developer
  • 2. qcow2 Format $ qemu-img create -f qcow2 image.qcow2 10G Metadata Cluster Map Cluster Data
  • 3. qcow2 Image With Parent $ qemu-img create -f qcow2 -o backing_file=base.qcow2 image.qcow2 Metadata Cluster Map Cluster Data Metadata Cluster Map Cluster Data Parent
  • 4. ● There are other ways to create your images: ○ virt-install ○ packer.io ○ foreman ○ etc... ● Sometimes modifying already created images is convenient ● Even if you use other image formats you can convert them
  • 5. Mount Image ➔ Convert to raw and use mount -o loop ◆ mount -o loop,offset=32256 image.raw /mnt ➔ Convert to raw and use losetup ◆ losetup /dev/loop0 image.raw ◆ kpartx -a /dev/loop0 ◆ mount /dev/loop0p1 /mnt ➔ Use nbd ◆ modprobe nbd ◆ qemu-nbd -c /dev/nbd0 image.qcow2 ◆ mount /dev/nbd0p1 /mnt
  • 6. libguestfs From its webpage http://libguestfs.org: libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images. You can use this for viewing and editing files inside guests, scripting changes to VMs, monitoring disk used/free statistics, creating guests, P2V, V2V, performing backups, cloning VMs, building VMs, formatting disks, resizing disks, and much more.
  • 7. guestfish - Read or Edit Files $ guestfish -ia image.qcow2 ><fs> cat /var/log/service/error.log ><fs> vi /etc/service.conf $ guestfish -ia image.qcow2 <<EOF upload service.conf /etc/service.conf tar-in ssh-configuration.tar /etc/sshd EOF $ guestfish --ro -i -c qemu:///system -d vm-name ><fs> cat /var/log/service/error.log
  • 8. virt-customize ● Starts custom VM and attach disks and connects to network ● Change passwords, create users ● Move files ● Install packages ● Execute scripts virt-customize [--options] [ -d domname | -a disk.img [-a disk.img ...] ] [--chmod PERMISSIONS:FILE] [--commands-from-file FILENAME] [--copy SOURCE:DEST] [--copy-in LOCALPATH:REMOTEDIR] [--delete PATH] [--edit FILE:EXPR] [--firstboot SCRIPT] [--firstboot-command 'CMD+ARGS'] [--firstboot-install PKG,PKG..] [--hostname HOSTNAME] [--install PKG,PKG..] [--link TARGET:LINK[:LINK..]] [--mkdir DIR] [--move SOURCE:DEST] [--password USER:SELECTOR] [--root-password SELECTOR] [--run SCRIPT] [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR] [--sm-register] [--sm-remove] [--sm-unregister] [--ssh-inject USER[:SELECTOR]] [--truncate FILE] [--truncate-recursive PATH] [--timezone TIMEZONE] [--touch FILE] [--update] [--upload FILE:DEST] [--write FILE:CONTENT] [--no-logfile] [--password-crypto md5|sha256|sha512] [--selinux-relabel] [--sm-credentials SELECTOR]
  • 9. OpenNebula Marketplace Images ● Download CentOS images ● Create CDROM with OpenNebula context packages ● Create script to modify the image ○ Mount CDROM ○ Install context packages ○ Remove cloud-init and NetworkManager packages ○ Install EPEL repository ○ Install growpart packages
  • 10. OpenNebula Images - Create CDROM # Download context packages from github curl -s https://api.github.com/repos/OpenNebula/addon-context- linux/releases | jq -r '.[0].assets[].browser_download_url' | xargs -L1 wget -P repo # Create ISO image with label “EXTRA” genisoimage -o extra-packages.iso -R -J -V EXTRA repo/
  • 11. OpenNebula Images - Prepare Script mkdir /tmp/mount mount LABEL=EXTRA /tmp/mount # Install opennebula context package rpm -Uvh /tmp/mount/one-context*rpm # Remove cloud-init and NetworkManager yum remove -y NetworkManager cloud-init # Install growpart and upgrade util-linux yum install -y epel-release --nogpgcheck yum install -y cloud-utils-growpart --nogpgcheck yum upgrade -y util-linux --nogpgcheck
  • 12. OpenNebula Images - Calling virt-customize # Create an overlay to preserve original image $ qemu-img create -f qcow2 -b $orig $image # Run customization $ virt-customize --attach $ISO_IMAGE --run $script --format qcow2 -v -a $image --root-password disabled
  • 13. Optimizing Images ● qemu-img does not know anything about filesystems ● Blocks not allocated (sparse files) or that contain zeroes are not copied ● Normal file deletion does not zero or deallocate blocks ● Swap partitions contain information if used ● This information can be stripped to make the images smaller ● virt-sparsify to the rescue!
  • 14. Optimizing Images - virt-sparsify There are two ways of doing sparsification: ● Normal Sparsification: ○ Occupies the maximum space of the image ● In Place Sparsification: ○ Create an sparse qcow2 file
  • 15. Optimizing Images - Normal Sparsification ● Create overlay of the image ● Create a file in all filesystems and fill it with zeroes until there is not more space and delete file ● Fill swap partitions with zeroes ● Convert it to a new qcow2 file skipping zero blocks $ TMPDIR=/var/tmp virt-sparsify original.qcow2 new.qcow2
  • 16. Optimizing Images - In Place Sparsification ● Uses trim command, normally used for SSD disks ● Deallocates blocks from filesystem ● Does not require the total amount of disk space ● The qcow2 file contains holes and is not the best one for distribution ● Can be converted to a non sparse qcow2 file ● Can not be used with compression $ virt-sparsify --in-place original.qcow2 new.qcow2
  • 17. Optimizing Images - Compression ● qcow2 images can have the blocks compressed ● Compression rate is less that xz or bzip2 ● Is more convenient as it can be directly used as is ● Use of these images trades disk space for CPU consumption ● Can be done directly in virt-sparsify with --compress (not In Place)
  • 18. qemu-img tips ● There are two qcow2 file formats, pre version 0.10 and newer ○ CentOS 6 does not support post 0.10 version ○ On conversion or creation it can be specified with -o compat=0.10 ● qemu-img < 2.4 does not support creation of delta images with compression ○ This tool can be easily compiled manually ○ Download qemu 2.4 code ○ ./configure ○ make qemu-img
  • 21. Consolidate qcow2 Image $ qemu-img convert -O qcow2 image.qcow2 new_image.qcow2 Metadata Cluster Map Cluster Data Parent Metadata Cluster Map Cluster Data Convert
  • 22. qcow2 Image After Copy $ cp base.qcow2 image.qcow2 Metadata Cluster Map Cluster Data Metadata Cluster Map Cluster Data Copy
  • 23. Create Delta From 2 qcow2 Images $ qemu-img rebase -b base.qcow2 image.qcow2 $ qemu-img convert -O qcow2 -o backing_file=base.qcow2 image.qcow2 new_image.qcow2 Metadata Cluster Map Cluster Data Metadata Cluster Map Cluster Data Copy Metadata Cluster Map Cluster Data Convert