rhl6u146

Lemur zaprasza

Red Hat® Linux 6 Unleashed










Chapter 15: Filesystems, Disks, and Other Devices





Previous
ChapterNext
Chapter










Sections in this Chapter:












Character
Devices





Mounting
with the User Mount Tool





Repairing
Filesystems






Block
Devices





Setting
Up Filesystems





Various Kinds of Hardware











Creating
New Filesystems





Character
Devices






The mount
Command





Creating
and Editing Filesystems Graphically with fsconf











 

Previous
SectionNext
Section





Various Kinds of Hardware






























There are block devices under Linux for representing all sorts
of random access devices: floppy disks, hard disks (XT, EIDE, and SCSI), Zip
drives, CD-ROM drives, ramdisks, and loopback devices.



Hard Disks
Hard disks
are
large enough to make it useful to keep different filesystems on different parts
of the hard disk. The scheme for dividing these disks is called
partitioning. Although it is common for computers
running MS DOS to have only one partition, it is possible to have several
different partitions on each disk. The summary of how the disk is partitioned is
kept in its partition table.



The Partition Table
A hard disk
might
be divided like this:



$ fdisk -l
Disk /dev/hda: 128 heads, 63 sectors, 970 cylinders
Units = cylinders of 8064 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 177 713632+ 6 FAT16
/dev/hda2 179 970 3193344 5 Extended
/dev/hda3 178 178 4032 a OS/2 Boot Manager
/dev/hda5 179 696 2088544+ 6 FAT16
/dev/hda6 920 970 205600+ 6 FAT16
/dev/hda7 697 762 266080+ 82 Linux swap
/dev/hda8 763 919 632992+ 83 Linux

Disk /dev/hdb: 255 heads, 63 sectors, 523 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 * 2 383 3068415 5 Extended
/dev/hdb2 384 523 1124550 83 Linux
/dev/hdb5 2 192 1534176 6 FAT16
/dev/hdb6 193 383 1534176 6 FAT16

Note that the partitions on the first disk have names starting
with /dev/hda and those on the second have names
starting with /dev/hdb. The number of the partition
follows these prefixes.


Note -
All is not quite as simple as it could be in the partition table, however. Early
hard disk drives on PCs were quite small (about 10MB), so you were limited to a
small number of partitions, and the format of the partition table originally
allowed for only four partitions. Later on, this was too great a restriction,
and the extended partition was introduced as a
workaround.


Inside each extended partition is another partition
table. This enables the extended partition to be divided, in the same way, into
four logical partitions. Partitions that
aren't inside an extended partition are sometimes referred to
as primary
partitions.


Disk Geometry
The units
of
the table in the last section are cylinders. The
partition table allocates a consecutive block of cylinders to each partition.
The term cylinder itself dates from the days when it was possible to
remove a disk pack from a UNIX machine and point to the various parts. That
can't be done here, so here's another way of looking at
it.Imagine that a hard disk is in fact a stack of
pizzas. Each of the pizzas is a platter, a
disk-shaped surface with a magnetic coating designed to hold magnetic encodings.
Both sides of these platters are used. These platters rotate around the spindle,
like the spindle in a record player. The hard disk has a movable arm containing
several disk heads. Each side of each platter has
a separate disk head. If you were to put your fingers between the pizzas while
keeping them straight, your fingers are the same as the arrangement of the heads
on the arm. All the parts of the platters that the heads pass over in one
rotation of the disk is called a cylinder. The parts of a single platter
that one head passes over in one rotation is called a
track. Each track is divided into sectors,
as if the pizzas had been already sliced for you. The
layout of a disk, its geometry, is described by the number of cylinders,
heads, and sectors comprising the disk. Another important feature is the
rotational speed of the disk; generally, the faster it is, the faster the hard
disk can read or write data.You can discover the
geometry of one of your hard disks by using the
hdparm command, and typical output might look like
this:



$ hdparm -g /dev/hda

/dev/hda:
geometry = 970/128/63, sectors = 7825932, start = 0

$ hdparm -g /dev/hdb

/dev/hdb:
geometry = 523/255/63, sectors = 8406720, start = 0

As you can see from the geometry specified in this example,
these are the drives discussed previously.


Note -
IBM PCs with older BIOSs can have difficulty with large disks; see the Linux
Large-Disk
mini HOWTO.


