(no commit message)
[ikiwiki.git] / docs / handbook / handbook-disk-organization.mdwn
1
2
3
4 ## Disk Organization 
5
6
7
8 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.
9
10
11
12 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.
13
14
15
16 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`.
17
18
19
20 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.
21
22
23
24 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 `:`.
25
26
27
28 DragonFly does not use drive letters, or other drive names in the path. You would not write `c:/foo/bar/readme.txt` on DragonFly.
29
30
31
32 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.
33
34
35
36 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`).
37
38
39
40 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:
41
42
43
44 install/example-dir1.png
45
46
47
48 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:
49
50
51
52 install/example-dir2.png
53
54
55
56 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.
57
58
59
60 If `B` had been mounted on `A2` then the diagram would look like this:
61
62
63
64 install/example-dir3.png
65
66
67
68 and the paths would be `/A2/B1` and `/A2/B2` respectively.
69
70
71
72 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:
73
74
75
76 install/example-dir4.png
77
78
79
80 Or `C` could be mounted directly on to the `A` file system, under the `A1` directory:
81
82
83
84 install/example-dir5.png
85
86
87
88 If you are familiar with MS-DOS, this is similar, although not identical, to the `join` command.
89
90
91
92
93
94 ### Choosing File System Layout 
95
96
97
98 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.
99
100
101
102 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.
103
104
105
106  **Benefits of Multiple File Systems** 
107
108
109
110
111 * Different file systems can have different ***mount options***.  For example, with careful planning, the root file system can be mounted read-only, making it impossible for you to inadvertently delete or edit a critical file.  Separating user-writable file systems, such as `/home`, from other file systems also allows them to be mounted ***nosuid***; this option prevents the ***suid***/***guid*** bits on executables stored on the file system from taking effect, possibly improving security.
112
113
114 * The UFS file system automatically optimizes the layout of files, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files.  By having one big file system this optimization breaks down.
115
116
117 * DragonFly's file systems are very robust should you lose power.  However, a power loss at a critical point could still damage the structure of the file system.  By splitting your data over multiple file systems it is more likely that the system will still come up, making it easier for you to restore from backup as necessary. This a major reason to make the root file system of limited size, and with low write activity.
118
119
120
121  **Benefit of a Single File System** 
122
123
124
125
126 * File systems are a fixed size. If you create a file system when you install DragonFly and give it a specific size, you may later discover that you need to make the partition bigger.  The [growfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=growfs&section8) command makes it possible to increase the size of a UFS file system on the fly.
127
128
129
130
131
132 ### Disk Slices, Partitions and local UNIX file systems 
133
134 Here we describe how disks are subdivided.
135
136
137
138 #### Slices 
139
140 A disk can be subdivided in slices.
141
142 Slices are named `s0`, `s1` and so on.
143
144 For examples the disk `ad6` can contain the slice `ad6s3`.
145
146 DragonFly support two schemes for slices, MBR and GPT, either of them will manage all slices on a disk:
147
148
149 * MBR: set up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&section8), can be up to 2 TB in size.  MBR slices are numbered from 1; but if disk is ***dangerously dedicated*** it has slice number 0.
150
151
152 * GPT: set up using [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section8), can be extremely large: size up to 8 billion TB.  DragonFly doesn't support booting from a GPT slice in DragonFly  2.0.  GPT slices are numbered from 0. ***Dangerously dedicated*** is not supported nor needed for GPT.  DragonFly 2.1 does have some support for booting from a GPT slice, this is described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section=8).
153
154
155
156 #### Partitions 
157
158 Partitions are contained in slices.
159
160 Partitions are named `a`, `b` and so on.
161
162 DragonFly support 16 partitions per slice, that is `a` through `p`.
163
164 For example the partition `ad6s3a` is contained in the slice `ad6s3`.
165
166 Partitions layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel and disklabel64:
167
168
169 * [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&section8): 32 bit disk label which can use slices with size up to 2 TB.
170
171
172 * [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section8): 64 bit disk label which can use very large slices: size up to 16 million TB. DragonFly doesn't support booting from file systems in these partitions yet.
173
174
175
176 #### Local UNIX file systems 
177
178 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.
179
180
181
182 DragonFly support two local UNIX file systems, UFS and HAMMER:
183
184
185 * UFS: The classical BSD UNIX file system, see [ffs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ffs&section5), it supports size up to 2 TB.
186
187
188 * [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5): A new file system, as of DragonFly 2.0, with many advanced features.  HAMMER file system support size up to 1 million TB.  DragonFly doesn't support booting from a HAMMER file system yet.
189
190
191
192 #### Typical disk layout 
193
194 From the above we see the following typical disk layout scenarios:
195
196
197 * For booting DragonFly from a local file system UFS needs to be used, it will have to reside in a partiton on a [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#disklabel&section8) label, which for DragonFly 2.0 needs to be set up on an MBR slice.
198
199
200 * For moderate storage requirements UFS can be used; it can be setup on any partition, e.g. on the same disk slice as the boot partition.  HAMMER is an alternative, with extra features supported, like history retention.  You should evaluate if HAMMER is suitable, see note below.
201
202
203 * If really big storage capacity is needed UFS can't fit the need.  You should evaluate if HAMMER is suitable, see note below.  For this use HAMMER needs to be used on a GPT slice with  a [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section8) label.  In DragonFly 2.0 it has to be set up on a disk separate from the boot disk.  In  DragonFly 2.1 one disk can be used for both booting and HAMMER file system on GPT slice, as some support for booting from GPT is present, as described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section=8).
204
205
206
207
208
209 #### HAMMER Note 
210
211 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5)
212
213 is a rather new file system, under active development.
214
215 As of DragonFly 2.0 HAMMER is considered to be in an early Beta state.
216
217 You should evaluate if HAMMER is suitable for your needs.
218
219
220
221 Examples of ongoing development includes:
222
223
224 * Making HAMMER more self managing; e.g. ability to setup policy for which history to save for how long: e.g. make snapshot every hour and prune and reblock the file system regularly.  When snapshot gets older than 1 month only keep them for every 6 hours; when older than 3 months only keep snapshot for every 24 hours, when older than 3 years only keep snapshot per month.  For now you need to set up [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section8) jobs for this yourself, see [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&section=8).
225
226
227 * Multi master mirroring. For now only one mirror master is supported, but multiple mirror targets, called slaves, are already supported.
228
229
230 * Support for growing and shrinking existing HAMMER file systems, e.g. by adding and removing volumes from the file system.  The HAMMER design is prepared for this, utilities just have to be written to support it.
231
232
233
234 #### HAMMER Features 
235
236 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5)
237
238 has several advanced features not found in UFS:
239
240
241 * Large file systems:  Up to 1 million TB, also called 1 Exabyte is supported.
242
243
244 * Multiple volumes:  A HAMMER file system can span up to 256 disks, each partition part of a HAMMER file system is called a volume.  Each volume can be up to 4096 TB in size.
245
246
247 * Instant crash recovery:  If a crash should occur, then HAMMER file systems will be ready a few seconds after boot, no lenghty fsck have to be run.
248
249
250 * Full history retension:  All file system changes are saved every ~30 seconds.  Changes are written at least when sync() is called, see [syncer(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syncer&amp;section4).  Every time data for a file is written to disk a transaction is completed, this is assigned an ID and the file updated can after this be accessed with the contents from this moment.  To access the file with the state of this moment, the transaction ID, TID for brevity, just needs to be added to the file name, like: '@@<TID>file'.  The TID can be saved from the 'synctid' [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) command or looked up with the 'hammer history file' command.  This history will typically grow over time, so any disk will fill up over time.  Two things are done so disks doesn't fill up: first: big disks are used, at least 50GB is typical for HAMMER file systems, and second: unused history information is deleted regularly. Here we need to define what unused means: a TID is used if a snapshot have been taken on it. Data assigned to unused history can be reclaimed using the `prune` and `reblock` [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) commands, this will also defragment the file system and can be done while the file system is in normal operation.  Generally after file system is pruned only TIDs for the snapshots or newer than newest shapshot should be used, see explanation [here](http://leaf.dragonflybsd.org/mailarchive/bugs/2008-07/msg00213.html) (more info on HAMMER design [here](http://leaf.dragonflybsd.org/mailarchive/kernel/2008-07/msg00114.html)).  See also [hammer(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=5). 
251
252
253 * Mirroring:  A master file system can be mirrored online to a number of slave file systems.  Mirror targets are read-only, but does have history available.  History retension policy can even be different on slaves and master.  Mirroring can be over network and unreliable connections are handled gracefully.
254
255
256 * Data integrity:  HAMMER has high focus in data integrity and implements a CRC checksum on all data, this means that if disk fails with bit errors it will be detected.
257
258
259
260 More info on HAMMER can be found [here](http://www.dragonflybsd.org/hammer/index.shtml).
261
262
263
264 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.
265
266
267
268
269
270 ### Adding a Disk 
271
272
273
274 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.
275
276
277
278 Assuming that disk `ad6` is installed, we could set it up using
279
280 [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section8) &
281
282 [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8)
283
284 disklabel or
285
286 [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section8) &
287
288 [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8).  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)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8) & [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8).
289
290
291
292     
293
294     # gpt -v create ad6
295
296     ...
297
298     # gpt add -s1 ad6
299
300     ad6s0
301
302     # gpt add ad6
303
304     ad6s1
305
306     # gpt show ad6
307
308     ...
309
310
311
312
313
314 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.
315
316
317
318     
319
320     # disklabel64 -rw ad6s1 auto
321
322     # disklabel64 -e ad6s1          # edit label to add partitions as needed
323
324
325
326
327
328 ### disklabel 
329
330
331
332 For [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8) labels some partitions have certain conventions associated with them.
333
334
335
336 [[!table  data="""
337 |<tablestyle="width:100%"> Partition | Convention 
338 <tablestyle="width:100%"> `a` | Normally contains the root file system 
339  `b` | Normally contains swap space 
340  `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. 
341  `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`. |
342
343 """]]
344
345 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.
346
347
348
349 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.
350
351 ***Dangerously dedicated*** physical drives are accessed as slice 0.
352
353
354
355 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.
356
357
358
359 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](disk-organization.html#BASICS-DEV-CODES).
360
361
362
363 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](disk-organization.html#BASICS-DISK-SLICE-PART).
364
365
366
367 [Example 3-2](disk-organization.html#BASICS-CONCEPT-DISK-MODEL) shows a conceptual model of the disk layout that should help make things clearer.
368
369
370
371 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.
372
373
374
375 ***'Table 3-1. Disk Device Codes***'
376
377
378
379 [[!table  data="""
380 |<tablestyle="width:100%"> Code | Meaning 
381 <tablestyle="width:100%"> `ad` | ATAPI (IDE) disk 
382  `da` | SCSI direct access disk 
383  `acd` | ATAPI (IDE) CDROM 
384  `cd` | SCSI CDROM 
385  `fd` | Floppy disk |
386
387 """]]
388
389 ***'Example 3-1. Sample Disk, Slice, and Partition Names***'
390
391
392
393 [[!table  data="""
394 |<tablestyle="width:100%"> Name | Meaning 
395 <tablestyle="width:100%"> `ad0s1a` | The first partition (`a`) on the first slice (`s1`) on the first IDE disk (`ad0`). 
396  `da1s2e` | The fifth partition (`e`) on the second slice (`s2`) on the second SCSI disk (`da1`). |
397
398 """]]
399
400 ***'Example 3-2. Conceptual Model of a Disk***'
401
402
403
404 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.
405
406
407
408 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.
409
410
411
412 install/disk-layout.png
413
414
415
416
417
418
419
420 CategoryHandbook
421
422 CategoryHandbook-basics
423