BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


Dividing Your Data
Pages: 1, 2, 3

Let's summarize the BIOS partition table: It is used by a PC's BIOS to determine the physical layout of a hard disk which may have been logically divided into as many as four slices. Normally, users create multiple slices when they wish to run multiple operating systems. If a slice is to contain a Microsoft operating system, it must first be formatted with a file system that the operating system understands. The formatting process will create a table on that slice which will be used by the file system to keep track of where data is stored on that slice.



The nice thing about slicing up a hard drive is that you can reformat a slice (which destroys the table for that slice, meaning you'll no longer be able to find the data on that slice) without affecting the data on the other slices of the disk. However, a slice formatted for a Microsoft operating system can only contain one file system; that is, you can't have two or more file systems on a slice that contains a Microsoft operating system.

If a slice is to contain the FreeBSD operating system, the Unix partition table will be written to that slice. A FreeBSD slice can contain up to eight partitions, and each partition can be either a separate file system or a swap partition.

If you run the disklabel utility without any switches, you will be able to safely view the Unix partition table without modifying it; again, only the superuser can use this utility as only the superuser has permission to access the disk's device name. My PC is running FreeBSD 4.2, so its IDE drive is called ad. Drives are numbered starting with the number 0; since my FreeBSD slice is on my first drive, I'll specify the device ad0 like so:

Also in FreeBSD Basics:

Fun with Xorg

Sharing Internet Connections

Building a Desktop Firewall

Using DesktopBSD

Using PC-BSD

disklabel ad0

# /dev/ad0c:
type: ESDI
disk: ad0s2
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 407
sectors/unit: 6538455
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0 # milliseconds
track-to-track seek: 0 # milliseconds
drivedata: 0

8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 102400 0 4.2BSD 0 0 0 # (Cyl. 0 - 6*)
b: 270976 102400 swap # (Cyl. 6*- 23*)
c: 6538455 0 unused 0 0 # (Cyl. 0 - 406)
e: 40960 373376 4.2BSD 0 0 0 # (Cyl. 23*- 25*)
f: 6124119 414336 4.2BSD 0 0 0 # (Cyl. 25*- 406*)

The Unix partition table looks quite different from the BIOS partition table. All of these entries live in that one FreeBSD slice which the BIOS sees as "partition 2". Notice that this one slice has been assigned five letters, but the letter c shows a filesystem type of unused. By convention, the letter c represents the entire slice, so the actual filesystems will be assigned the letters a-b and d-h. On this FreeBSD slice, there are three separate filesystems lettered a, e, and f. The swap partition has been assigned the letter b.

Each filesystem is defined by its cylinder groups, which are simply a bunch of cylinders grouped together. Each filesystem is only responsible for the data stored on its cylinder group. So, filesystem a has been assigned the cylinders 0-6, the filesystem e has been assigned the cylinders 23-25, and the filesystem f has been assigned the cylinders 25-406. Notice that the entire slice, or c, is composed of cylinders 0-406, for a total of 407 cylinders which was the number of cylinders we saw with FreeBSD's fdisk utility.

We can also see from the beginning of this output how the cylinders are divided into their storage units: cylinders are divided into sectors and tracks, each track is intersected by 63 sectors, and each sector is composed of 512 byte "blocks". If you are unfamiliar with sectors and tracks, there is a good picture here.

Finally, with a bit of math we can figure out how big this slice is in megabytes. There are 6,538,455 sectors and each sector is 512 bytes. If we multiply the number of sectors by the number of bytes, we'll get the total number of bytes. If we divide this result by 1,024, we'll get the number of kilobytes; if we divide that result by another 1,024, we'll get the number of megabytes:

6,538,455 x 512 = 3,347,688,960 bytes
3,347,688,960 / 1,024 = 3,269,227 kilobytes
3,269,227 / 1,024 = 3,192 megabytes

which just happens to be the size reported by the fdisk utility.

The disklabel utility can be used to create the Unix partition table, but it does not actually create the filesystems. Instead, it creates a "disk pack label" which is read by the newfs utility. It is the newfs or new filesystem utility which creates the actual filesystems and their associated inode tables. I want to take a good look at newfs and inode tables, so we'll continue the rest of this article next week.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Discuss this article in the Operating Systems Forum.

Return to the BSD DevCenter.





Sponsored by: