HOW TO USE DISK IMAGES IN LINUX


Copyright (C) 2004 Daniel Brodzik

This document is free software; you may distribute an/or modify it under the terms of the GNU Free Documentation License, either version 1.2 or, at your option, any later version, with no Front-Cover Texts, no Back-Cover Texts, and no Invariant Sections.



INTRODUCTION

Sooner or later, you may have to manipulate a disk image. A disk image is a file that contains all the data on a disk—including the boot sector and file system itself—in one file. Under Windows, the utilities to work with disk images, like WinImage, cost money and are almost never open-source. Under Linux, and most other Unices, the software to do this is included with the operating system, and the commands to manipulate disk images are the very same ones you'd use to manipulate a real disk.


This document explains how to create disk images, how to mount/unmount them, and how to write them to a real disk. Note that you have to be root to use most or all of these commands.



TO CREATE A DISK IMAGE FROM AN EXISTING DISK, type 'cp device image_name'

where:



TO MOUNT A DISK IMAGE, type 'mount image_name mount_point -o loop [-t type]'

where


To unmount a disk image (or anything else, for that matter), type 'umount mount_point' OR 'umount image_file_or_device'. It took me two weeks to figure out that the command to unmount disks was 'umount' instead of 'unmount'!



TO CREATE A NEW, EMPTY DISK IMAGE, type 'dd if=/dev/zero of=filename bs=blocksize count=size' to create an empty file (all zeros/nulls, that is), where:


Now, type 'mkfs.type filename', where:



TO COMPLETELY ERASE A DISK, type 'cp /dev/zero /dev/device'. This procedure COMPLETELY erases a disk, even to the point of removing any existing file system! USE EXTREME CAUTION!

1