Floppy Disks
Floppy disks are
removable
low-capacity storage media. As storage devices, they are far slower than hard
disks, but they have the advantage of being removable, which makes them good
media for transporting modest amounts of data.The
block devices corresponding to the floppy disks begin with the letters
fd; /dev/fd0 is the
first, and any additional ones have increasing numbers. There are many possible
formats for a floppy disk, and the kernel needs to know the format (geometry) of
a disk to read it properly. Linux can usually work out the correct format, so
the automatic devices /dev/fd0 (plus
/dev/fd1 and so on for extra floppy drives) are
usually sufficient, but if for some reason it is necessary to specify the exact
format, further device names are provided. The device
/dev/fd0H1440, for example, denotes a 1.44MB
high-density floppy. There are many more devices indicating obscure formats,
both older lower-capacity formats and other nonstandard extra-high-capacity
formats. You can even create your own floppy disk formats using the serfdprm
program.The most common reason to use the
specific-format device names is that you are formatting a floppy for the first
time. In this situation, the disk is not yet readable, so the kernel will not be
able to autoprobe an existing format. You need to use the name
/dev/fd0H1440, for example, to denote a high-density
3.5-inch disk in the first floppy drive. For device names representing other
formats, refer to the fd manual page. Section 4 of the manual is devoted to
devices.The process of formatting a floppy is
completely destructive to the data on it, and because it requires writing to the
actual device itself, it requires root privileges.
It is done like this:



# fdformat /dev/fd0H1440
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
Verifying ... done

