libguestfs tools for viewing and modifying virtual machine disk images

Similar documents
Virtualization Management the ovirt way

Windows Template Creation Guide. How to build your own Windows VM templates for deployment in Cloudturk.

Oracle VM Server Recovery Guide. Version 8.2

Module I-7410 Advanced Linux FS-11 Part1: Virtualization with KVM

Use Cases for Docker in Enterprise Linux Environment CloudOpen North America, 2014 Linda Wang Sr. Software Engineering Manager Red Hat, Inc.

LSN 10 Linux Overview

RED HAT ENTERPRISE VIRTUALIZATION & CLOUD COMPUTING

Professional Xen Visualization

Red Hat System Administration 1(RH124) is Designed for IT Professionals who are new to Linux.

Options in Open Source Virtualization and Cloud Computing. Andrew Hadinyoto Republic Polytechnic

Red Hat Enterprise Linux 7 Virtualization Getting Started Guide

Navigating the Rescue Mode for Linux

Advanced Server Virtualization: Vmware and Microsoft Platforms in the Virtual Data Center

RPM Brotherhood: KVM VIRTUALIZATION TECHNOLOGY

EXPLORING LINUX KERNEL: THE EASY WAY!

RedHat (RHEL) System Administration Course Summary

Restoring a Suse Linux Enterprise Server 9 64 Bit on Dissimilar Hardware with CBMR for Linux 1.02

Virtualization on Linux Using KVM and libvirt. Matt Surico Long Island Linux Users Group 11 March, 2014

KVM, OpenStack, and the Open Cloud

KVM, OpenStack, and the Open Cloud

RH033 Red Hat Linux Essentials or equivalent experience with Red Hat Linux..

Week Overview. Installing Linux Linux on your Desktop Virtualization Basic Linux system administration

SCVMM Driver for Libvirt

How to Restore a Linux Server Using Bare Metal Restore

With Red Hat Enterprise Virtualization, you can: Take advantage of existing people skills and investments

BLACK BOX. Quick Start Guide. Virtual Central Management System (VCMS) Works with LES Series Console Servers. LES-VCMS. Customer Support Information

UNIX - FILE SYSTEM BASICS

Installing & Using KVM with Virtual Machine Manager COSC 495

A Virtualized Linux Integrity Subsystem for Trusted Cloud Computing

Paragon ExtFS for Windows

How to create a Virtual machine from a Macrium image backup

Linux FTP Server Setup

LAMP Quickstart for Red Hat Enterprise Linux 4

How to Backup XenServer VM with VirtualIQ

Computer Virtualization in Practice

How To Boot A Cloud Instance On Ubuntu (Oracle) On Ubuntusa (Orca) On A Ubuntu Cloud Instance (Ora) On An Ubuntu 3.5

Onboarding VMs to Cisco OpenStack Private Cloud

Red Hat Linux Administration II Installation, Configuration, Software and Troubleshooting

Linux System Administration on Red Hat

Introduction to ovirt

Buildroot for Vortex86EX (2016/04/20)

Deploying a Virtual Machine (Instance) using a Template via CloudStack UI in v4.5.x (procedure valid until Oct 2015)

PARALLELS SERVER BARE METAL 5.0 README

Next Generation Now: Red Hat Enterprise Linux 6 Virtualization A Unique Cloud Approach. Jeff Ruby Channel Manager jruby@redhat.com

SUSE Cloud Installation: Best Practices Using an Existing SMT and KVM Environment

Operating Systems Virtualization mechanisms

KVM Security Comparison

Red Hat Certifications: Red Hat Certified System Administrator (RHCSA)

Deploying Red Hat Enterprise Virtualization On Tintri VMstore Systems Best Practices Guide

red hat enterprise virtualization: vmware migration

Red Hat Enterprise Linux 6 Virtualization Getting Started Guide

CS 103 Lab Linux and Virtual Machines

Developing tests for the KVM autotest framework

Red Hat enterprise virtualization 3.0 feature comparison

USB 2.0 Flash Drive User Manual

2972 Linux Options and Best Practices for Scaleup Virtualization

System administration basics

Acronis Backup & Recovery 10 Server for Linux. Update 5. Installation Guide

Operating System Structures

Introduction. dnotify

CS197U: A Hands on Introduction to Unix

OpenNebula Open Souce Solution for DC Virtualization

Programming for GCSE Topic H: Operating Systems

ovirt: Open Your Virtual Data Center

ovirt Introduction James Rankin Product Manager Red Hat Virtualization Management the ovirt way

PARALLELS SERVER 4 BARE METAL README

Installing VMware Tools on Clearswift v4 Gateways

