DragonFly BSD

handbook-disk-organization

Disk Organization

The smallest unit of organization that DragonFly uses to find files is the filename. Filenames are case-sensitive, which means that readme.txt and README.TXT are two separate files. DragonFly does not use the extension (.txt) of a file to determine whether the file is a program, or a document, or some other form of data.

Files are stored in directories. A directory may contain no files, or it may contain many hundreds of files. A directory can also contain other directories, allowing you to build up a hierarchy of directories within one another. This makes it much easier to organize your data.

Files and directories are referenced by giving the file or directory name, followed by a forward slash, /, followed by any other directory names that are necessary. If you have directory foo, which contains directory bar, which contains the file readme.txt, then the full name, or path to the file is foo/bar/readme.txt.

Directories and files are stored in a file system. Each file system contains exactly one directory at the very top level, called the root directory for that file system. This root directory can then contain other directories.

So far this is probably similar to any other operating system you may have used. There are a few differences; for example, MS-DOS® uses \ to separate file and directory names, while Mac OS® uses :.

DragonFly does not use drive letters, or other drive names in the path. You would not write c:/foo/bar/readme.txt on DragonFly.

Instead, one file system is designated the root file system. The root file system's root directory is referred to as /. Every other file system is then mounted under the root file system. No matter how many disks you have on your DragonFly system, every directory appears to be part of the same disk.

Suppose you have three file systems, called A, B, and C. Each file system has one root directory, which contains two other directories, called A1, A2 (and likewise B1, B2 and C1, C2).

Call A the root file system. If you used the ls command to view the contents of this directory you would see two subdirectories, A1 and A2. The directory tree looks like this:

install/example-dir1.png

A file system must be mounted on to a directory in another file system. So now suppose that you mount file system B on to the directory A1. The root directory of B replaces A1, and the directories in B appear accordingly:

install/example-dir2.png

Any files that are in the B1 or B2 directories can be reached with the path /A1/B1 or /A1/B2 as necessary. Any files that were in /A1 have been temporarily hidden. They will reappear if B is unmounted from A.

If B had been mounted on A2 then the diagram would look like this:

install/example-dir3.png

and the paths would be /A2/B1 and /A2/B2 respectively.

File systems can be mounted on top of one another. Continuing the last example, the C file system could be mounted on top of the B1 directory in the B file system, leading to this arrangement:

install/example-dir4.png

Or C could be mounted directly on to the A file system, under the A1 directory:

install/example-dir5.png

If you are familiar with MS-DOS, this is similar, although not identical, to the join command.

Choosing File System Layout

This is not normally something you need to concern yourself with. Typically you create file systems when installing DragonFly and decide where to mount them, and then never change them unless you add a new disk.

It is entirely possible to have one large root file system, and not need to create any others. There are some drawbacks to this approach, and one advantage.

Benefits of Multiple File Systems

Disk Slices, Partitions and local UNIX file systems

Here we describe how disks are subdivided.

Slices

A disk can be subdivided in slices.

Slices are named s0, s1 and so on.

For examples the disk ad6 can contain the slice ad6s3.

DragonFly support two schemes for slices, MBR and GPT, either of them will manage all slices on a disk:

Partitions

Partitions are contained in slices.

Partitions are named a, b and so on.

DragonFly support 16 partitions per slice, that is a through p.

For example the partition ad6s3a is contained in the slice ad6s3.

Partitions layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel and disklabel64:

Local UNIX file systems

File systems are contained in partitions. Each partition can contain only one file system, which means that file systems often are described by either their typical mount point in the file system hierarchy, or the letter of the partition they are contained in. Partition does not have the same meaning as the common usage of the term partition (for example, MS-DOS partition), because of DragonFly's UNIX® heritage.

DragonFly support two local UNIX file systems, UFS and HAMMER:

Typical disk layout

From the above we see the following typical disk layout scenarios:

HAMMER Note

HAMMER(5)

is a rather new file system, under active development.

As of DragonFly 2.0 HAMMER is considered to be in an early Beta state.

You should evaluate if HAMMER is suitable for your needs.

Examples of ongoing development includes:

HAMMER Features

HAMMER(5)

has several advanced features not found in UFS:

More info on HAMMER can be found here.

DragonFly also uses disk space for swap space. Swap space provides DragonFly with virtual memory. This allows your computer to behave as though it has much more memory than it actually does. When DragonFly runs low on memory it moves some of the data that is not currently being used to the swap space, and moves it back in (moving something else out) when it needs it.