After you have formatted a floppy, don't forget to use mkfs
to build a filesystem on it. (See the section "Creating
New Filesystems" earlier in this chapter.)
If you have X Windows running, you can use
the user mount tool previously discussed in this chapter to accomplish the same
tasks by clicking
buttons.



CD-ROM Drives
The CD-ROM drive
is
fundamentally another kind of read-only block device. They are mounted in just
the same way as other block devices. CD-ROMs almost always contain standard ISO
9660 filesystems, often with some optional extensions. There is no reason,
however, why you should not use any other filesystem. Once you have mounted your
CD-ROM, it behaves like any other read-only
filesystem.You can set up and mount your CD-ROM drive
using the Red Hat File System Manager, as explained previously, or by using the
mount command:



# mount /dev/cdrom -t iso9660 /mnt/cdrom

The directory /mnt/cdrom is a common place to mount one's
CD-ROM drive under Red Hat Linux because it is where the graphical package
manager Glint expects to find the contents of the Red Hat installation CD-ROM,
for example.The device name
/dev/cdrom is commonly used as a symbolic link to
the actual device name corresponding to the CD-ROM. This is because at the time
the CD-ROM drive became available for the PC, there was no cheap standard
interface for these devices. Each manufacturer chose or invented an interfacing
scheme that was incompatible with everyone else's. For this reason, there
are about a dozen different drivers for CD-ROM drives available in the Linux
kernel. SCSI would have been a sensible standard to use, but although SCSI
CD-ROM drives are available, they're not particularly
popular.The ATAPI standard
arrived in time to ensure that all non-SCSI CD-ROM drives at quad speed or
faster use a standard interface, so the situation is far simpler for new CD-ROM
drives. Support for ATAPI CD-ROMs is handled by one driver for all drives. The
ATAPI standard also provides for very large hard disk drives and tape drives.
ATAPI CD-ROM drives are attached to IDE interfaces, just like hard disks, and
they have the same set of device names as hard disk
devices.Because CD-ROMs
come
already written, there is no need to partition them. They are accessed using the
device names for whole-disk devices: /dev/hda,
/dev/hdb, and so on.The
ISO 9660 standard specifies a standard format for the
layout of data on CD-ROMs. It restricts filenames to no more than 32 characters,
for example. Most CD-ROMs are written with very short filenames for
compatibility with MS-DOS. To support certain UNIX features such as symbolic
links and long filenames, developers created a set of extensions called Rock
Ridge, and the Linux kernel will automatically detect and use the Rock Ridge
extensions.CD-ROM drives also
usually support the playing of audio CDs, and there are many Linux programs for
controlling the CD-ROM drive in the same way as you might control a CD player.
The multimedia package on the Red Hat 6.0 CD-ROM contains the xplaycd program
for playing CDs. To make it work, you need to set the
/dev/cdrom symbolic link to point to your real
CD-ROM
device.If
you have X Windows running, you can use the user mount tool previously discussed
in this chapter to accomplish the same tasks by clicking
buttons.



Loopback Devices
Loopback devices
enable
you to store new filesystems inside regular files. You might want to do this to
prepare an emulated hard disk image for DOSEMU, an install disk, or just to try
a filesystem of a new type or an ISO9660 CD-ROM image before writing it to the
CD writer.



Mounting Filesystems on Files
Under UNIX, you need root
permissions
to change the system's filesystem structure; even if you own a file and the
mount point on which you want to mount it, only root
can do this, unless the user option has been
specified in /etc/fstab for this
filesystem.When a filesystem is mounted using the
loopback driver, the file containing the filesystem plays the role of the block
device in the mount command and
/etc/fstab. The kernel talks to the block device
interface provided by the loopback device driver, and the driver forwards
operations to the file:



# mount $(pwd)/rtems.iso -t iso9660 -o ro,loop /mnt/test
# ls -F /mnt/test
INSTALL LICENSE README SUPPORT c/ doc/ rr_moved/
# mount | grep loop | fold -s
/home/james/documents/books/Sams/Linux-Unleashed-2/ch9/tmp/rtems.iso on
/mnt/test type iso9660 (ro,loop=/dev/loop0)
# umount /mnt/test

Once the loopback filesystem is mounted, it's a normal
filesystem.



Using Encrypted Filesystems
Loopback filesystems
offer
even more features--encryption, for example. A loopback filesystem can be
configured to decrypt data from the block device on-the-fly so that the data on
the device is useless to people even if they can read it--unless they have the
password. The mount command prompts for the password
at the appropriate time. To make this work, first you have to use
mkfs to generate
a
filesystem on the encrypted block device; losetup is
used to associate a loop device and encryption method with the block device you
want to use (in the following case, a floppy drive):



# /sbin/losetup -e DES /dev/loop0 /dev/fd1
Password:
Init (up to 16 hex digits):
# /sbin/mkfs -t ext2 -m0 /dev/loop0
mke2fs 1.10, 24-Apr-97 for EXT2 FS 0.5b, 95/08/09
Linux ext2 filesystem format
Filesystem label=
360 inodes, 1440 blocks
0 blocks (0.00) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
# losetup -d /dev/loop0

As shown previously, losetup's
-e option associates an encryption method and block
device with a loopback device. The -d option deletes
this association and erases the stored encryption
key.When the filesystem has been created on the
encrypted device, it can be mounted
in a
manner similar to the normal case:



# /sbin/losetup -d /dev/loop0
# mount /dev/fd1 -t ext2 -o loop=/dev/loop0,encryption=DES /mnt/test
Password:
Init (up to 16 hex digits):
# ls /mnt/test
lost+found

Usually, the whole process of using an encrypted filesystem can
be set up
for
ordinary users by adding the appropriate line to
/etc/fstab:



$ mount /mnt/test
Password:
Init (up to 16 hex digits):
$ ls -ld /mnt/test
drwxrwxrwx 3 james root 1024 Sep 14 22:04 /mnt/test

In this example, root has enabled
users to mount encrypted filesystems by including this line in
/etc/fstab:



/dev/fd1 /mnt/test ext2 user,loop,encryption=DES

Additionally, ownership of the top-level directory on the floppy
disk has been given to the user james because it is
presumably his floppy disk. If root had not done
this, james would have been able to mount his
filesystem but not read it. It was an essential step, but it turns out that in
this example, root has made a fatal mistake. As well
as changing the ownership of the filesystem's
root directory, root has
changed the directory's mode as well. This means that once the unsuspecting
james has supplied his secret password, any user on
the system can read and write the files on the floppy. This underlines the fact
that encryption alone is not sufficient for safety. Careful thought is also
essential.In the previous case, the file ownerships
and permissions have turned out to be more of a hindrance than a help. It is
probably better to use an MS-DOS filesystem on the encrypted device
because
ownership is automatically given away to the user mounting the disk and the file
modes are set correctly:



$ ls -ld /mnt/floppy/
drwxr-xr-x 2 james users 7168 Jan 1 1970 /mnt/floppy/

However, there are still two problems with this strategy. First,
it is not possible to make an encrypted filesystem easily on a floppy because
the mkfs.msdos program needs to know the geometry for the device on which it is
creating the filesystem and the loopback
device
drivers don't really have geometries. Second, once your encrypted
ext2 filesystem is mounted, the superuser can still
read your data.
The encryption methods outlined previously are not available in
standard kernels because most useful forms of encryption technology are not
legally exportable from the United States. However, they are already available
outside the United States at ftp://ftp.replay.com/crypto/linux/all/linux-crypt-kernelpatches.tar.gz.
This
site is in Holland. You need to apply these patches to your kernel and recompile
it in order to use the DES and IDEA encryption methods with loopback devices.
The patches were made against version 2.0.11 of the Linux kernel, but they work
perfectly well with the kernel supplied with Red Hat Linux
6.0.To summarize, encrypted filesystems can be useful
for some kinds of data (for example, for storing digital signatures for
important system binaries in such a way that they can't be tampered with),
but their usefulness to users other than root is
limited. Of course, all the ordinary file encryption mechanisms are still
available to and useful for
ordinary
users.



Other Block Devices
Although hard disks, floppy disks, and CD-ROM drives are
probably the most heavily used block devices, there are other kinds of block
devices, including ramdisks and Zip drives.



Ramdisks
Ramdisks are
block
devices that store their data in RAM rather than on a disk. This means they are
very fast; nevertheless, ramdisks are rarely used with Linux because Linux has a
very good disk-caching scheme, which provides most of the speed benefit of a
ramdisk but not the fixed cost in memory.The most
common use for ramdisks is to serve as a root
filesystem while Linux is being installed. A compressed filesystem image is
loaded into a ramdisk, and the installation process is run from this disk. The
ramdisk's filesystem can be larger than a single floppy because the image
is compressed on the floppy.Although ramdisks are
useful with operating systems lacking effective disk buffering, they offer
little performance advantage under Linux. If you want to try a ramdisk, they
work just like any other block device. For example, to mount a ramdisk as
/tmp, you add this line to
/etc/fstab:



/dev/ram /tmp ext2 defaults 0 0

Then you create and mount an ext
filesystem with the following:



/sbin/mkfs -t ext2 /dev/ram
mount /tmp

Any performance benefits from doing this are hard to find, but
you might find that this helps in unusual
circumstances.The principal advantage of ramdisks is
that they provide great flexibility in the boot process. Although it is possible
to recompile a kernel including support for your hardware, it makes the initial
installation process difficult. Historically, programmers worked around this
problem by providing dozens of different installation boot disks, each with
support for one or two items of boot hardware (SCSI cards and CD-ROM drives, for
example).A simpler solution is to exploit loadable
kernel modules. Instead of having separate boot disks for each type of hardware,
all containing different kernels, it is simple to provide just one boot disk
containing a modular kernel and the module utilities
themselves.A compressed filesystem is loaded from the
floppy disk into a ramdisk by the kernel loader, LILO, at the same time the
kernel is loaded. The kernel mounts this filesystem and runs a program
(/linuxrc) from it. This program then mounts the "real"
root filesystem and exits, enabling the kernel to
remount the real root filesystem on
/. This system is convenient to set up, and the
process of creating initial ramdisks had been automated by Red Hat Software (see
the manual page for mkinitrd). Red Hat Linux systems
whose root filesystem is on a SCSI device have a
modular kernel and boot by this
method.



Zip Drives
Zip drives
are
drives providing removable 100MB cartridges. They come in three varieties:
parallel port (PPA), IDE, and SCSI. All are supported, but the parallel port
version is slowest; it is also a SCSI drive but with a proprietary parallel port
interface, for which the Linux kernel provides a driver. Hence, both kinds of
drive appear as SCSI disks.
Because they're just standard (but removable) SCSI or IDE
disks, most aspects of their use are similar to those for other block devices.
Red Hat Linux 6.0 comes with support for both the SCSI and PPA varieties. You
can find further information in the Zip-Drive mini HOWTO (which explains how
to install your Zip drive), and the Zip-Install mini HOWTO, which explains how
to install Red Hat Linux onto a Zip drive.





Red Hat® Linux 6 Unleashed










Chapter 15: Filesystems, Disks, and Other Devices





Previous
ChapterNext
Chapter










Sections in this Chapter:












Character
Devices





Mounting
with the User Mount Tool





Repairing
Filesystems






Block
Devices





Setting
Up Filesystems





Various Kinds of Hardware











Creating
New Filesystems





Character
Devices






The mount
Command





Creating
and Editing Filesystems Graphically with fsconf











 

Previous
SectionNext
Section





© Copyright Macmillan USA. All rights reserved.

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • teen-mushing.xlx.pl
  • Wątki
    Powered by wordpress | Theme: simpletex | © Lemur zaprasza