October Gluster Virtual Storage Appliance User Guide

Acronis Backup & Recovery 10 Server for Linux. Installation Guide

OpenNebula Open Souce Solution for DC Virtualization

ovirt self-hosted engine seamless deployment

Virtualization in Linux KVM + QEMU

Introduction to Operating Systems

RED HAT ENTERPRISE VIRTUALIZATION SCALING UP LOW LATENCY, VIRTUALIZATION, AND LINUX FOR WALL STREET OPERATIONS

Red Hat Enterprise Linux 6 Essentials. Red Hat Enterprise Linux 6 Essentials

Open Source Virtualization

IBM Cloud Manager with OpenStack

OLH: Oracle Loader for Hadoop OSCH: Oracle SQL Connector for Hadoop Distributed File System (HDFS)

SUSE Virtualization Technologies Roadmap

Automated deployment of virtualization-based research models of distributed computer systems

GL-250: Red Hat Linux Systems Administration. Course Outline. Course Length: 5 days

The Tor VM Project. Installing the Build Environment & Building Tor VM. Copyright The Tor Project, Inc. Authors: Martin Peck and Kyle Williams

Backup of ESXi Virtual Machines using Affa

KVM Architecture Overview

Cloud Platform Comparison: CloudStack, Eucalyptus, vcloud Director and OpenStack

6422: Implementing and Managing Windows Server 2008 Hyper-V (3 Days)

Understanding MySQL storage and clustering in QueueMetrics. Loway

Acronis Backup & Recovery 11.5

How to Install Windows on Xen TM 3.0

KVM Virtualization in RHEL 7 Made Easy

How you configure Iscsi target using starwind free Nas software & configure Iscsi initiator on Oracle Linux 6.4

Using Red Hat Enterprise Linux with Georgia Tech's RHN Satellite Server Installing Red Hat Enterprise Linux

NI Real-Time Hypervisor for Windows

Migrating LAMP stack from x86 to Power using the Server Consolidation Tool

VMware Server 2.0 Essentials. Virtualization Deployment and Management

RED HAT ENTERPRISE VIRTUALIZATION

Transcription:

libguestfs tools for viewing and modifying virtual machine disk images Richard W.M. Jones Software Engineer Red Hat rjones@redhat.com November 2012 1 Introduction The libguestfs project is nearly 4 years old, so for my rare opportunity to talk at the KVM Forum I thought I d cover where we ve got to in those 4 years, and also talk about some of the ways we are using the new features in KVM. 2 Overview of libguestfs libguestfs is a C library with a simple, long-term stable API that contains about 400 different calls. It also has bindings in many popular high-level languages, including Perl, Python, Ruby, OCaml, Java, PHP, and more. The library lets you write simple programs to create, view and modify disk images, like the one in Appendix A. There are many tools which use libguestfs: guestfish Interactive and scriptable shell. guestmount Mount filesystems from any guest or disk image on the host. 1

virt-alignment-scan Check alignment of partitions in guests. virt-cat Display a file from a guest. virt-copy-in Copy files and directories into a guest. virt-copy-out Copy files and directories out of a guest. virt-df Display disk usage of a guest. virt-edit Edit a file in a guest. virt-filesystems Display the partitions, filesystems, logical volumes etc. in a guest. virt-inspector Inspect a guest and produce a report detailing the operating system, version, applications installed and more. virt-ls List files and directories in a guest. virt-make-fs Make a new filesystem. virt-rescue Rescue mode for guests. virt-resize Resize a guest. virt-sparsify Make a disk sparse. virt-sysprep Reset a guest to factory configuration. virt-tar-in Copy files from a tarball into a guest. virt-tar-out Copy files out of a guest into a tarball. virt-win-reg Display and edit the Windows Registry in a guest. and libguestfs is increasingly being used by major projects: BoxGrinder & Oz Projects that can create guests from scratch. OpenStack Uses libguestfs to inject files into guests. virt-manager Uses libguestfs to display icons and applications in guests. virt-v2v & virt-p2v Migrate between physical machines and different hypervisors. 2

3 Using guestfish to view and inject files An easy way to get started with libguestfs is to use our shell scripting tool, guestfish 1 to open up a disk image and look inside. You can open up almost any type of disk image, such as a raw file, qcow2 file, or a logical volume or partition that contains a virtual machine. You don t need to be root, unless you need root to access the device. Simply do: $ guestfish -a disk.img -i Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: help for help on commands man to read the manual quit to quit the shell Operating system: Red Hat Enterprise Linux Server release 6.3 (Santiago) /dev/vg_rhel6x32/lv_root mounted on / /dev/sda1 mounted on /boot You can now use guestfish commands to list files and directories and create files: ><fs> ls / bin boot cgroup [etc] ><fs> write-append /etc/rc.d/rc.local "service sshd start" ><fs> cat /etc/rc.d/rc.local #!/bin/sh touch /var/lock/subsys/local service sshd start Some useful commands include: 1 http://libguestfs.org/guestfish.1.html 3

