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

Disks

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

Labeling the disk

Once we have a valid PC BIOS partition table, we need to create the file systems. We won't look at the Microsoft partition in anymore detail, but we still need to do some more work on our FreeBSD slice (slice or PC BIOS partition 2). It'll make life easier here to remember a couple of things:

  • From now on, we're just looking at the slice, which we can think of as a logical disk. Names like disk label really refer to the slice, but many standard terms use the word disk, so we'll continue to use them.
  • All offsets are relative to the beginning of the slice, not the beginning of the disk. Sizes also refer to the slice and not the disk.

The first thing we need is the disk (slice) label, which supplies general information about the slice:

  • The fact that it's a FreeBSD slice.
  • The size of the slice.
  • The sizes, types and layout of the file systems.
  • Some obsolete information about details like rotational speed of the disk and the track-to-track switching time. This is still here for historical reasons only. It may go away soon.

The only information we need to input is the kind, size and locations of the partitions. In this case, we have decided to create a file system on partition h (/dev/da1s2h) and swap space on partition b (/dev/dalslb). The swap space will be 512 MB, and the file system will take up the rest of the slice. This is mainly tradition: traditionally data disks use the h partition and not the a partition, so we'll stick to that tradition, though there's nothing to stop you from using the a partition if you prefer. In addition, we need to define the c partition, which represents the whole slice. In summary, the FreeBSD slice we want to create looks like:

Таблица 11.2. TABLE FreeBSD slice on second disk
/dev/da1s2b: FreeBSD swap, 512 MB
/dev/da1s2h: /newhome file system, 2.5 GB

bsdlabel

The program that writes the disk label used to be called disklabel As FreeBSD migrated to multiple platforms, this proved to be too generic: many hardware platforms have their own disk label formats. For example, FreeBSD on SPARC64 uses the Sun standard labels. On platforms which use the old BSD labels, such as the PC, the name was changed to bsdlabel. On SPARC64 it is called sunlabel. On each platform, the appropriate file is linked to the name disklabel, but some of the options have changed. In addition, the output format now normally ignores a number of historical relics. It's not as warty as fdisk, but it can still give you a run for your money. You can usually ignore most of the complexity, though. You can normally create a disk label with the single command:

# bsdlabel -w /dev/da1s2 auto

This creates the label with a single partition c. You can look at the label with bsdlabel without options:

#bsdlabel /dev/da1s2
#/dev/da0s2:
8partitions:
#       size  offset  fstype  [fsize bsize bps/cpg]
 c:  6295133       0  unused     0     0          # "raw" part, don't edit

At this point, the only partition you have is the "whole disk" partition c. You still need to create partitions b and h and specify their location and size. Do this with bsdlabel -e, which starts an editor with the output you see above. Simply add additional partitions:

8partitions:
#       size   offset  fstype   [fsize bsize bps/cpg]
 c:  6295133        0  unused      0     0  # "raw" part, don't edit
 b:  1048576        0  swap        0     0
 h:  5246557  1048576  unused      0     0

You don't need to maintain any particular order, and you don't need to specify that partition h will be a file system. In the next step , newfs does that for you automatically.

Problems running biddable

Using the old disklabel program used to be like walking through a minefield. Things have got a lot better, but it's possible that some problems are still hiding. Here are some of the problems that have been encountered in the past, along with some suggestions about what to do if you experience them:

  • When writing a label (the –w option), you may find:
    # bsdlabel -w da1s2
    bsdlabel: /dev/da1s2c: Undefined error: 0
    

    This message may be the result of the kernel having out-of-date information about the slice in memory. If this is the case, a reboot may help.

  • No disk label on disk is straightforward enough. You tried to use bsdlabel to look at the label before you had a label to look at.
  • Label magic number or checksum is wrong! tells you that bsdlabel thinks it has a label, but it's invalid. This could be the result of an incorrect previous attempt to label the disk. It can be difficult to get rid of an incorrect label. The best thing to do is to repartition the disk with the label in a different position, and then copy /dev/zero to where the label used to be:
    # dd if=/dev/zero of=/dev/da1 bs=128k count=
    

    Then you can repartition again the way you want to have it.

  • Open partition would move or shrink probably means that you have specified incorrect values in your slice definitions. Check particularly that the c partition corresponds with the definition in the partition table.
  • write: Read-only file system means that you are trying to do something invalid with a valid disk label. FreeBSD write protects the disk label, which is why you get this message.
  • In addition, you might get kernel messages like:
    fixlabel: raw partition size > slice size
    or
    fixlabel: raw partitions offset != slice offset
    

    The meanings of these messages should be obvious.

Creating file systems

Once we have a valid label, we need to create the file systems. In this case, there's only one file system, on /dev/da1s2/z. Mercifully, this is easier:

