[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
All files and directories on a Linux-based system are stored on a Linux filesystem, which is a disk device (such as a hard drive) that is formatted to store a directory tree (see section Files and Directories).
There are two kinds of disk storage on a Linux system: fixed and removable. Fixed storage refers to a disk that is firmly attached to the computer system, and is not intended for casual removal (except when upgrading). Your hard drive (sometimes called "hard disk"), used to store the operating system, application software, and user data, is the prime example of a fixed disk.
The second kind of disk storage is removable storage, disks that are intended to be removed for archiving or transfer to another system. Common examples of removable storage are floppy disk (or "diskette") and CD-ROM drives, where you typically remove the storage media from its drive bay when you're done using it.
On Linux systems, disks are used by mounting them to a directory, which makes the directory tree the disk contains available at that given directory mount point. Disks can be mounted on any directory on the system, but any divisions between disks are transparent--so a system which has, aside from the root filesystem disk mounted on `/', separate physical hard disks for the `/home', `/usr', and `/usr/local' directory trees will look and feel no different from the system that only has one physical disk.
System administrators often mount high-capacity drives on directory trees that will contain a lot of data (such as a `/home' directory tree on a system with a lot of users), and for purposes of fault tolerance, administrators often use several physical hard disks on one system--if there is a disk failure, only the data in that disk is lost.
This chapter describes tools and techniques for manipulating disks and storage media.
25.1 Listing a Disk's Free Space Listing free disk space. 25.2 Listing a File's Disk Usage Listing disk usage. 25.3 Floppy Disks Floppy disks. 25.4 CD-ROMs
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To see how much free space is left on a disk, use df
. Without any
options, df
outputs a list of all mounted filesystems. Six
columns are output, displaying information about each disk: the name of
its device file in `/dev'; the number of 1024-byte blocks the
system uses; the number of blocks in use; the number of blocks
available; the percent of the device used; and the name of the directory
tree the device is mounted on.
$ df RET Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hda1 195167 43405 141684 23% / /dev/hda2 2783807 688916 1950949 26% /usr /dev/hdb1 2039559 1675652 258472 87% /home/webb $ |
This example shows that three filesystems are mounted on the system--the filesystem mounted on `/' is at 23 percent capacity, the filesystem mounted on `/usr' is at 26 percent capacity, and the filesystem mounted on `/home/webb', a home directory, is at 87 percent capacity.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use du
to list the amount of space on disk used by files. To
specify a particular file name or directory tree, give it as an
argument. With no arguments, du
works on the current directory.
It outputs a line for each subdirectory in the tree, listing the space used and the subdirectory name; the last line lists the total amount of space used for the entire directory tree.
$ du RET 8 ./projects/documentation 12 ./projects/source 4 ./projects/etc 24 ./projects 3 ./tmp 27 . $ |
This example shows two subdirectories in the directory tree: `projects' and `tmp'; `projects' contains three additional directories. The amount of disk space used by the individual directories is the total on the last line, 27K.
By default, output is in 1K blocks, but you can specify another unit to use as an option: `-k' for kilobytes and `-m' for megabytes.
$ du -k /usr/local RET |
$ du -m /tmp/cache RET |
Use the `-s' option ("summarize") to output only the last line containing the total for the entire directory tree. This is useful when you are only interested in the total disk usage of a directory tree.
$ du -s /usr/local RET |
$ du -s -k /usr/local RET |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Before you can use a floppy disk for the first time, it must be formatted, which creates an empty filesystem on the disk.
To read or write files to a formatted disk, you mount the floppy on an empty directory, making its filesystem available in the specified directory. Usually, Linux systems have an empty `/floppy' directory for this purpose. (Another general-purpose directory for mounting filesystems is the `/mnt' directory.)
NOTE: While you cannot mount a filesystem on a directory containing other files, you can always create a new directory somewhere to mount a filesystem.
When you mount a disk on a directory, that directory contains all the files and directories of the disk's filesystem; when you later unmount the disk, that directory will be empty--all the files and directories on the disk are still on the disk's filesystem, but the filesystem is no longer mounted.
When you're done using a floppy, you must unmount it first before you remove it from the drive. If you don't, you risk corrupting or deleting some of the files on it--Linux may still be using the mounted files when you remove the disk (see section Turning Off the System).
The following sections show you how to format, mount, and unmount floppies. On many systems, you need superuser privileges to do any one of these actions.
NOTE: For recipes describing use of MS-DOS (and Microsoft Windows) formatted disks under Linux, see Using DOS and Windows Disks.
25.3.1 Formatting a Floppy Disk Formatting a floppy. 25.3.2 Mounting a Floppy Disk Mounting a floppy. 25.3.3 Unmounting a Floppy Disk Unmounting a floppy.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use mke2fs
to format a floppy and make a Linux filesystem. Give
the name of the device file of the floppy drive as an argument--usually
the first removable disk drive, `/dev/fd0'. The floppy must be in
the drive when you give the format command, and any data already on it
will be lost.
$ mke2fs /dev/fd0 RET |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To mount a floppy, use mount
with the `/floppy'
option.(33)
$ mount /floppy RET |
To mount a floppy to a specific directory, use mount
and give as
arguments the device name of the floppy drive (usually `/dev/fd0'
for one-floppy systems) and the name of the directory to mount to.
$ mount /dev/fd0 ~/tmp RET |
Once you have mounted a floppy, its contents appear in the directory you specify, and you can use any file command on them.
$ ls /floppy RET |
$ ls -lR /floppy RET |
NOTE: You can copy files to and from the directory tree that the floppy is mounted on, make and remove directories, and do anything else you could on any other directory tree. But remember, before you remove it, you must first unmount it.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use umount
to unmount a floppy disk, using the name of the
directory it is mounted on as an argument.
$ umount /floppy RET |
NOTE: You can't unmount a disk if your current working directory, the directory you are in, is somewhere in that disk's directory tree.(34) In this case, trying to unmount the disk will give the error that the `/floppy' filesystem is in use; change to a different directory that isn't in the `/floppy' directory tree, and then you can unmount the disk.
Sometimes when you unmount a floppy, the light on the floppy drive will go on and remain on for a few seconds after it has been unmounted. This is because Linux sometimes keeps changes to files in memory before it writes them to disk; it's making sure that the files on the floppy are up-to-date. Simply wait until the light goes off before you remove the floppy from the drive.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As with a floppy disk, before you can use a data CD (compact disc) on your system, you must first mount it on an empty directory. You then unmount it from the directory before you can eject the CD from the CD-ROM drive (you can also eject the disc using software---see section Ejecting an Audio CD).
NOTE: To use audio CDs, see Audio Compact Discs.
25.4.1 Mounting a CD-ROM 25.4.2 Unmounting a CD-ROM
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To mount a CD-ROM on the system, use mount
with the `/cdrom'
option.(35)
$ mount /cdrom RET |
This command makes the contents of the CD-ROM available from the `/cdrom' directory tree. You can use any Linux file command on the files and directories on a CD-ROM, but you can't write to a CD-ROM--the CD-ROM format is read-only, so you can read the disc but not write to it.
Like the `/floppy' directory, the use of the `/cdrom' directory is a standard practice and convenient, but not necessary--you can mount disks in whatever empty directory you like. (You could even, for example, mount discs from the CD-ROM drive to `/floppy' and mount floppy disks to `/cdrom', but why would anyone do that!)
To mount a CD-ROM to a specific directory, use mount
and give as
arguments the name of the device file in `/dev' corresponding to
the CD-ROM drive, and the name of the directory to mount to. This
directory must already exist on the filesystem, and must be empty. If it
doesn't exist, use mkdir
to create it first (see section Making a Directory).
Most Linux systems are set up so that the device file of the first CD-ROM drive is `/dev/cdrom', but the name of the device file may be different, especially if you have a SCSI CD-ROM drive.
$ mount /dev/cdrom /usr/local/share/clipart RET |
The contents of the disc in the CD-ROM drive will then be available in the `/usr/local/share/clipart' directory tree, and you can then use the files and directories on the CD-ROM as you would any other files. For example:
$ tree /usr/local/share/clipart | less RET |
$ cd /usr/local/share/clipart RET |
$ ls /usr/local/share/clipart RET |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use umount
to unmount a CD-ROM; give as an argument the name of
the directory it's mounted on.
$ umount /cdrom RET |
NOTE: As with unmounting any kind of filesystem, make sure that none of the files on the disc are in use, or you won't be able to unmount it. For example, if the current working directory in a shell is somewhere inside the `/cdrom' directory tree, you won't be able to unmount the CD-ROM until you change to a different directory.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |