• Aucun résultat trouvé

A DDING A DISK : A STEP - BY - STEP GUIDE

Adding a Disk

7.7 A DDING A DISK : A STEP - BY - STEP GUIDE

Errors that do not fall into one of the five categories above are potentially serious.

They causefsck -p to ask for help and then quit. In this case, run fsck without the -p option. When run in manual mode, fsck asks you to confirm each of the repairs that it wants to make. The following list shows some of the errors thatfsck considers dan-gerous enough to warrant human intervention:

Blocks claimed by more than one file

Blocks claimed outside the range of the filesystem

Link counts that are too small

Blocks that are not accounted for

Directories that refer to unallocated inodes

Various format errors

Unfortunately, it is difficult to patch a disk by hand without extensive knowledge of the implementation of the filesystem. Never attempt to write directly to the filesys-tem through the device files.

In practice, this state of affairs means that you have little choice but to accept the fixes proposed by fsck. You can minimize problems by carefully recording the messages that fsckproduces, since they can sometimes tip you off about the file or files thatare causing problems. Iffsckasks for permission to delete a file, you should try to copy it to a different filesystem before allowingfsckto proceed. Be aware that any time you attempt to access a damaged filesystem, you risk panicking the system.

See Chapter 9 for infor-mation about backups.

If a damaged filesystem (one thatfsckcannot repair automatically) contains valu-able data, do not experiment with it before making an ironclad backup. You can try to dump the disk, but since dump expects to be reading an undamaged filesystem, the resulting image may be missing data (or the command may crash). The best insurance policy is to dd the entire disk to a backup file or backup disk.

If fsck finds a file whose parent directory cannot be determined, it puts the file in the lost+found directory in the top level of the filesystem. Since the name given to a file is recorded only in the file’s parent directory, names for orphan files are not available and the files placed inlost+foundare named with their inode numbers.

The inode table does record the UID of the file’s owner, so getting a file back to its original owner is relatively easy.

7.7 A

DDING A DISK

:

A STEP

-

BY

-

STEP GUIDE

In this section we walk through the configuration of a new disk drive. We set up the drive with several partitions, including one for swap space. On the remaining parti-tions, we create ext3fs filesystems.

After you install a new disk, it’s a good idea to make sure the system can see the new device before you boot up the kernel. If it’s an IDE disk, check to be sure the disk is recognized in the BIOS setup display, which you usually access by typing a magic key sequence before the system boots. Consult the manuals that came with your

com-puter or motherboard for specific information on BIOS configuration for IDE de-vices. In most cases, no special configuration is necessary.

Many SCSI cards also have a BIOS setup screen that you can invoke before the sys-tem boots. If this option is available, you scan the SCSI bus to make sure the new device appears. If this procedure hangs or produces a warning message, it’s possible that you picked a SCSI ID that was already in use or that you did not install termi-nators in the right places.

You can also use the SCSI BIOS to do a low-level format of a disk. This operation takes a long time on some disks and cannot be interrupted, so plan ahead.

See page 878 for more information about installing device drivers.

If your SCSI card does not have its own user interface, you can always just try to boot the system and note the messages displayed by the kernel. If you do not see any messages from a SCSI driver, you may need to install the driver before the disk can be recognized by the kernel.

In our case, we saw the following messages from our BusLogic SCSI host adaptor.

scsi0 : BusLogic BT-948 scsi : 1 host.

Vendor: SEAGATE Model: ST446452W Rev: 0001 Type: Direct-Access ANSI SCSI revision: 02 Detected scsi disk sda at scsi0, channel 0, id 3, lun 0

scsi0: Target 3: Queue Depth 28, Asynchronous

SCSI device sda: hdwr sector=512 bytes. Sectors=91923356 [44884 MB] [44.9 GB]

sda: unknown partition table

We ignore warnings about the partition table since this is the first time the disk has been used. Once the system has finished booting, we can move on to partitioning the disk.

Before partitioning, we must first check to see if device files for the disk already exist (they should). In Linux, the names for SCSI disk device files are of the form /dev/sdXN, where X is a lowercase letter that identifies the drive (a is the lowest-numbered SCSI disk, b is the second lowest, and so on7) and N is the partition ber, starting at 1. When referring to the whole disk, simply omit the partition num-ber. There are no character (raw) disk devices in Linux.

In this example, our disk is the first one on the SCSI chain. The first partition is there-fore/dev/sda1, and the disk as a whole is referred to as /dev/sda. If these device files didn’t exist, we could create them with MAKEDEV or mknod.

The disk is now ready to be partitioned. As in most PC operating systems, the tool used for partitioning under Linux is called fdisk. Though all versions of fdisk do approximately the same thing (they implement Microsoft’s standard partitioning system), there are many variations among them. You would be wise to read the man page for your particular system to be sure it matches what we show here.

7. Note that this letter refers to the order of the target numbers of the SCSI devices, not to the target num-bers themselves. If you add or remove a disk, all the drive letters change!

Adding a Disk

7.7 Adding a disk: a step-by-step guide 135

#fdisk /dev/sda

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 5721.

There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:

1) software that runs at boot time (e.g., LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)

Since we are using this disk only on our Linux system, we can ignore the helpful warning. In the past, it has sometimes been important to make the first partition small to ensure that it will work with an old BIOS and will work with other operating systems that might be installed on the system.

The fdisk program is interactive; pressing m displays a list of all its commands. The ones we use here are:

n, or new, to create a new partition

t, or type, to change the type of a partition

p, or print, to print the partition table

w, or write, to write the partition table to disk

