Tải bản đầy đủ (.pdf) (21 trang)

Chapter-11-Disks

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (728.98 KB, 21 trang )

2Apr il 2003, 17:00:47 The Complete FreeBSD (disks.mm), page 199
11
Disks
In this chapter:
• Adding a hard disk
• Using sysinstall
• Doing it the hard way
• Creating file systems
• Moving file systems
• Recovering from disk
data errors
In this chapter:
• Adding a hard disk
• Using sysinstall
• Doing it the hard way
• Creating file systems
• Moving file systems
• Recovering from disk
data errors
One of the most important parts of running anycomputer system is handling data on disk.
We hav e already looked at UNIX file handling in Chapter 10. In this chapter,we’ll look
at twoways to add another disk to your system, and what you should put on them. In
addition, we’ll discuss disk error recovery on page 218.
Adding a harddisk
When you installed FreeBSD, you created file systems on at least one hard disk. At a
later point, you may want to install additional drives. There are twoways to do this: with
sysinstall and with the traditional UNIX command-line utilities.
There was a time when it was dangerous to use sysinstall after the system had been
installed: there was a significant chance of shooting yourself in the foot. There’salways a
chance of doing something wrong when initializing disks, but sysinstall has become a lot
better,and nowit’sthe tool of choice. It’sgood to knowthe alternatives, though. In this


section we’ll look at sysinstall,and on page 209 we’ll see howtodoitmanually if
sysinstall won’tcooperate.
We’v e been through all the details of disk layout and slices and partitions in Chapter 2, so
Iwon’trepeat them here. Basically,toadd a newdisk to the system, you need to:
• Install the disk physically.This usually involves power cycling the machine.
• Barely possibly,format the disk. Without exception, modern disks come pre-
formatted, and you only need to format a disk if it has defects or if it’sancient. In
manycases the so-called ‘‘format’’program doesn’treally format at all.
disks.mm,v v4.17 (2003/04/02 06:44:17) 199
Adding a hard disk 200
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 200
• If you want to share with other operating systems, create a PC style partition table on
the disk. We looked at the concepts on page 63.
• Define a FreeBSD slice (which the PC BIOS calls a ‘‘partition’’).
• Define the partitions in the FreeBSD slice.
• Tell the system about the file systems and where to mount them.
• Create the file systems.
These are the same operations that we performed in Chapter 5.
Disk hardware installation
Before you can do anything with the disk, you have toinstall it in the system. To dothis,
you must normally shut down the system and turn the power off, though high-end SCSI
enclosures allow hot-swapping,changing disks in a running system. If the disk is IDE,
and you already have anIDE disk on the controller,you need to set the second disk as
‘‘slave’’ drive. And you may have toset the first disk as ‘‘master’’drive:ifyou only have
one drive,you don’tset anyjumpers, but if you have two drives, some disks require you
to set jumpers on both disks. If you don’tdothis, the system will appear to hang during
the power-on self test, and will finally report some kind of disk error.
Adding a SCSI disk is more complicated. Youcan connect up to 15 SCSI devices to a
host adapter,depending on the interface. Manysystems restrict the number to 7 for
compatibility with older SCSI interfaces. Typically,your first SCSI disk will have the

SCSI ID 0, and the host adapter will have the SCSI ID 7. Traditionally,the IDs 4, 5, and
6are reserved for tape and CD-ROM drives, and the IDs 0 to 3 are reserved for disks,
though FreeBSD doesn’timpose anyrestrictions on what goes where.
Whateverkind of disk you’re adding, look at the boot messages, which you can retrieve
with the dmesg command. For example, if you’re planning to add a SCSI device, you
might see:
sym0: <875> port 0xc400-0xc4ff mem 0xec002000-0xec002fff,0xec003000-0xec0030ff irq 10
at device 9.0 on pci0
sym0: Symbios NVRAM, ID 7, Fast-20, SE, NO parity
sym0: open drain IRQ line driver, using on-chip SRAM
sym0: using LOAD/STORE-based firmware.
sym0: SCAN FOR LUNS disabled for targets 0.
sym1: <875> port 0xc800-0xc8ff mem 0xec001000-0xec001fff,0xec000000-0xec0000ff irq 9
at device 13.0 on pci0
sym1: No NVRAM, ID 7, Fast-20, SE, parity checking
further down...
Waiting 3 seconds for SCSI devices to settle
sa0 at sym0 bus 0 target 3 lun 0
sa0: <EXABYTE EXB-8505SMBANSH2 0793> Removable Sequential Access SCSI-2 device
sa0: 5.000MB/s transfers (5.000MHz, offset 11)
sa1 at sym0 bus 0 target 4 lun 0
sa1: <ARCHIVE Python 28849-XXX 4.CM> Removable Sequential Access SCSI-2 device
sa1: 5.000MB/s transfers (5.000MHz, offset 15)
sa2 at sym0 bus 0 target 5 lun 0
sa2: <TANDBERG TDC 3800 -03:> Removable Sequential Access SCSI-CCS device
sa2: 3.300MB/s transfers
pass4 at sym0 bus 0 target 4 lun 1
pass4: <ARCHIVE Python 28849-XXX 4.CM> Removable Changer SCSI-2 device
disks.mm,v v4.17 (2003/04/02 06:44:17)
201 Chapter 11: Disks

