The Linux Sysadmins Guide to Virtual Disks

From the basics to the advanced.

Tim Bielawa

This work is licensed under the Creative Commons Attribution 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

You can view the latest DocBook 5 XML source to this guide under version control on the web at http://github.com/tbielawa/Virtual-Disk-Guide and an HTML compiled version under http://lnx.cx/docs/vdg/.

Introduction

I was motivated to write this document because I felt the quality of the information regarding commonly used functionality in virtual disk operation was lacking certain specific clear examples. The information that is available is not contained in a central location. Some concepts of the qemu system aren't covered at all. FAQs lead on to having an answer to a particular query, but many lead you to off site resources, some of which are no longer available on the Internet.

What I hope to do is provide a document which will demonstrate the core concepts of virtual disk management. This document will concern itself primarily with the qemu-img tool and common GNU/Linux disk utility tools like fdisk. Most importantly to me, in the case of non-trivial examples, I hope to identify what the relevant technical concepts are how they work up to the final result of each example.


Table of Contents

1. The Virtual Disk Cookbook
1. Introduction
2. Query an Image for Information
3. Converting Between RAW and QCOW2
3.1. Convert an Image from RAW to QCOW2
3.2. Convert an Image from QCOW2 to RAW
4. Creating Disks with Backing Images
5. Creating Simple Images
2. Disk Concepts
1. Introduction
2. Learning by doing (Creating a 1GiB virtual disk from scratch)
2.1. Background on the dd command
2.2. Running dd
2.3. Examining the created file
2.4. Create a Partition Table
2.5. What parted changed
2.6. Creating Partitions
3. Advanced Operations
1. Creating a Mountable Disk
2. Cloning a Physical Disk
A. Appendices
UNITS — decimal and binary prefixes

List of Tables

2.1. Attribute Comparison

List of Examples

1.1. Querying an Image
1.2. Converting from RAW to QCOW2
1.3. Converting from QCOW2 to RAW
1.4. Creating a Disk with a Backing Image
1.5. Using qemu-img to Create RAW Images
2.1. Regular Disk Drive
2.2. Running the dd command
2.3. Creating a loop device
2.4. Creating a partition with fdisk
2.5. Formatting the partition
2.6. Detaching a loop device
3.1. Making a virtual disk from a physical disk

List of Equations

2.1. Calculating the Count
2.2. Total Capacity of a Disk