Adding a Disk

Adding a disk is done by installing it physically, and to connect it to a disk controller that DragonFly supports. If you are in doubt if controller is supported, manual pages for disk controllers can be consulted ('man -k disk' or 'man -k scsi' can be of help). The easiest thing is normally to boot DargonFly with the controller installed and note if boot message contains the controller.

Assuming that disk ad6 is installed, we could set it up using

fdisk(8) &

disklabel(8)

disklabel or

gpt(8) &

disklabel64(8). The last option is needed if disk is over 2 TB in size (for 512B block size), but it won't support booting from disk. In this example it is second disk in system so booting from it isn't essential, we choose gpt(8) & disklabel64(8).

# gpt -v create ad6

...

# gpt add -s1 ad6

ad6s0

# gpt add ad6

ad6s1

# gpt show ad6

...

Here we first create the GPT and then add two slices. In this example the first slice added is ad6s0, which is made a dummy slice of size 1 sector, this is just for not having to make further reference to it, as many users remembers that s0 has special meaning, which really isn't true for GPT slices. The second slice is ad6s1 which will cover the rest of the disk.

# disklabel64 -rw ad6s1 auto

# disklabel64 -e ad6s1          # edit label to add partitions as needed

disklabel

For disklabel(8) labels some partitions have certain conventions associated with them.

Partition Convention
a Normally contains the root file system
b Normally contains swap space
c Normally the same size as the enclosing slice. This allows utilities that need to work on the entire slice (for example, a bad block scanner) to work on the c partition. You would not normally create a file system on this partition.
d Partition d used to have a special meaning associated with it, although that is now gone. To this day, some tools may operate oddly if told to work on partition d.

Each partition-that-contains-a-file-system is stored in what DragonFly calls a slice. Slice is DragonFly's term for what the common call partitions, and again, this is because of DragonFly's UNIX background. Slices are numbered, starting at 1, through to 4.

Slice numbers follow the device name, prefixed with an s, starting at 1. So da0s1 is the first slice on the first SCSI drive. There can only be four physical slices on a disk, but you can have logical slices inside physical slices of the appropriate type. These extended slices are numbered starting at 5, so ad0s5 is the first extended slice on the first IDE disk. These devices are used by file systems that expect to occupy a slice.

Dangerously dedicated physical drives are accessed as slice 0.

Slices, dangerously dedicated physical drives, and other drives contain partitions, which are represented as letters from a to p. This letter is appended to the device name, so da0s0a is the a partition on the first da drive, which is dangerously dedicated. ad1s3e is the fifth partition in the third slice of the second IDE disk drive.

Finally, each disk on the system is identified. A disk name starts with a code that indicates the type of disk, and then a number, indicating which disk it is. Disk numbering starts at 0. Common codes that you will see are listed in Table 3-1.

When referring to a partition DragonFly requires that you also name the slice and disk that contains the partition, and when referring to a slice you should also refer to the disk name. Do this by listing the disk name, s, the slice number, and then the partition letter. Examples are shown in Example 3-1.

Example 3-2 shows a conceptual model of the disk layout that should help make things clearer.

In order to install DragonFly you must first configure the disk slices, then create partitions within the slice you will use for DragonFly, and then create a file system (or swap space) in each partition, and decide where that file system will be mounted.

'Table 3-1. Disk Device Codes'

Code Meaning
ad ATAPI (IDE) disk
da SCSI direct access disk
acd ATAPI (IDE) CDROM
cd SCSI CDROM
fd Floppy disk

'Example 3-1. Sample Disk, Slice, and Partition Names'

Name Meaning
ad0s1a The first partition (a) on the first slice (s1) on the first IDE disk (ad0).
da1s2e The fifth partition (e) on the second slice (s2) on the second SCSI disk (da1).

'Example 3-2. Conceptual Model of a Disk'

This diagram shows DragonFly's view of the first IDE disk attached to the system. Assume that the disk is 4 GB in size, and contains two 2 GB slices (MS-DOS partitions). The first slice contains a MS-DOS disk, C:, and the second slice contains a DragonFly installation. This example DragonFly installation has three partitions, and a swap partition.

The three partitions will each hold a file system. Partition a will be used for the root file system, e for the /var directory hierarchy, and f for the /usr directory hierarchy.

install/disk-layout.png

CategoryHandbook

CategoryHandbook-basics