2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 201
pass4: 5.000MB/s transfers (5.000MHz, offset 15)
cd0 at sym0 bus 0 target 6 lun 0
cd0: <NRC MBR-7 110> Removable CD-ROM SCSI-2 device
cd0: 3.300MB/s transfers
cd0: cd present [322265 x 2048 byte records]
da0 at sym1 bus 0 target 3 lun 0
da0: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da0: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da0: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
This output shows twoSymbios SCSI host adapters /dev/(sym0 and /dev/sym1), three
tape drives/dev/(sa0, /dev/sa1 and /dev/sa2), a CD-ROM drive /dev/(cd0), a tape
changer /dev/(pass4), and also a disk drive /dev/da0 on ID 3, which is called a target in
these messages. The disk is connected to the second host adapter,and the other devices
are connected to the first host adapter.
Installing an external SCSI device
External SCSI devices have two cable connectors: one goes towards the host adapter,and
the other towards the next device. The order of the devices in the chain does not have to
have anything to do with the SCSI ID. This method is called daisy chaining.Atthe end
of the chain, the spare connector may be plugged with a terminator,aset of resistors
designed to keep noise offthe bus. Some devices have internal terminators, however.
When installing an external device, you will have todoone of the following:
• If you are installing a first external device (one connected directly to the cable
connector on the backplane of the host adapter), you will have toensure that the
device provides termination. If you already have atleast one internal device, the host
adapter will no longer be at one end of the chain, so you will also have tostop it from
providing termination. Modern SCSI host adapters can decide whether theyneed to
terminate, but older host adapters have resistor packs. In the latter case, remove these
resistor packs.
• If you are adding an additional external device, you have two choices: you can

remove a cable in the middle of the daisy chain and plug it into your newdevice. You
then connect a newcable from your device to the device from which you removedthe
original cable.
Alternatively,you can add the device at the end of the chain. Remove the terminator
or turn offthe termination, and plug your cable into the spare socket. Insert the
terminator in your device (or turn termination on).
Youcan add external SCSI devices to a running system if they’re hot-pluggable. It might
ev enwork if they’re not hot-pluggable, but it’snot strictly the correct thing to do, and
there’sthe risk that you might damage something, possibly irreparably.After connecting
the devices, powering them up and waiting for them to come ready,run camcontrol
rescan.For example, if you added a second disk drive tothe second host adapter in the
example above,you might see:
disks.mm,v v4.17 (2003/04/02 06:44:17)
Adding a hard disk 202
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 202
# camcontrol rescan 1
da1 at sym1 bus 0 target 0 lun 0
da1: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da1: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da1: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
Re-scan of bus 1 was successful
There’saproblem with this approach: note that /dev/da1 has ID 0, and the already
present /dev/da0 has ID 3. If you nowreboot the system, theywill come up with the
device names the other way round. We’lllook at this issue in more detail in the next
section.
Installing an internal SCSI device
Installing an internal SCSI device is much the same as installing an external device.
Instead of daisy chains, you have a flat band cable with a number of connectors. Find one
that suits you, and plug it into the device. Again, you need to think about termination:
• If you are installing the device at the end of the chain, it should have termination

enabled. You should also disable termination for the device that was previously at the
end of the chain. Depending on the device, this may involveremoving the physical
terminators or setting a jumper.
• If you are installing the device in the middle of the chain, makesure it does not have
termination enabled.
In this chapter,we’ll look at twoways of installing a drive inanexisting SCSI chain. We
could be in for a surprise: the device ID we get for the newdrive depends on what is
currently on the chain. Forexample, consider our example above,where we have a chain
with a single drive onit:
da0 at sym1 bus 0 target 3 lun 0
da0: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da0: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da0: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
This drive ontarget (ID) 2. If we put our newdrive ontarget 0 and reboot, we see:
da0 at sym1 bus 0 target 0 lun 0
da0: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da0: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da0: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
da1 at sym1 bus 0 target 3 lun 0
da1: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da1: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da1: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
At first glance, this looks reasonable, but that’sonly because both disks are of the same
type. If you look at the target numbers, you’ll notice that the newdisk is /dev/da0,not
/dev/da1.The target ID of the newdisk is lower than the target ID of the old disk, so the
system recognizes the newdisk as /dev/da0,and our previous /dev/da0 has become
/dev/da1.
disks.mm,v v4.17 (2003/04/02 06:44:17)
203 Chapter 11: Disks
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 203

