Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1189 / 25 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 11:

Disks

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

Doing it the hard way

Unfortunately, sometimes you may not be able to use the sysinstall method. You may not have access to sysinstall, or you may want to use options that sysinstall doesn't offer. That leaves us with the old way to add disks. The only difference is that this time we need to use different tools. In the following sections, we'll look at what we have to do to install this same 4 GB Seagate drive manually. This time we'll change the partitioning to contain the following partitions:

  • A Microsoft file system.
  • The /newhome file system for our FreeBSD system.
  • Additional swap for the FreeBSD system.

We've called this file system /newhome to use it as an example of moving file systems to new disks.

Creating a partition table

The first step is to create a PC BIOS style partition table on the disk. As in Microsoft, the partitioning program is called fdisk. In the following discussion, you'll find a pocket calculator indispensable.

If the disk is not brand new, it will have existing data of some kind on it. Depending on the nature of that data, fdisk could get sufficiently confused to not work correctly. If you don't format the disk, it's a good idea to overwrite the beginning of the disk with dd:

# dd if=/dev/zero of=/dev/da1 count=100
100+0 records in 100+0 records out
51200 bytes transferred in 1 sees (51200 bytes/sec)

We'll as sign 1 GB for Microsoft and use the remaining approximately 3 GB for FreeBSD. Our resulting partition table should look like:

Partition table on second FreeBSD disk

Рис. 11.3. Partition table on second FreeBSD disk

The Master Boot Record and the Partition Table take up the first sector of the disk, but many of the allocations are track oriented, so the entire first track of the disk is not available for allocation. The rest, up to the end of the last entire cylinder, can be divided between the partitions. It's easy to make a mistake in specifying the parameters, and fdisk performs as good as no checking. You can easily create a partition table that has absolutely no relationship with reality, so it's a good idea to calculate them in advance. For each partition, we need to know three things:

  • The partition type, which fdisk calls sysid. This is a number describing what the partition is used for. FreeBSD partitions have partition type 165, and modern (MS-DOS Release 4 and later) Microsoft partitions have type 6.
  • The start sector, the first sector in the partition.
  • The end sector for the partition.

In addition, we need to decide which partition is the active partition, the partition from which we want to boot. In this case, it doesn't make any difference, because we won't be booting from the disk, but it's always a good idea to set it anyway.

We specify the partitions we don't want by giving them a type, start sector and end sector of 0. Our disk has 8386733 sectors, numbered 0 to 8386732. Partitions should start and end on a cylinder boundary, and we want the Microsoft partition to be about 1 GB. 1GB is 1024 MB, and 1 MB is 2048 sectors of 512 bytes each, so theoretically we want 1024 x 2048, or 2197152 sectors. Because of the requirement that partitions begin and end on a "cylinder" boundary, we need to find the closest number of "cylinders " to this vaflue. First we need to find out how big a "cylinder "is. We can do this by running /fdisk without any options:

# fdisk dal
******* Working on device /dev/dal *******
parameters extracted from in-core disklabel are:
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1 
parameters to be used for BIOS calculations are:
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

fdisk: invalid fdisk partition table found
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1 
Information from DOS bootblock is:
The data for partition 1 is:
<UNUSED>
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
sysid 165,(FreeBSD/NetBSD/386BSD)
   start 47, size 8386539 (4094 Meg), flag 80 (active)
       beg: cyl 0/ head 1/ sector 1;
       end: cyl 413/ head 12/ sector 47

You'll notice that /fdisk has decided that there is a FreeBSD partition in partition 4. That happens even if the disk is brand new. In fact, this is a less desirable feature of /fdisk: it "suggests" this partition, it's not really there, which can be really confusing. This printout does, however, tell us that /fdisk thinks there are 611 sectors per cylinder, sowe divide 2197152 by 611 and get 3423.327 cylinders. We round down to 3423 cylinders, which provestobe2091453 sectors. This is the length we give to the first partition.

We use the remaining space for the FreeBSD partition. How much? Well, dmesg tells us that there are 8386733 sectors, but if you look at the geometry that /fdisk outputs, there are 13726 cylinders with 13 heads (tracks) per cylinder and 47 sectors per track. 13726 x 13 x 47 is 8386586. This rounding down is the explanation for the missing data at the end of the disk that we saw on page 204. The best way to calculate the size of the FreeBSD partition is to take the number of cylinders and multiply by the number of tracks per cylinder. The FreeBSD partition starts behind the Microsoft partition, so it goes from cylinder 3423 to cylinder 13725 inclusive or 10303 cylinders. At 611 sectors per cylinder, we have a total of 6295133 sectors in the partition. Our resulting information is:

Таблица 11.1. sample fdisk parameters
Partition number Partition Start Size
1 6 1 2091453
2 165 2091453 6295133
3 0 0
4 0 0

Next we run fdisk in earnest by specifying the -i option. During this time, you may see messages on the console:

