1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
|
@c $Id: disk-storage.texinfo,v 1.19 2002/01/09 16:58:10 m Exp m $
@node Disk Storage, Printing, Productivity, Productivity
@comment node-name, next, previous, up
@chapter Disk Storage
@cindex disk storage
@cindex storage, disk
@cindex fixed storage
@cindex removable storage
@cindex filesystem
@noindent
All files and directories on a Linux-based system are stored on a Linux
@dfn{filesystem}, which is a disk device (such as a hard drive) that is
formatted to store a directory tree (@pxref{Files and Directories, ,
Files and Directories}).
There are two kinds of disk storage on a Linux system: fixed and
removable. @dfn{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 @dfn{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 @dfn{mounting} them to a directory,
which makes the directory tree the disk contains available at that given
directory @dfn{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
@file{/}, separate physical hard disks for the @file{/home},
@file{/usr}, and @file{/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 @file{/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.
@menu
* Disk Space:: Listing free disk space.
* Disk Usage:: Listing disk usage.
* Floppy Disks:: Floppy disks.
* CD-ROMs:: CD-ROMs.
@end menu
@node Disk Space, Disk Usage, Disk Storage, Disk Storage
@comment node-name, next, previous, up
@section Listing a Disk's Free Space
@cindex listing a disk's free space
@cindex disk, listing the free space on a
@pindex df
@noindent
To see how much free space is left on a disk, use @code{df}. Without any
options, @code{df} outputs a list of all mounted filesystems. Six
columns are output, displaying information about each disk: the name of
its device file in @file{/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.
@itemize @bullet
@item
To see how much free space is left on the system's disks, type:
@example
@cartouche
$ @kbd{df @key{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
$
@end cartouche
@end example
@end itemize
This example shows that three filesystems are mounted on the
system---the filesystem mounted on @file{/} is at 23 percent capacity,
the filesystem mounted on @file{/usr} is at 26 percent capacity, and the
filesystem mounted on @file{/home/webb}, a home directory, is at 87
percent capacity.
@node Disk Usage, Floppy Disks, Disk Space, Disk Storage
@comment node-name, next, previous, up
@section Listing a File's Disk Usage
@cindex listing a file's disk usage
@cindex disk usage, listing a file's
@cindex file, listing disk usage of a
@pindex du
@noindent
Use @code{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, @code{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.
@itemize @bullet
@item
To output the disk usage for the directory tree whose root is the
current directory, type:
@example
@cartouche
$ @kbd{du @key{RET}}
8 ./projects/documentation
12 ./projects/source
4 ./projects/etc
24 ./projects
3 ./tmp
27 .
$
@end cartouche
@end example
@end itemize
This example shows two subdirectories in the directory tree:
@file{projects} and @file{tmp}; @file{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: @samp{-k} for kilobytes and @samp{-m} for megabytes.
@itemize @bullet
@item
To output the disk usage, in kilobytes, of the @file{/usr/local}
directory tree, type:
@example
$ @kbd{du -k /usr/local @key{RET}}
@end example
@item
To show the number of megabytes used by the file @file{/tmp/cache},
type:
@example
$ @kbd{du -m /tmp/cache @key{RET}}
@end example
@end itemize
Use the @samp{-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.
@itemize @bullet
@item
To output @emph{only} the total disk usage of the @file{/usr/local}
directory tree, type:
@example
$ @kbd{du -s /usr/local @key{RET}}
@end example
@item
To output only the total disk usage, in kilobytes, of the
@file{/usr/local} directory tree, type:
@example
$ @kbd{du -s -k /usr/local @key{RET}}
@end example
@end itemize
@node Floppy Disks, CD-ROMs, Disk Usage, Disk Storage
@comment node-name, next, previous, up
@section Floppy Disks
@cindex floppy disks
@cindex disks, floppy
@cindex diskettes
@noindent
Before you can use a floppy disk for the first time, it must be
@dfn{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 @file{/floppy} directory
for this purpose. (Another general-purpose directory for mounting
filesystems is the @file{/mnt} directory.)
@sp .25
@noindent
@strong{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
@dfn{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 (@pxref{Turning Off, , 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.
@sp .25
@noindent
@strong{NOTE:} For recipes describing use of MS-DOS (and Microsoft
Windows) formatted disks under Linux, see @ref{DOS Disks, , Using DOS
and Windows Disks}.
@menu
* Formatting Floppies:: Formatting a floppy.
* Mounting Floppies:: Mounting a floppy.
* Unmounting Floppies:: Unmounting a floppy.
@end menu
@node Formatting Floppies, Mounting Floppies, Floppy Disks, Floppy Disks
@comment node-name, next, previous, up
@subsection Formatting a Floppy Disk
@cindex formatting a floppy disk
@cindex floppy disk, formatting a
@pindex mkisofs
@noindent
Use @code{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, @file{/dev/fd0}. The floppy must be in
the drive when you give the format command, and any data already on it
will be lost.
@itemize @bullet
@item
To format a floppy disk in the first removable floppy drive, type:
@example
$ @kbd{mke2fs /dev/fd0 @key{RET}}
@end example
@end itemize
@node Mounting Floppies, Unmounting Floppies, Formatting Floppies, Floppy Disks
@comment node-name, next, previous, up
@subsection Mounting a Floppy Disk
@cindex mounting a floppy disk
@cindex floppy disk, mounting a
@pindex mount
@pindex ls
@noindent
To mount a floppy, use @code{mount} with the @samp{/floppy}
option.@footnote{This works if your administrator has set up the floppy
drive filesystem for user access---see @ref{Hardware Access, , Letting
Users Access Hardware Peripherals}.}
@itemize @bullet
@item
To mount a floppy, type:
@example
$ @kbd{mount /floppy @key{RET}}
@end example
@end itemize
To mount a floppy to a specific directory, use @code{mount} and give as
arguments the device name of the floppy drive (usually @file{/dev/fd0}
for one-floppy systems) and the name of the directory to mount to.
@itemize @bullet
@item
To mount the floppy in the first floppy drive to @file{~/tmp}, type:
@example
$ @kbd{mount /dev/fd0 ~/tmp @key{RET}}
@end example
@end itemize
Once you have mounted a floppy, its contents appear in the directory you
specify, and you can use any file command on them.
@itemize @bullet
@item
To list the contents of the base directory of the floppy mounted on
@file{/floppy}, type:
@example
$ @kbd{ls /floppy @key{RET}}
@end example
@item
To list the contents of the entire directory tree on the floppy mounted
on @file{/floppy}, type:
@example
$ @kbd{ls -lR /floppy @key{RET}}
@end example
@end itemize
@sp .25
@noindent
@strong{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.
@node Unmounting Floppies, , Mounting Floppies, Floppy Disks
@comment node-name, next, previous, up
@subsection Unmounting a Floppy Disk
@cindex unmounting a floppy disk
@cindex floppy disk, unmounting a
@pindex umount
@noindent
Use @code{umount} to unmount a floppy disk, using the name of the
directory it is mounted on as an argument.
@itemize @bullet
@item
To umount the floppy that is mounted on @file{/floppy}, type:
@example
$ @kbd{umount /floppy @key{RET}}
@end example
@end itemize
@sp .25
@noindent
@strong{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.@footnote{This is sometimes called being ``under the
mount point'' of the disk.} In this case, trying to unmount the disk
will give the error that the @file{/floppy} filesystem is in use; change
to a different directory that isn't in the @file{/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.
@node CD-ROMs, , Floppy Disks, Disk Storage
@comment node-name, next, previous, up
@section CD-ROMs
@cindex CD-ROMs
@cindex data CDs
@noindent
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---@pxref{CD
Eject, , Ejecting an Audio CD}).
@sp .25
@noindent
@strong{NOTE:} To use audio CDs, see @ref{Compact Discs, , Audio Compact
Discs}.
@menu
* Mounting CDs:: Mounting a CD-ROM.
* Unmounting CDs:: Unmounting a CD-ROM.
@end menu
@node Mounting CDs, Unmounting CDs, CD-ROMs, CD-ROMs
@comment node-name, next, previous, up
@subsection Mounting a CD-ROM
@cindex mounting a CD-ROM
@cindex CD-ROM, mounting a
@pindex mount
@noindent
To mount a CD-ROM on the system, use @code{mount} with the @samp{/cdrom}
option.@footnote{This works if your administrator has set up the CD-ROM
drive filesystem for user access---see @ref{Hardware Access, , Letting
Users Access Hardware Peripherals}.}
@itemize @bullet
@item
To mount a CD-ROM on the system, type:
@example
$ @kbd{mount /cdrom @key{RET}}
@end example
@end itemize
This command makes the contents of the CD-ROM available from the
@file{/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 @emph{read} the disc but not
write to it.
Like the @file{/floppy} directory, the use of the @file{/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 @file{/floppy} and
mount floppy disks to @file{/cdrom}, but why would anyone do that!)
To mount a CD-ROM to a specific directory, use @code{mount} and give as
arguments the name of the device file in @file{/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 @code{mkdir} to create it first (@pxref{Making
Directories, , Making a Directory}).
Most Linux systems are set up so that the device file of the first
CD-ROM drive is @file{/dev/cdrom}, but the name of the device file may
be different, especially if you have a SCSI CD-ROM drive.
@itemize @bullet
@item
To mount the disc in the CD-ROM drive to the
@file{/usr/local/share/clipart} directory, type:
@example
$ @kbd{mount /dev/cdrom /usr/local/share/clipart @key{RET}}
@end example
@end itemize
The contents of the disc in the CD-ROM drive will then be available in
the @file{/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:
@itemize @bullet
@item
To peruse a directory tree graph of the CD-ROM's contents, type:
@example
$ @kbd{tree /usr/local/share/clipart | less @key{RET}}
@end example
@item
To change to the root directory of the CD-ROM, type:
@example
$ @kbd{cd /usr/local/share/clipart @key{RET}}
@end example
@item
To list the contents of the root directory of the CD-ROM, type:
@example
$ @kbd{ls /usr/local/share/clipart @key{RET}}
@end example
@end itemize
@node Unmounting CDs, , Mounting CDs, CD-ROMs
@comment node-name, next, previous, up
@subsection Unmounting a CD-ROM
@cindex unmounting a CD-ROM
@cindex CD-ROM, unmounting a
@pindex umount
@noindent
Use @code{umount} to unmount a CD-ROM; give as an argument the name of
the directory it's mounted on.
@itemize @bullet
@item
To unmount the disc in the CD-ROM drive mounted on @file{/cdrom}, type:
@example
$ @kbd{umount /cdrom @key{RET}}
@end example
@end itemize
@sp .25
@noindent
@strong{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 @file{/cdrom} directory tree, you won't be able to
unmount the CD-ROM until you change to a different directory.
|