cat Display small text files. edit Edit a file. less Display longer files. ll List (long) directory. ls List directory. mkdir Make a directory. rm Remove a file. touch Touch a file. upload Upload a local file to the disk. write Create a file with content. As there are hundreds of commands, it s a good idea to read the guestfish(1) and guestfs(3) 2 man pages. These are also available online at the website 3. 4 Introducing virt-rescue virt-rescue 4 is a good way to rescue virtual machines that don t boot, or just generally make ad hoc changes to virtual machines. It s like a rescue CD for virtual machines. virt-rescue is a little different from guestfish in that you get an ordinary shell and ordinary tools. However unlike guestfish, virt-rescue cannot be used from shell scripts, so it s not useful if you want to make repeatable changes to lots of your guests. You must not use virt-rescue on running VMs. 2 http://libguestfs.org/guestfs.3.html 3 http://libguestfs.org 4 http://libguestfs.org/virt-rescue.1.html 4

If you had a libvirt guest called Fedora then: # virt-rescue -d Fedora [lots of boot messages] Welcome to virt-rescue, the libguestfs rescue shell. Note: The contents of / are the rescue appliance. You have to mount the guest s partitions under /sysroot before you can examine them. ><rescue> lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_root vg_f13x64 -wi-a- 7.56g lv_swap vg_f13x64 -wi-a- 1.94g ><rescue> mount /dev/vg_f13x64/lv_root /sysroot/ [ 107.912813] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null) ><rescue> ls -l /sysroot/etc/fstab -rw-r--r--. 1 root root 781 Sep 16 2010 /sysroot/etc/fstab ><rescue> vi /sysroot/etc/fstab There is a lot more information about virt-rescue in the man page virtrescue(1). 5 New features in libguestfs 1.20 At the end of this year (2012) we hope to make a major new release of libguestfs. Since the last version was released in May 2012, this represents over 6 months of development effort, and it includes and uses some major new features from KVM. The new version will (optionally) use libvirt to manage the libguestfs appliance. From the point of view of libguestfs this hides the complexity of dealing with the qemu command line. It also lets us leverage libvirt for: security The appliance will now be encapsulated with svirt (SELinux or AppArmor) to prevent a malicious guest from being able to take over the qemu process and escape to attack the host. 5

remote access libvirt will provide remote access to guests, using the ordinary libvirt remote URIs. We are also using new features from KVM: virtio-scsi The primary new feature is Paolo Bonzini s virtio-scsi driver, which is far superior in both performance and features compared to virtio-blk. up to 255 disks With virtio-scsi, we can now access up to 255 disks at a time, and possibly many more in future. hot-plugging of disks With virtio-scsi and libvirt together we are able to hotplug (add and remove) disks, giving libguestfs users a lot more performance and flexibility. sparsification Coming soon, we ll be able to trim filesystems and cause the host backing file to become sparse. qcow2 v3 We use the new version of qcow2 wherever possible because of its performance benefits. 6

A Example: how to inspect a virtual machine disk #!/usr/bin/perl -w use strict; use Sys::Guestfs; if (@ARGV < 1) { die "usage: inspect_vm disk.img" my $disk = $ARGV[0]; my $g = new Sys::Guestfs (); $g->add_drive_opts ($disk, readonly => 1); $g->launch (); # Ask libguestfs to inspect for operating systems. my @roots = $g->inspect_os (); if (@roots == 0) { die "inspect_vm: no operating systems found"; for my $root (@roots) { # Print basic information about the operating system. printf " Product name: %s\n", $g->inspect_get_product_name ($root); printf " Version: %d.%d\n", $g->inspect_get_major_version ($root), $g->inspect_get_minor_version ($root); # Mount up the disks, like guestfish -i. my %mps = $g->inspect_get_mountpoints ($root); my @mps = sort { length $a <=> length $b (keys %mps); for my $mp (@mps) { eval { $g->mount_ro ($mps{$mp, $mp) ; 7

if ($@) { print "$@ (ignored)\n" # If /etc/issue.net file exists, print up to 3 lines. my $filename = "/etc/issue.net"; if ($g->is_file ($filename)) { printf "--- %s ---\n", $filename; my @lines = $g->head_n (3, $filename); print "$_\n" foreach @lines; # Unmount everything. $g->umount_all () 8