# newfs -U /dev/da1s2h
/dev/vinum/da1s2h: 2561.8MB (5246556 sectors) block size 16384, fragment size 2048 
    using 14 cylinder groups of 183.77MB, 11761 blks, 23552 inodes.
    with soft updates
super-block backups (for fsck -b #)at:
160, 376512, 752864, 1129216, 1505568, 1881920, 2258272, 2634624, 3010976, 3387328,
3763680, 4140032, 4516384, 4892736

The -U flag tells newfs to enable soft updates, which we looked at on page 191.

Mounting the file systems

Finally the job is done. Well, almost. You still need to mount the file system, and to tell the system that it has more swap. But that's not much of a problem:

# mkdir /newhome             make sure we have a directory to mount on
# mount /dev/da1s2h/newhome  and mount it
# swapon /dev/da1s2b
# df                         show free capacity and mounted file systems
Filesystem    1024-blocks     Used    Avail  Capacity  Mounted on
/dev/ad0s1a         19966    17426      944     95%    /
/dev/ad0s1e       1162062   955758   113340     89%    /usr
procfs                  4        4        0    100%    /proc
presto:/            15823     6734     8297     45%    /presto/root
presto:/usr        912271   824927    41730     95%    /presto/usr
presto:/home      1905583  1193721   521303     70%    /presto/home
presto:/S         4065286  3339635   563039     86%    /S
/dev/da1s2h       2540316        2  2337090      0%    /newhome
# pstat -s                   show  swap usage
Device          1K-blocks     Used    Avail  Capacity  Type
/dev/ad0s4b        524160        0   524160      0%    Interleaved
/dev/da1s2b        524160        0   524160      0%    Interleaved
Total             1048320        0  1048320      0%

This looks fine, but when you reboot the system, /newhome and the additional swap will be gone. To ensure that they get mounted after booting, you need to add the following lines to /etc/fstab:

/dev/da1s2b  none      swap  sw  0  0
/dev/da1s2h  /newhome  ufs   rw  0  0

Moving file systems

Very frequently, you add a new disk to a system because existing disks have run out of space. Let's consider the disk we have just added and assume that currently the files in /home are physically located on the /usr file system, and that /home is a symbolic link to /usr/home. We want to move them to the new file system and then rename it to /home. Here's what to do:

  • Copy the files:
    #cd /home
    #tar cf - .  |   (cd /newhome; tar xvf – 2>/var/tmp/tarerrors)
    

    This writes any error messages to the file /var/tmp/tarerrors. if you don't do this, any errors will get lost.

  • Check/var/tmp/tarerrors and make sure that the files really made it to the right place!
  • Remove the old files:
    #  rm -rf /usr/home
    
  • In this case, /home was a symbolic link, so we need to remove it and create a directory called /home:
    #rm /home
    #mkdir /home
    

    You don't need to do this if /home was already a directory (for example, if you're moving a complete file system).

  • Modify /etc/fstab to contain a line like:
    /dev/da1s2h  /home  ufs  rw  0  0
    
  • Un mount the /newhome directory and mount it as /home:
    #umount /newhome
    #mount /home
    

Recovering from disk data errors

Modern hard disks are a miracle in evolution. Today you can buy a 200 GB hard disk for under $200, and it will fit in your shirt pocket. Thirty years ago, a typical disk drive was the size of a washing machine and stored 20 MB. You would need 10,000 of them to store 200 GB.

At the same time, reliability has gone up, but disks are still relatively unreliable devices. You can achieve maximum reliability by keeping them cool, but sooner or later you are going to run into some kind of problem. One kind is due to surface irregularities: the disk can't read a specific part of the surface.

Modern disks make provisions for recovering from such errors by allocating an alternate sector for the data. IDE drives do this automatically, but with SCSI drives you have the option of enabling or disabling reallocation. Usually reallocation is enabled when you buy the disk, but occasionally it is not. When installing a new disk, you should check that the parameters ARRE (Auto Read Reallocation Enable) and AWRE (Auto Write Reallocation Enable) are turned on. For example, to check and set the values for disk /dev/da1 , you would enter:

#  camcontrol modepage dal -m 1 -e

This command will start up your favorite editor (either the one specified in the EDITOR environment variable, or vi by default) with the following data:

AWRE (Auto Write Reallocation Enbld): 0
ARRE (Auto Read Reallocation Enbld): 0
TB (Transfer Block): 1
EER (Enable Early Recovery): 0
PER (Post Error): 1
DTE (Disable Transfer on Error): 0
DCR (Disable Correction): 0
Read Retry Count: 41
Write Retry Count: 24

The values for AWRE and ARRE should both be 1. If they aren't, as in this case, where AWRE is 0, change the data with the editor, write it back, and exit. camcontrol writes the data back to the disk and enables the option.

Note the last two lines in this example. They give the number of actual retries that this drive has performed. You can reset these values too if you want; they will be updated if the drive performs any additional retries.

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