da1: invalid primary partition table: no magic

The message no magic doesn't mean that fdisk is out of purple smoke. It refers to the fact that it didn't find the so-called magic number, which identifies the partition table. We don't have a partition table yet, so this message isn't surprising. It's also completely harmless.

fdisk prompts interactively when you specify the -i flag:

# fdisk -i dal
******* Working on device /dev/da1 *******
parameters extracted from in-core disklabel are:
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

Do you want to change our idea of what BIOS thinks ? [n] Enter pressed Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblack is:
The data for partition 1 is:
sysid 165,(FreeBSD/NetBSD/386BSD)
   start 0, size 8386733 (4095 Meg), flag 80 (active)
       beg: cyl 0/ head 0/ sector 1; 
       end: cyl 522/ head 12/ sector 47
Do you want to change it?  [n] y
Supply a decimal value for "sysid (165=FreeBSD)"  [0] 6
Supply a decimal value for "start"  [0]    Enter pressed Supply a decimal value for "size"  [0] 2091453
Explicitly specify beg/end address ?  [n]    Enter pressed
sysid 6,(Primary 'big' DOS (> 32MB))
   start 0, size 2091453 (1021 Meg), flag 0 
      beg: cyl 0/ head 0/ sector 1;
      end: cyl 350/ head 12/ sector 47
Are we happy with this entry?  [n] y
The data for partition 2 is:
<UNUSED>
Do you want to change it?  [n] y
Supply a decimal value for "sysid (165=FreeBSD)"  [0] 165 Supply a decimal value for "start"  [0] 2091453 
Supply a decimal value for "size"  [0] 6295133 
Explicitly specify beg/end address ?  [n]    Enter pressed
sysid 165,(FreeBSD/NetBSD/386BSD)
start 2091453, size 6295133  (3073 Meg), flag 0
   beg: cyl 351/ head 0/ sector 1;
   end: cyl 413/ head 12/ sector 47
Are we happy with this entry?  [n] y
The data for partition 3 is:
<UNUSED>
Do you want to change it?  [n] Enter pressed
The data for partition 4 is:
sysid 165,(FreeBSD/NetBSD/386BSD)
    start 47, size 8386539 (4094 Meg), flag 80 (active)
      beg: cyl 0/ head 1/ sector 1;
      end: cyl 413/ head 12/ sector 47 
Do you want to change it?  [n] y
The static data for the DOS partition 4 has been reinitialized to:
sysid 165,(FreeBSD/NetBSD/386BSD)
start 47, size 8386539 (4094 Meg), flag 80 (active)
    beg: cyl 0/ head 1/ sector 1;
    end: cyl 413/ head 12/ sector 47
Supply a decimal value for "sysid (165=FreeBSD)"  [165] 0 Supply a decimal value for "start"  [47] 0 
Supply a decimal value for "size"  [8386539] 0 
Explicitly specify beg/end address ?  [n] Enter pressed 
<UNUSED>
Are we happy with this entry?  [n] y 
Do you want to change the active partition?  [n] y 
Supply a decimal value for "active partition"  [1] 2 
Are you happy with this choice [n] y

We haven't changed the partition table yet.   This is your last chance, parameters extracted from in-core disklabel are: 
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are:
cylinders=13726 heads=13 sectors/track=47 (611 blks/cyl)

Information from DOS bootblack is:
1: sysid 6,(Primary 'big' DOS (> 32MB))
    start 0, size 2091453 (1021 Meg), flag 0
      beg: cyl 0/ head 0/ sector 1;
      end: cyl 350/ head 12/ sector 47 
2: sysid 165,(FreeBSD/NetBSD/386BSD)
    start 2091453, size 6295133  (3073 Meg), flag 80 (active)
      beg: cyl 351/ head 0/ sector 1;
      end: cyl 413/ head 12/ sector 47 
3: <UNUSED> 
4: <UNUSED>
Should we write new partition table?  [n] y

You'll notice a couple of things here:

  • Even though we created valid partitions 1 and 2, which cover the entire drive, fdisk gave us the phantom partition 4 which covered the whole disk, and we had to remove it.
  • The cylinder numbers in the summary at the end don't make any sense. We've already calculated that the Microsoft partition goes from cylinder 0 to cylinder 3422 inclusive, and the FreeBSD partition goes from cylinder 3423 to cylinder 13725. But fdisk says that the Microsoft partition goes from cylinder 0 to cylinder 350 inclusive, and the FreeBSD partition goes from cylinder 351 to cylinder 413. What's that all about?

    The problem here is overflow: once upon a time, the maximum cylinder value was 1023, and /fdisk still thinks this is the case. The numbers we're seeing here are the remainder left by dividing the real cylinder numbers by 1024.

< Лекция 10 || Лекция 11: 12345 || Лекция 12 >
Владимир Шишкин
Владимир Шишкин
Россия, Киров
Олег Страхов
Олег Страхов
Россия