• Nenhum resultado encontrado

Before you go to the trouble of making any dev ice files, you should see whether you're running devfs, an automatic device-file generation system. The easiest way to check for devfs is to run mount and look for devfs in the output.

If your system runs devfs, you should not have to create missing device files because the kernel maintains the directory of available dev ice files. Linux kernels typically configure devfs at boot time, starting a special auxiliary system program called devfsd that gives the administrator the ability to customize the device system.

Note devfs was an experimental feature in older Linux kernels, but is classified as obsolete in the latest Linux kernels.

2.3.4 Partitioning Disk Devices

Before you can use a new disk on your system, you need to know how to partition disks with their device files. If you'v e never worked with partitions before, don't worry. A disk partition is just a piece of the disk dedicated to one purpose, such as a specific directory tree. On PCs, partitions have numbers starting at 1.

To get started, identify the disk device that you want to partition. Most PCs have two ATA interfaces, called primary and secondary interfaces, and each interface can have a master and slave disk, for a total of four disk dev ices. The standard ATA disk assignments are as follows:

/dev/hda Master disk, primary interface

/dev/hdb Slave disk, primary interface

/dev/hdc Master disk, secondary interface

/dev/hdd Slav e disk, secondary interface

There are several partitioning utilities, but the most simple and direct is fdisk. To get started, run fdisk dev (where dev is one of the devices listed abov e), then print the current partition list with p.

Here is sample from fdisk output for a device with three partitions, two containing filesystems and one with swap (see Section 2.5 for more information on swap partitions).

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

Disk /dev/hda: 240 heads, 63 sectors, 2584 cylinders Units = cylinders of 15120 * 512 bytes

Device Boot Start End Blocks Id System /dev/hda1 1 136 1028128+ 83 Linux /dev/hda2 137 204 514080 82 Linux swap /dev/hda3 205 2584 17992800 83 Linux

Partition dimensions are usually in units of cylinders. Each partition has a start and end cylinder,

determining its size, but the amount of space per cylinder varies depending on the disk. The second line in the preceding output shows you the cylinder size, but you don't need to do any weird computations to create partitions.

When creating a new partition, you only need to know the starting cylinder. Cylinders do not overlap in PC partitions, so if you're partitioning a disk, pick the first available cylinder in the fdisk partition list output.

In the preceding example, you would choose 2585 as the starting cylinder.

Each partition also has a system ID, a number that represents an operating system. Linux uses 83 for partitions containing files and 82 for Linux swap.

When you partition a new disk, there is usually one partition on the disk already, containing some sort of variant on the FAT filesystem for Microsoft systems. If you want only a single partition on the disk, just change the system ID to Linux with the t command inside fdisk. Howev er, if you want to customize the partitions, use d to delete any old partitions and n to add new ones.

fdisk is easy to use because each command steps you through the partition number and size. In addition, there is an important safety feature: fdisk does not actually change the partition table until you tell it to with the w command. If you're uneasy about your changes, or you were just testing something, use q to exit without altering the disk.

Here is an example of fdisk in action on a very small disk. Command input is in boldface:

# fdisk /dev/hdc

Command (m for help): p

Disk /dev/hdc: 2 heads, 16 sectors, 247 cylinders Units = cylinders of 32 * 512 bytes

Device Boot Start End Blocks Id System /dev/hdc1 * 1 494 7891+ 1 FAT12 Command (m for help): d

Partition number (1-4): 1 Command (m for help): n Command action

e extended

p primary partition (1-4) p

Partition number (1-4): 1

Last cylinder or +size or +sizeM or +sizeK (1-247, default 247): 120 Command (m for help): t

Partition number (1-4): 1

Hex code (type L to list codes): 83 Command (m for help): p

Disk /dev/hdc: 2 heads, 16 sectors, 247 cylinders Units = cylinders of 32 * 512 bytes

Device Boot Start End Blocks Id System /dev/hdc1 1 120 1912 83 Linux Command (m for help): w

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x

partitions, please see the fdisk manual page for additional information.

Syncing disks.

