Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

device

da0

at

scbus0

target

2

unit

0

device

da0

at

scbus0

target

8

unit

0

...............................................................................................

Similarly, you can wire a particular SCSI bus to a particular card, and even to a particular slot on a card. For example, we know that SCSI bus 0 is on ahc0. While this system only has one SCSI card, we don't want a new SCSI card to subvert SCSI bus 0. We can wire this SCSI bus to this particular slot on this card with the following kernel configuration:

...............................................................................................

device scbus0 at ahc0 bus 0

...............................................................................................

Once you've entered these settings, rebuild your kernel with the proper information, and reboot. You'll see these devices coming up in this configuration, which isn't at all exciting, of course, because that's where you started.

To prove that you've wired your devices to something in the kernel, play with this configuration a little. You might, say, go into your kernel configuration and change all the instances of da0 to da7. After a recompile and a reboot, you'll see a /dev/da1 and a /dev/da7 in your boot messages. (This little test might make it difficult for your system to boot. Don't capriciously change the names of the disk your root and /usr filesystems live on!)

Adding New Hard Disks

Handling new disks can be something of a pain because you have to format them, give them a filesystem, mount them somewhere, and move your data. You have a couple of different options here to make the first few steps easier. You can use sysinstall(8), which is simple and fast and makes life simpler, or you can do it the ugly command−line way. Being always in a hurry, you'll almost certainly want to use sysinstall.

Sysinstall occasionally has problems with some older disks (usually about 300MB or less). If you're using older disks, you might have no choice but to use the command−line method. In that case, check the FreeBSD Handbook for assistance.

We'll assume that you are adding disks to an existing system, and that your eventual goal is to move some of your current data to this disk. We'll cover two examples: creating a new /usr/obj on this disk and moving /home to a new disk.

Note Before doing anything with disks, be sure that you have a complete backup. A single dumb fat−finger mistake in this process can destroy your system! You do not want to accidentally reformat your root filesystem, for example.

Creating Slices

Your first step in working with a new hard disk will be to partition it. Follow these steps:

386

1.Become root, and start sysinstall. We'll want to do post−install configuration, so choose Configure and start with Fdisk.

2.This menu should look somewhat familiar; you used it when you installed FreeBSD. (You can see screenshots in Figure 1.4 in Chapter 1.) You'll see your existing FreeBSD disk and your new disk. Choose the new disk.

3.If this disk is recycled from another server, you might find that it has a filesystem on it. Decide whether you want to keep what's on the disk, or erase it and start over. It's usually simplest to just remove the existing partitions and filesystems. Use the arrow keys to move to the existing partition, and press d to delete it.

4.You can either create a new slice by pressing c, or just use the whole disk by pressing a. In a server, you almost certainly want to use the entire disk. When you've chosen your slices, make the changes effective immediately by pressing w. You'll see a warning like this:

Warning This should only be used when modifying an EXISTING installation. If you are installing FreeBSD for the first time then you should simply type Q when you're finished here and your changes will be committed in one batch automatically at the end of these questions. If you're adding a disk, you should NOT write from this screen, you should do it from the label editor.

Are you absolutely sure you want to do this now?

5.Yes, you're absolutely sure. Tab over to "Yes" and hit enter.

6.You'll then be asked if you want to install a boot manager on this disk. You don't need a boot manager on an additional disk, so arrow down to Standard and press the spacebar. Then arrow down to OK and press ENTER. The sysinstall program should tell you that it has written out the FDISK information. We now have a FreeBSD slice on the disk. Leave the fdisk part of sysinstall, and head on to create partitions in the slice.

Creating Partitions

To create partitions on your disk, follow these steps:

1.Choose the Label option of sysinstall. Here you can create a new partition with the c command, specifying its size in either megabytes, gigabytes, disk blocks, or disk cylinders. (You'll probably want megabytes or gigabytes.) You can also decide if each new partition will be a filesystem or a swap space.

Note When creating partitions, be sure that your new disk name is at the top of the screen. You don't want to relabel your current disk!

2.Enable soft updates, if they aren't enabled by default.

3.When you're satisfied with the way partitions on your new disk are labeled, press w again to write the label changes to the disk. You now have a partition table. (Take note of the partition names (such as da7s1e); you'll need them later.)

4.Finally, press w to commit the changes. You should see a text box about newfs pop up. (This may take several minutes–formatting a 100GB hard drive is no simple task!)

5.When this finishes, exit sysinstall.

387

Configuring /etc/fstab

If you've added swap space, you should configure /etc/fstab to recognize it. (You did write down the partition names for your new partitions, right?) Your swap space is probably something like da7s1b (substituting your disk's name for da7). There's already an entry for your existing swap space in /etc/fstab, which you can use as a model when adding this new space.

