Опубликован: 06.08.2012 | Уровень: специалист | Доступ: платный
Лекция 11:

Disks

< Лекция 10 || Лекция 11: 12345 || Лекция 12 >

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 they can read this pattern, they can read anything. Microsoft calls this a low-level format.1 Microsoft also uses the term high-level format for what we call creating a file system. Obviously it destroys any existing data, so

If you have anything you want to keep, back it up before formatting. Most modern disks don't need formatting unless they're damaged. In particular, formatting will not help if you're having configuration problems, if you can't get PPP to work or you're running out of disk space. Well, it will solve the 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 dal

Remember that formatting a disk destroys all data on the disk. Before using the command, make sure 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, in sufficient to write zeros to the entire disk:

# dd if=/dev/zero of=/dev/ad1 bs=128k

If this doesn't work, you may find formatting programs on the manufacturer's web site. You'll probably need to run them under a Microsoft platform.

Using sysinstall

If you can, use sysinstall to partition your disk. Looking at the dmesg output for our new disk, we see:

dal at syml bus 0 target 0 lun 0
dal: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
dal: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled
da1: 4095MB (8386733 512 byte sectors: 255H 63s/t 522C)

You see the standard installation screen (see "Installing FreeBSD" , page 60). Select Index, then Partition, and you see the following screen:

Disk selection menu

Рис. 11.1. Disk selection menu

In this case, we want to partition /dev/dai, so we position the cursor on da1 (as shown) and press Enter. We see 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's the 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, we have 803 sectors left over as a result 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:

Disk partition menu

Рис. 11.2. Disk partition menu
  • We can change the partition type (called "Sub type" in the menu). It's currently 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 new partition, 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, we don't have to waste even this 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 BlOSes expect to find a partition table on the first sector of a disk, and they can't access the disk if they don't find one. If your BIOS has this bug, you'll find this one out pretty quickly when you try to boot. If it doesn't fail on the first boot, it won't fail, though it's barely possible that you might have trouble if you move it to a 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.

The next step is to create a new partition using the entire disk. If we press f, we get the following message:


We don't get 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 gives us a boot manager selection screen:


< Лекция 10 || Лекция 11: 12345 || Лекция 12 >
Бехзод Сайфуллаев
Бехзод Сайфуллаев
Узбекистан, Бухара, Бухарский институт высоких технологий, 2013
Василь Остапенко
Василь Остапенко
Россия