When you write the partition table to the disk with the w command, fdisk tells the kernel to re-read the partition table from the disk and update the system's in-memory partition list (fdisk does not relay the new partition list directly to the kernel). Therefore, you should nev er write the partition table to a disk that already has a mounted (attached) filesystem; doing so risks damage to the filesystem.

Note The ioctl operation that causes the kernel to re-read the partition table can fail on rare occasions.

If such a failure occurs, you need to reboot the system to get the kernel to see the changes.

After writing the partition table, a new list of partition tables should appear on the console. If you don't see this list, run dmesg to see the kernel messages and look at the end of the output. For the fdisk session earlier in this section, here is what you would see:

hdc: hdc1

The hda indicates the disk that you repartitioned. The new partition list appears after the colon. For example, if you create three partitions on the disk, the output might appear as hdc: hdc1 hdc2 hdc3.

Note Looking at the fdisk session in this section, you may be wondering what the difference between a primary and an extended partition is. The standard PC disk-partitioning scheme originally only allowed a maximum of four partitions, 1–4. These are the primary partitions. If you want more partitions, fdisk can designate one of these primary partitions as an extended partition,

allowing you to place subpartitions in the extended partition. Each of these subpartitions is called a logical partition.

After partitioning a disk, you're not quite ready to attach it to your system because you must put a filesystem on your partition(s) first.

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

2.4 Filesystems

A filesystem is a database of files and directories that you can attach to a Unix system at the root (/) or some other directory (like /usr) in a currently attached filesystem. At one time, filesystems resided on disks and other physical media used exclusively for data storage. However, the tree-like directory structure and I/O interface of filesystems is quite v ersatile, so filesystems now perform a variety of tasks.

2.4.1 Filesystem Types

Linux supports an extraordinarily large number of filesystems, including native designs optimized for Linux, foreign types such as the Windows FAT family, univ ersal filesystems like ISO9660, and others. The following list includes the most common types of filesystems for data storage; the type names as

recognized by Linux are in parentheses next to the boldfaced filesystem names.

The Second Extended filesystem (ext2) is native to Linux. It is fairly quick, and it defragments itself.

Nearly every Linux system uses ext2 or its newer, journaled version, ext3.

Third Extended filesystems (ext3) are ext2 filesystems augmented with journal support. This can make recovery from an abrupt system reboot or failure quicker and less painful.

ISO9660 (iso9660) is a CD-ROM standard. Most CD-ROMs use some variety of ISO9660 extension;

Linux supports them.

FAT filesystems (msdos, vfat, umsdos) pertain to Microsoft systems. The simple msdos type supports the very primitive monocase v ariety in MS-DOS systems. For W indows filesystems, use vfat. The umsdos filesystem is peculiar to Linux; it supports Unix features such as symbolic links on top of an MS-DOS filesystem. It is also not very common.

The Reiser filesystem (reiserfs) is relativ ely new. It supports a journal and is optimized for fairly small files, a condition that often occurs in Unix systems.

2.4.2 Creating a Filesystem

You cannot mount and store files on a partition that does not contain a filesystem. The partitioning process described in Section 2.3.4 does not create any filesystems; you must place the filesystems on the

partitions in a separate step. To create a Second Extended (ext2) filesystem, use the mke2fs program on the target device, as in this example for /dev/hdc3:

mke2fs /dev/hdc3

The mke2fs program automatically determines the number of blocks in a device and sets some

reasonable defaults. Unless you really know what you're doing and feel like reading the mke2fs(8) manual page in detail, you shouldn't change these.

When you create a filesystem, you initialize its database, including the superblock and the inode tables.

The superblock is at the top lev el of the database, and it's so important that mke2fs creates a number of backups in case the original is destroyed. You may wish to record a few of the superblock backup numbers when mke2fs runs, in case you need to recover it later in the ev ent of a disk failure (see Section 2.4.8).

Warning Filesystem creation is a rare task that you should only need to perform after adding a new disk or repartitioning an old disk. You should create a filesystem just once for each new partition that has no preexisting data (or data that you want to remove). Creating a new filesystem on top of an existing filesystem will effectively destroy the old data.

No documento Introduction to Shell ScriptsChapter 8 (páginas 40-43)