This change of disk ID can be a problem. One of the first things you do with a newdisk
is to create newdisk labels and file systems. Both offer excellent opportunities to shoot
yourself in the foot if you choose the wrong disk: the result would almost certainly be the
complete loss of data on that disk. Even apart from such catastrophes, you’ll have toedit
/etc/fstab before you can mount anyfile systems that are on the disk. The alternativesare
to wire down the device names, or to change the SCSI IDs. In FreeBSD 5.0, you wire
down device names and busses by adding entries to the boot configuration file
/boot/device.hints.We’ll look at that on page 568.
Formatting the disk
Formatting is the process of rewriting every sector on the disk with a specific data pattern,
one that the electronics find most difficult to reproduce: if theycan read this pattern, they
can read anything. Microsoft calls this a low-level format.
1
Obviously it destroys any
existing data, so
If you haveanything you want to keep, backitupbefore
formatting.
Most modern disks don’tneed formatting unless they’re damaged. In particular,
formatting will not help if you’re having configuration problems, if you can’tget PPP to
work, or you’re running out of disk space. Well, it will solvethe disk space problem, but
not in the manner you probably desire.
If you do need to format a SCSI disk, use camcontrol. camcontrol is a control program
for SCSI devices, and it includes a lot of useful functions that you can read about in the
man page. To format a disk, use the following syntax:
# camcontrol format da1
Remember that formatting a disk destroys all data on the disk.
Before using the command, makesure that you need to do so:
there are relatively few cases that call for formatting a disk.
About the only reasons are if you want to change the physical
sector size of the disk, or if you are getting ‘‘medium format

corrupted’’errors from the disk in response to read and write
requests.
FreeBSD can format only floppies and SCSI disks. In general it is no longer possible to
reformat ATA (IDE) disks, though some manufacturers have programs that can recover
from some data problems. In most cases, though, it’ssufficient to write zeros to the entire
disk:
# dd if=/dev/zero of=/dev/ad1s2 bs=128k
If this doesn’twork, you may find formatting programs on the manufacturer’sweb site.
You’ll probably need to run them under a Microsoft platform.
1. Microsoft also uses the term high-level format for what we call creating a file system.
disks.mm,v v4.17 (2003/04/02 06:44:17)
Adding a hard disk 204
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 204
Using sysinstall
If you can, use sysinstall to partition your disk. Looking at the dmesg output for our
newdisk, we see:
da1 at sym1 bus 0 target 0 lun 0
da1: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da1: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da1: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
Yousee the standard installation screen (see Chapter 5, page 60). Select Index,then
Partition,and you see the following screen:
Figure11-1: Disk selection menu
In this case, we want to partition /dev/da1,soweposition the cursor on da1 (as shown)
and press Enter.Wesee the disk partition menu, which shows that the disk currently
contains three partitions:
• The first starts at offset 0, and has a length of 63. This is not unused, no matter what
the description says. It’sthe partition table, padded to the length of a ‘‘track.’’
• The next partition takes up the bulk of the drive and is a Microsoft partition.
• Finally,wehav e 803 sectors left overasaresult of the partitioning scheme.

Sometimes this can be much larger—I have seen values as high as 35 MB. This is
the price we pay for compatibility with PC BIOS partitioning.
We want a FreeBSD partition, not a Microsoft partition. At this point, we have a number
of choices:
disks.mm,v v4.17 (2003/04/02 06:44:17)
205 Chapter 11: Disks
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 205
Figure11-2: Disk partition menu
• We can change the partition type (called ‘‘Subtype’’inthe menu). It’scurrently 6,
and we would need to change it to 165. Do this with the t command.
• We could delete the partition by positioning the cursor on the partition information
and pressing d,then create a newpartition, either with a if we want a single partition,
or with c if we want more than one partition.
• If we’re using this disk for FreeBSD only,wedon’thav e to waste eventhis much
space. There is an option ‘‘use whole disk for FreeBSD,’’ the so-called ‘‘dangerously
dedicated’’mode. This term comes partially from superstition and partially because
some BIOSes expect to find a partition table on the first sector of a disk, and they
can’taccess the disk if theydon’tfind one. If your BIOS has this bug, you’ll find this
one out pretty quickly when you try to boot. If it doesn’tfail on the first boot, it
won’tfail, though it’sbarely possible that you might have trouble if you move ittoa
system with a different BIOS. If you want to use this method, use the undocumented
f command.
To use the whole disk, we first delete the current partition: we press the cursor down key
until it highlights the FreeBSD partition. Then we press d,and the three partitions are
joined into one, marked unused.
disks.mm,v v4.17 (2003/04/02 06:44:17)
Using sysinstall 206
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 206
The next step is to create a newpartition using the entire disk. If we press f,weget the
following message:

We don’tget this message if we use the a command: it just automatically assumes Yes.
In this case we’ve decided to use the whole disk, so we move the cursor right to No and
press Enter.That givesusaboot manager selection screen:
disks.mm,v v4.17 (2003/04/02 06:44:17)

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×