For example, suppose a test server has a swap line that looks like this:

...............................................................................................

/dev/da0s1b none swap sw 0 0

...............................................................................................

If your new disk is /dev/da7, and you've created a swap partition on /dev/da7s1b, add a line like this:

...............................................................................................

/dev/da7s1b none swap sw 0 0

...............................................................................................

At your next boot, FreeBSD will find this entry and turn it into a swap space.

You should also add a similar entry for your new data partition(s). Here is an /etc/fstab entry to mount a new /dev/da7s1e partition on /crud, a new mount point created just for this drive:

...............................................................................................

/dev/da7s1e /crud ufs rw 0 0

...............................................................................................

Installing Existing Files onto New Disks

Chances are that you will want your new disk to replace an existing FreeBSD partition or to subdivide an existing partition. To do so, make your new partition available on the system on a temporary mount point. Move files from the old location to the new location. Then remount the partition at the desired location.

Temporary Mounts

Suppose you have a new partition /dev/da7s1e that you want to use for /usr/src, and you want to move the files from the existing /usr/src to the new partition. To talk to the new partition, however, you need to mount it at some different location temporarily.

The temporary location can be any directory on your system. The /mnt directory is traditionally used as a temporary mount point for partitions.

...............................................................................................

# mount /dev/da7s1e /mnt

#

...............................................................................................

388

Moving Files

Now you need to move files from their current location to the new partition without changing their permissions or otherwise affecting them. This is fairly simple to do with tar(1). (We use tar to preserve our filesystem permissions.)

You can simply tar up your existing data to a tape or a file, and untar it in the new location, but that's kind of clumsy. You can concatenate tar commands to avoid that middle step, however:

...............................................................................................

(cd /old/directory && tar cf .) | (cd /newplace && tar xpf −)

...............................................................................................

If you don't speak UNIX at parties, this line looks fairly stunning. Let's dismantle it. First, you're going to the old directory and tarring up everything you find there with (cd /old/directory && tar cf .). Next, the output is piped to the new directory, where it is untarred with | (cd /newplace && tar xpf −). Wait a few minutes, and you'll be all set.

For example, to move /usr/src onto a new partition temporarily mounted on /mnt, you would do this:

...............................................................................................

# ( cd /usr/src && tar cf . ) | ( cd /mnt && tar xpf −)

...............................................................................................

This isn't simple, but it's not incomprehensible. Of course, if it makes you feel more comfortable, you can create a tarball in one location and uncompress it elsewhere. All you need is the disk space to do so.

Note This does not delete the files from the original location. Unless you're sure that they're copied correctly, use rm −rf to remove them.

Moving Live Files

You cannot safely move files that are being changed. For example, if you're moving your mail spool to a new partition, shut down your mail services. Otherwise, the files will change as you're trying to copy them.

Stackable Mounts

Suppose you don't care about your old data; you simply want to split an existing disk to get more space, and you plan to recover your data from backup. Fair enough.

All BSD filesystems are stackable. This is an advanced idea, and not very useful in day−to−day administration. However, it can bite you when you try to split up one partition between two disks.

Suppose, for example, that you have data in /usr/src. (If you followed the installation advice, or you've upgraded your system, you should.) Do an ls, and confirm that the data is still there. Now mount your new partition over /usr/src:

389

...............................................................................................

# mount /dev/da7s1e /usr/src

#

...............................................................................................

If you look in /usr/src now, you'll see that the directory is empty.

But here's the problem: The new partition is mounted "above" the old disk, and the old disk still has all that data on it. If you unmount the new partition and check that directory again, you'll see your data miraculously restored! The new partition obscured the lower partition.

Although you can't see it, the data on the old disk still takes up space. (You can view how much disk space you're using with df(1) and du(1).) If you're splitting a disk to gain space, and you just mount a new disk over part of the old, you won't gain any disk space on the original disk.

The moral is: Even if you are restoring your data from backup, make sure you remove that data from your original disk to recover the disk space.

390