Since our disk does not yet have partitions, we start by creating a new one. If your disk has partitions defined from a former life, you may have to remove them with fdisk’s deletecommand before you can create new ones. The fdisk program does not change anything on disk until you tell it to write the partition table.

The partition table has room for four “primary” partitions that can hold data. Alter-natively, you can create an “extended” partition, which is a primary partition that points to another partition table, giving you another four “logical” partitions. Al-though the use of extended partitions can overcome the normal four-partition re-striction, it is simplest to stick with primary partitions if only a few will be needed, and that’s what we do in this case:

Command (m for help): new Command action

e extended

p primary partition (1-4): p Partition number (1-4): 1

First cylinder (1-5721, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-5721, default 5721): +2G Command (m for help): print

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

Device Boot Start End Blocks Id System

/dev/sda1 1 255 2048256 83 Linux

We create a swap partition similarly, except that we change the type from “Linux” to

“Linux swap.” Although the kernel does not care about the partition type, some pro-grams and scripts try to use the type to figure out what each partition is. We specify a size of 2GB, which is probably overkill for most applications, but since we have disk space to spare, we might as well be generous. mkswap will warn us if it cannot use all of the space we have allocated.

Command (m for help): new e extended

p primary partition (1-4): p Partition number (1-4): 2

First cylinder (256-5721, default 256): 256

Last cylinder or +size or +sizeM or +sizeK (256-1275, default 1275): 511 Command (m for help): type

Partition number (1-4): 2

Hex code (type L to list codes): 82

Changed system type of partition 2 to 82 (Linux swap)

The third partition, which contains the rest of the disk, is defined similarly. We re-view the partition table one last time before writing it.

Command (m for help): print

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

Device Boot Start End Blocks Id System

/dev/sda1 1 255 2048256 83 Linux

/dev/sda2 256 511 2056320 82 Linux swap /dev/sda3 512 5721 41849325 83 Linux

A star appears next to the number of blocks if the partition does not end on a cylin-der boundary. We could either delete the partition and recreate it by entering a num-ber of cylinders (as above) or live with the fact that a small bit of disk space may be unusable. We are happy with the new partition table, so we write the label out to disk:

Command (m for help): write The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

We’re now ready to create filesystems. To create a an ext3fs filesystem, we simply run mke2fs -j and specify the device name as an argument.

#mke2fs -j /dev/sda1 mke2fs 1.36 (05-Feb-2005) Filesystem label=

OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 245280 inodes, 489974 blocks ...

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912

Adding a Disk

7.7 Adding a disk: a step-by-step guide 137

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 34 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

done

In creating your filesystem, you could also use the -J option to explicitly specify ei-ther the size of the journal file that will reside on the new filesystem (-J size=x) or the identity of an external device that will contain the journal file (-J device=y).

Typical installations locate the journal file (which must be between 1,024 and 102,400 filesystem blocks) inside the filesystem itself.

The process for creating the larger filesystem is the same, but it takes significantly longer. If you know that you will not need all of the inodes that mke2fsallocates by default, you can reduce the number of inodes per group, speeding up themke2fsand giving you more space for real data. Likewise, you may wish to increase the number of inodes for filesystems that will house a large number of very small files. It’s much better to have too many inodes than too few, since running out of inodes will pre-vent you from creating any more files. You cannot add more inodes after the filesys-tem has been created. If you run into this situation, you’ll need to dump the data on the filesystem to tape or to a file on another partition, rerunmke2fswith a larger number of inodes (-i), and then restore the data to the partition. Days of fun!

We runfsckon our filesystems to make sure they were created properly. The-fflag forcesfsckto check new filesystems rather than assuming that they are clean.

#fsck -f /dev/sda1 fsck 1.36 (05-Feb-2005) e2fsck 1.36 (05-Feb-2005)

Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/sda1: 11/245280 files (9.1% non-contiguous), 16629/489974 blocks

We can mount new filesystems as soon as their mount points are created:

#mkdir /bkroot

#mount /dev/sda1 /bkroot

#df /bkroot

Filesystem 1k-blocks Used Available Use% Mounted on

/dev/sda1 1981000 13 1878575 0% /bkroot

To ensure that the system mounts the new filesystems at boot time, we add a line for each one to the/etc/fstabfile. Each line lists, as required, the name of the device, the mount point, the filesystem type, the mount options, the backup frequency, and the pass number forfsck.

/dev/sda1 /bkroot ext3 defaults 0 1

/dev/sda3 /new ext3 defaults 0 2

A boot loader must be written to the disk device to make it bootable. Depending on the installation, either the lilo or the grubcommand does the actual installation.

See page 26 for more information about configuring and installing a boot loader.

The final step is to create the swap space and add it to the system. We initialize swap partitions with mkswap, which takes the device name of the partition as an argu-ment. It is no longer necessary to specify the size of the swap partition. With the swap area created, we enable it with the swapon command. swapon also verifies that the swap area was properly added.

#mkswap /dev/sda2

Setting up swapspace version 1, size = 2105667584 bytes

#swapon /dev/sda2

#swapon -s

Filename Type Size Used Priority /dev/hda5 partition 133020 688 -1 /dev/sda2 partition 2056316 0 -2

As with regular filesystems, we must add the new swap partition to the /etc/fstab file so that the system remembers it the next time we reboot. The following entry is appropriate for our example disk:

/dev/sda2 swap swap defaults 0 0

Finally, we reboot to test the changes that were made to the /etc/fstab file and to make sure that the new filesystems and swap space come on-line correctly.