Mastering KVM Virtualization Mastering KVM Virtualization
Total Page:16
File Type:pdf, Size:1020Kb
NewOutlook.it NewOutlook.it Mastering KVM Virtualization Dive in to the cutting edge techniques of Linux KVM virtualization, and build the virtualization solutions your datacentre demands Humble Devassy Chirammal Prasad Mukhedkar Anil Vettathu BIRMINGHAM - MUMBAI NewOutlook.it Mastering KVM Virtualization Copyright © 2016 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: August 2016 Production reference: 2180816 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-905-4 www.Technet24,ir NewOutlook.it Credits Authors Project Coordinator Humble Devassy Chirammal Kinjal Bari Prasad Mukhedkar Anil Vettathu Proofreader Safis Editing Reviewers Aric Pedersen Indexer Hemangini Bari Ranjith Rajaram Amit Shah Graphics Disha Haria Commissioning Editor Kirk D'Penha Kunal Parikh Production Coordinator Acquisition Editor Shantanu N. Zagade Shaon Basu Cover Work Content Development Editor Shantanu N. Zagade Shweta Pant Technical Editor Saurabh Malhotra Copy Editors Sneha Singh Stephen Copestake NewOutlook.it About the Authors Humble Devassy Chirammal works as a senior software engineer at Red Hat in the Storage Engineering team. He has more than 10 years of IT experience and his area of expertise is in knowing the full stack of an ecosystem and architecting the solutions based on the demand. These days, he primarily concentrates on GlusterFS and emerging technologies, such as IaaS, PaaS solutions in Cloud, and Containers. He has worked on intrusion detection systems, clusters, and virtualization. He is an Open Source advocate. He actively organizes meetups on Virtualization, CentOS, Openshift, and GlusterFS. His Twitter handle is @hchiramm and his website is http://www.humblec.com/. I would like to dedicate this book in the loving memory of my parents, C.O.Devassy and Elsy Devassy, whose steady, balanced, and loving upbringing has given me the strength and determination to be the person I am today. I would like to thank my wife, Anitha, for standing beside me throughout my career and for the effort she put in taking care of our son Heaven while I was writing this book. Also, I would like to thank my brothers Sible and Fr. Able Chirammal, without whose constant support this book would not have been possible. Finally, a special thanks to Ulrich Obergfell for being an inspiration, which helped me enrich my knowledge in virtualization. NewOutlook.it Prasad Mukhedkar is a senior technical support engineer at Red Hat. His area of expertise is designing, building, and supporting IT infrastructure for workloads, especially large virtualization environments and cloud IaaS using open source technologies. He is skilled in KVM virtualization with continuous working experience from its very early stages, possesses extensive hands-on and technical knowledge of Red Hat Enterprise Virtualization. These days, he concentrates primarily on OpenStack and Cloudforms platforms. His other area of interest includes Linux performance tuning, designing highly scalable open source identity management solutions, and enterprise IT security. He is a huge fan of the Linux "GNU Screen" utility. Anil Vettathu started his association with Linux in college and began his career as a Linux System Administrator soon after. He is a generalist and is interested in Open Source technologies. He has hands on experience in designing and implementing large scale virtualization environments using open source technologies and has extensive knowledge in libvirt and KVM. These days he primarily works on Red Hat Enterprise Virtualization, containers and real time performance tuning. Currently, he is working as a Technical Account Manager for Red Hat. His website is http://anilv.in. I'd like to thank my beloved wife, Chandni, for her unconditional support. She took the pain of looking after our two naughtiest kids, while I enjoyed writing this book. I'd like also like to thank my parents, Dr Annieamma & Dr George Vettathu, for their guidance and to push me hard to study something new in life. Finally, I would like to thank my sister Dr. Wilma for her guidance and my brother Vimal. NewOutlook.it About the Reviewers Aric Pedersen is the author of cPanel User Guide and Tutorial and Web Host Manager Administration Guide, both written for Packt Publishing. He has also served as a reviewer for CUPS Administrative Guide, Linux E-mail, and Linux Shell Scripting Cookbook, published by Packt Publishing. He has over 11 years of experience working as a systems administrator. He currently works for http://www.hostdime.com/, the world-class web host and global data center provider, and also for https://netenberg.com/, the makers of Fantastico, the world's most popular web script installer for cPanel servers. I would like to thank Dennis and Nicky, who have helped me in innumerable ways with their friendship over the past several years. I'd also like to thank my mother and the rest of my family, Allen, Ken, Steve, and Michael, because without them, nothing I've done would have been possible. NewOutlook.it Ranjith Rajaram works as a Senior Principle Technical Support Engineer at a leading open source Enterprise Linux company. He started his career by providing support to web hosting companies and managing servers remotely. He has also provided technical support to their end customers. Early in his career, he has worked on Linux, Unix, and FreeBSD platforms. For the past 12 years, he has been continuously learning something new. This is what he likes and admires about technical support. As a mark of respect to all his fellow technical support engineers, he has included "developing software is humane but supporting them is divine" in his e-mail signature. At his current organization, he is involved in implementing, installing, and troubleshooting Linux environment networks. Apart from this, he is also an active contributor to the Linux container space, especially using Docker-formatted containers. As a reviewer this is his second book. His earlier book was Learning RHEL Networking from Packt Publishing. Amit Shah has been working on FOSS since 2001, and QEMU/KVM virtualization since 2007. He currently works as a senior software engineer in Red Hat. He has reviewed KVM Internals and Performance Tuning chapters. NewOutlook.it www.PacktPub.com eBooks, discount offers, and more Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser NewOutlook.it NewOutlook.it NewOutlook.it A big thank you to the KVM, QEMU, libvirt & oVirt community for wonderful opensource projects. We would also thank our reviewers and readers for supporting us. NewOutlook.it NewOutlook.it Table of Contents Preface ix Chapter 1: Understanding Linux Virtualization 1 What is virtualization? 2 Why should I use Linux virtualization? 2 Types of virtualization 2 Advantages of virtualization 3 Operating system virtualization/partitioning 7 Full virtualization 10 Paravirtualization 11 Hardware assisted virtualization 12 Introducing VMM/hypervisor 13 Type 1 and Type 2 hypervisors 14 Open source virtualization projects 15 Xen 16 Introducing KVM 17 High-level overview of KVM 18 What Linux virtualization offers you in the cloud 19 Summary 19 Chapter 2: KVM Internals 21 Getting acquainted with libvirt and its implementation 21 Internal workings of libvirt 24 Time to think more about QEMU 32 Qemu – KVM internals 35 Data structures 37 Threading models in QEMU 41 KVM in action 43 KVM APIs 46 [ i ] NewOutlook.it Table of Contents Anonymous inodes and file structures 47 Data structures 48 Execution flow of vCPU 52 Summary 57 Chapter 3: Setting Up Standalone KVM Virtualization 59 Getting acquainted with libvirt 60 Host system requirements 62 Determining the right system requirements for your environment 63 Physical CPU 63 CPU cores 64 Physical memory 65 Storage 66 Network 67 Setting up the environment 67 Installing