doc/en_US.ISO8859-1/articles/formatting-media/article.sgml
Tom Rhodes d4b003e30a FreeBSD documentation project prefers to use manual pages over man pages,
hence some documents should reflect this.

Tossed around on: -doc -developers
2002-07-11 19:08:31 +00:00

621 lines
20 KiB
Text

<!DOCTYPE article PUBLIC "-//FreeBSD//DTD DocBook V4.1-Based Extension//EN" [
<!ENTITY % authors PUBLIC "-//FreeBSD//ENTITIES DocBook Author Entities//EN">
%authors;
<!ENTITY % man PUBLIC "-//FreeBSD//ENTITIES DocBook Manual Page Entities//EN">
%man;
]>
<!-- $FreeBSD$ -->
<article>
<articleinfo>
<title>Formatting Media For Use With FreeBSD</title>
<subtitle>A Tutorial</subtitle>
<authorgroup>
<author>
<firstname>Doug</firstname>
<surname>White</surname>
<affiliation>
<address>
<email>dwhite@resnet.uoregon.edu</email>
</address>
</affiliation>
</author>
</authorgroup>
<pubdate>March 1997</pubdate>
<abstract>
<para>This document describes how to slice, partition, and
format hard disk drives and similar media for use with
FreeBSD. The examples given have been tested under FreeBSD
2.2 and should work for other releases. The text has been updated
for FreeBSD version 4.</para>
</abstract>
</articleinfo>
<sect1>
<title>Introduction & Definitions</title>
<sect2>
<title>Overview</title>
<para>Successfully adding disks to an existing system is the
mark of an experienced system administrator. Slicing,
partitioning, and adding disks requires a careful dance of
proper command and name syntax. One slipped finger and an
entire disk could disappear in seconds. This document is
written in an attempt to simplify this process and avoid
accidents. Thankfully, enhancements to existing tools
(notably sysinstall) have greatly improved this process in
recent releases of FreeBSD.</para>
<para>There are two possible modes of disk formatting:</para>
<itemizedlist>
<listitem>
<para><firstterm>compatibility mode</firstterm>: Arranging a
disk so that it has a slice table for use with other
operating systems.</para>
</listitem>
<listitem>
<para><firstterm>dedicated mode</firstterm>, sometimes called
<firstterm>dangerously dedicated mode</firstterm>: Formatting a disk
with no slice table. This makes the process of adding disks easier,
however non-FreeBSD operating systems may not accept the disk. The
term <emphasis>dangerously</emphasis> refers to the danger that the
system may not recognize a disk formatted in this manner.</para>
</listitem> </itemizedlist>
<para>For most cases, dedicated mode is the easiest to set up
and use in existing systems, as a new disk is usually
dedicated entirely to FreeBSD. However, compatibility mode
insures optimum interoperability with future installations at
a cost of increased complexity.</para>
<para>In addition to selecting the mode, two methods of slicing
the disk are available. One is using the system installation
tool <command>/stand/sysinstall</command>. 2.1.7-RELEASE and
later versions of <command>sysinstall</command> contain code
to ease setup of disks during normal system operation, mainly
allowing access to the Label and Partition editors and a Write
feature which will update just the selected disk and slice
without affecting other disks. The other method is running
the tools manually from a root command line. For
dedicated mode, only three or four commands are involved while
<command>sysinstall</command> requires some
manipulation.</para>
</sect2>
<sect2>
<title>Definitions</title>
<para>Unix disk management over the centuries has invented many
new definitions for old words. The following glossary covers
the definitions used in this document and (hopefully) for
FreeBSD in general.</para>
<!-- I'm tempted to use GLOSSARY here but will resort to a list for
now. -->
<itemizedlist>
<listitem>
<para>compatibility mode: Arranging a disk so that it has a
slice table for use with other operating systems. Oppose
dedicated mode.</para>
</listitem>
<listitem>
<para>(dangerously) dedicated mode: Formatting a disk with no
slice table. This makes the process of adding disks
easier, however non-FreeBSD operating systems may not
accept the disk. Oppose compatibility mode.</para>
</listitem>
<listitem>
<para>disk: A circular disc, covered with magnetic or
similarly manipulable material, spun by a motor under a
head. Data is stored on the disk by changing the pattern
of magnetism on the disc, which can be later read. Hard
disks, CDROMs, Magneto-optical,and Zip/Jaz removables are
examples of disks.</para>
</listitem>
<listitem>
<para>slice: A division of a disk. Up to four slices are
permitted on one disk in the PC standard. Slices are
composed of contiguous sectors. Slices are recorded in a
<quote>slice table</quote> used by the system BIOS to
locate bootable partitions. The slice table is usually
called the <quote>partition table</quote> in DOS parlance. Maintained by
the fdisk utility.</para>
</listitem>
<listitem>
<para>partition: A division of a slice. Usually used in
reference to divisions of the FreeBSD slice of a disk.
Each filesystem and swap area on a disk resides in a
partition. Maintained using the disklabel utility.</para>
</listitem>
<listitem>
<para>sector: Smallest subdivision of a disk. One sector
usually represents 512 bytes of data.</para>
</listitem>
</itemizedlist>
</sect2>
<sect2>
<title>Warnings & Pitfalls</title>
<para>Building disks is not something to take lightly. It is
quite possible to destroy the contents of other disks in your
system if the proper precautions are not taken.</para>
<para><emphasis>Check your work carefully.</emphasis> It is very simple
to destroy the incorrect disk when working with these
commands. When in doubt consult the kernel boot output for
the proper device.</para>
<para>Needless to say, we are not responsible for any damage to
any data or hardware that you may experience. You work at
your own risk!</para>
</sect2>
<sect2>
<title>Zip, Jaz, and Other Removables</title>
<para>Removable disks can be formatted in the same way as normal
hard disks. It is essential to have the disk drive connected
to the system and a disk placed in the drive during startup,
so the kernel can determine the drive's geometry. Check the
<command>dmesg</command> output and make sure your device and
the disk's size is listed. If the kernel reports
<informalexample>
<screen>Can't get the size</screen>
</informalexample>
then the disk was not in the drive. In this case, you will
need to restart the machine before attempting to format
disks.</para>
</sect2>
</sect1>
<sect1>
<title>Formatting Disks in Dedicated Mode</title>
<sect2>
<title>Introduction</title>
<para>This section details how to make disks that are totally
dedicated to FreeBSD. Remember, dedicated mode disks sometimes
cannot be booted by the PC architecture.</para>
</sect2>
<sect2>
<title>Making Dedicated Mode Disks using Sysinstall</title>
<para><command>/stand/sysinstall</command>, the system
installation utility, has been expanded in recent versions to
make the process of dividing disks properly a less tiring
affair. The fdisk and disklabel editors built into sysinstall
are GUI tools that remove much of the confusion from slicing
disks. For FreeBSD versions 2.1.7 and later, this is perhaps
the simplest way to slice disks.</para>
<procedure>
<step>
<para>Start sysinstall as root by typing
<informalexample>
<screen>&prompt.root; <userinput>/stand/sysinstall</userinput></screen>
</informalexample>
from the command prompt.</para>
</step>
<step>
<para>Select <command>Index</command>.</para>
</step>
<step>
<para>Select <command>Partition</command>.</para>
</step>
<step>
<para>Select the disk to edit with arrow keys and
<keycap>SPACE</keycap>.</para>
</step>
<step>
<para>If you are using this entire disk for FreeBSD, select
<command>A</command>.</para>
</step>
<step>
<para>When asked:
<informalexample>
<screen>Do you want to do this with a true partition entry so as to remain
cooperative with any future possible operating systems on the
drive(s)?</screen>
</informalexample>
answer <command>No</command>.</para>
</step>
<step>
<para>When asked if you still want to do this, answer
<command>Yes</command>.</para>
</step>
<step>
<para>Select <command>Write</command>.</para>
</step>
<step>
<para>When warned about writing on installed systems, answer
<command>Yes</command>.</para>
</step>
<step>
<para><command>Quit</command>the FDISK Editor and
<keycap>ESCAPE</keycap> back to the Index menu.</para>
</step>
<step>
<para>Select <command>Label</command> from the Index
menu.</para>
</step>
<step>
<para>Label as desired. For a single partition, enter
<command>C</command> to Create a partition, accept the
default size, partition type Filesystem, and a mountpoint
(which is not used).</para>
</step>
<step>
<para>Enter <command>W</command> when done and confirm to
continue. The filesystem will be newfs'd for you, unless
you select otherwise (for new partitions you will want to
do this!). You will get the error:
<informalexample>
<screen>Error mounting /mnt/dev/ad2s1e on /mnt/blah : No such file or directory</screen>
</informalexample>
Ignore.</para>
</step>
<step>
<para>Exit out by repeatedly pressing
<keycap>ESCAPE</keycap>.</para>
</step>
</procedure>
</sect2>
<sect2>
<title>Making Dedicated Mode Disks Using the Command Line</title>
<para>Execute the following commands, replacing <devicename>ad2</devicename> with the
disk name.</para>
<informalexample>
<screen>&prompt.root; <userinput>dd if=/dev/zero of=/dev/ad2 count=2</userinput>
&prompt.root; <userinput>disklabel /dev/ad2 | disklabel -B -R -r ad2 /dev/stdin</userinput>
<lineannotation>We only want one partition, so using slice 'c' should be fine:</lineannotation>
&prompt.root; <userinput>newfs /dev/ad2c</userinput></screen>
</informalexample>
<para>If you need to edit the disklabel to create multiple
partitions (such as swap), use the following: </para>
<informalexample>
<screen>&prompt.root; <userinput>dd if=/dev/zero of=/dev/ad2 count=2</userinput>
&prompt.root; <userinput>disklabel /dev/ad2 > /tmp/label</userinput>
<lineannotation>Edit disklabel to add partitions:</lineannotation>
&prompt.root; <userinput>vi /tmp/label</userinput>
&prompt.root; <userinput>disklabel -B -R -r ad2 /tmp/label</userinput>
<lineannotation>newfs partitions appropriately</lineannotation></screen>
</informalexample>
<para>Your disk is now ready for use.</para>
</sect2>
</sect1>
<sect1>
<title>Making Compatibility Mode Disks</title>
<sect2>
<title>Introduction</title>
<para>The command line is the easiest way to make dedicated
disks, and the worst way to make compatibility disks. The
command-line <command>fdisk</command> utility requires higher math skills and an
in-depth understanding of the slice table, which is more than
most people want to deal with. Use sysinstall for
compatibility disks, as described below.</para>
</sect2>
<sect2>
<title>Making Compatibility Mode Disks Using Sysinstall</title>
<procedure>
<step>
<para>Start sysinstall as root by typing
<informalexample>
<screen>&prompt.root; <userinput>/stand/sysinstall</userinput></screen>
</informalexample>
from the command prompt.</para>
</step>
<step>
<para>Select <command>Index</command>.</para>
</step>
<step>
<para>Select <command>Partition</command>.</para>
</step>
<step>
<para>Select the disk to edit with arrow keys and
<keycap>SPACE</keycap>.</para>
</step>
<step>
<para>If you are using this entire disk for FreeBSD, select
<command>A</command>.</para>
</step>
<step>
<para>When asked:
<informalexample>
<screen>Do you want to do this with a true partition entry so as to remain
cooperative with any future possible operating systems on the
drive(s)?</screen>
</informalexample>
answer <command>yes</command>.</para>
</step>
<step>
<para>Select <command>Write</command>.</para>
</step>
<step>
<para>When asked to install the boot manager, select None
with <keycap>SPACE</keycap> then hit
<keycap>ENTER</keycap> for OK.</para>
</step>
<step>
<para><command>Quit</command> the FDISK Editor.</para>
</step>
<step>
<para>You will be asked about the boot manager, select
<command>None</command> again. </para>
</step>
<step>
<para>Select <command>Label</command> from the Index
menu.</para>
</step>
<step>
<para>Label as desired. For a single partition, accept the
default size, type filesystem, and a mountpoint (which
is not used).</para>
</step>
<step>
<para>The filesystem will be newfs'd for you, unless you
select otherwise (for new partitions you will want to do
this!). You will get the error:
<informalexample>
<screen>Error mounting /mnt/dev/ad2s1e on /mnt/blah : No such file or directory</screen>
</informalexample>
Ignore.</para>
</step>
<step>
<para>Exit out by repeatedly pressing
<keycap>ESCAPE</keycap>.</para>
</step>
</procedure>
<para>Your new disk is now ready for use.</para>
</sect2>
</sect1>
<sect1>
<title>Other Disk Operations</title>
<sect2>
<title>Adding Swap Space</title>
<para>As a system grows, its need for swap space can also grow.
Although adding swap space to existing disks is very
difficult, a new disk can be partitioned with additional swap
space.</para>
<para>To add swap space when adding a disk to a system:</para>
<procedure>
<step>
<para>When partitioning the disk, edit the disklabel and
allocate the amount of swap space to add in partition `b'
and the remainder in another partition, such as `a' or
`e'. The size is given in 512 byte blocks.</para>
</step>
<step>
<para>When newfsing the drive, do NOT newfs the `c'
partition. Instead, newfs the partition where the
non-swap space lies.</para>
</step>
<step>
<para>Add an entry to <filename>/etc/fstab</filename> as
follows:</para>
<informalexample>
<programlisting>/dev/ad0b none swap sw 0 0
</programlisting>
</informalexample>
<para>Change <filename>/dev/ad0b</filename> to the device of the newly added
space.</para>
</step>
<step>
<para>To make the new space immediately available, use the
<command>swapon</command> command.
<informalexample>
<screen>&prompt.root; <userinput>swapon /dev/da0b</userinput>
swapon: added /dev/da0b as swap space</screen>
</informalexample>
</para>
</step>
</procedure>
</sect2>
<sect2>
<title>Copying the Contents of Disks</title>
<!-- Should have specific tag -->
<para>Submitted By: Renaud Waldura
(<email>renaud@softway.com</email>) </para>
<para>To move file from your original base disk to the fresh new
one, do:
<informalexample>
<screen>&prompt.root; <userinput>mount /dev/ad2 /mnt</userinput>
&prompt.root; <userinput>pax -r -w -p e /usr/home /mnt</userinput>
&prompt.root; <userinput>umount /mnt</userinput>
&prompt.root; <userinput>rm -rf /usr/home/*</userinput>
&prompt.root; <userinput>mount /dev/ad2 /usr/home</userinput></screen>
</informalexample>
</para>
</sect2>
<sect2>
<title>Creating Striped Disks using CCD</title>
<para>Commands Submitted By: Stan Brown
(<email>stanb@awod.com</email>) </para>
<para>The Concatenated Disk Driver, or CCD, allows you to treat
several identical disks as a single disk. Striping can result
in increased disk performance by distributing reads and writes
across the disks. See the &man.ccd.4; and &man.ccdconfig.8;
manual pages or the <ulink
URL="http://stampede.cs.berkeley.edu/ccd/">CCD
Homepage</ulink> for further details.</para>
<para>You no longer need to build a special kernel to run ccd. When you
run <command>ccdconfig</command>, it will load the KLD for you if the
kernel does not contain CCD support.</para>
<para>You build CCDs on disk partitions of type
<emphasis>4.2BSD</emphasis>. If you want to use the entire disk, you
still need to create a new partition. For example, <userinput>disklabel
-e</userinput> might show:</para>
<informalexample>
<screen># size offset fstype [fsize bsize bps/cpg]
c: 60074784 0 unused 0 0 0 # (Cyl. 0 - 59597)</screen>
</informalexample>
<para>You should not use partition <emphasis>c</emphasis> for the CCD,
since it is of type <emphasis>unused</emphasis>. Instead, create a new
partition of exactly the same size, but with type
<emphasis>4.2BSD</emphasis>:</para>
<informalexample>
<screen># size offset fstype [fsize bsize bps/cpg]
c: 60074784 0 unused 0 0 0 # (Cyl. 0 - 59597)
<userinput> e: 60074784 0 4.2BSD 0 0 0 # (Cyl. 0 - 59597)</userinput></screen>
</informalexample>
<para>To create a new CCD, execute the following commands. This
describes how to add three disks together; simply add or remove devices
as necessary. Remember that the disks to be striped must be
<emphasis>identical.</emphasis></para>
<informalexample>
<screen>&prompt.root; <userinput>cd /dev ; sh MAKDEV ccd0</userinput>
&prompt.root; <userinput>disklabel -r -w da0 auto</userinput>
&prompt.root; <userinput>disklabel -r -w da1 auto</userinput>
&prompt.root; <userinput>disklabel -r -w da2 auto</userinput>
&prompt.root; <userinput>disklabel -e da0</userinput>
<lineannotation>Add partition e with type 4.2BSD</lineannotation>
&prompt.root; <userinput>disklabel -e da1</userinput>
<lineannotation>Add partition e with type 4.2BSD</lineannotation>
&prompt.root; <userinput>disklabel -e da2</userinput>
<lineannotation>Add partition e with type 4.2BSD</lineannotation>
&prompt.root; <userinput>ccdconfig ccd0 273 0 /dev/da0e /dev/da1e /dev/da2e</userinput>
&prompt.root; <userinput>newfs /dev/ccd0c</userinput></screen>
</informalexample>
<para>The value 273 is the stripe size. This is the number of disk
sectors (of 512 bytes each) in each block of data on the CCD. It should
be at least 128 kB, and it should not be not be a power of 2.</para>
<para>Now you can mount and use your CCD by referencing device
<filename>/dev/ccd0c</filename>.</para>
<para>A more powerful and flexible alternative to CCD is Vinum. See the
<ulink URL="http://www.vinumvm.org/">Vinum Project home page</ulink>
for further details.</para>
</sect2>
</sect1>
<sect1>
<title>Credits</title>
<para>The author would like to thank the following individuals for
their contributions to this project:</para>
<itemizedlist>
<listitem>
<para>Darryl Okahata
(<email>darrylo@hpnmhjw.sr.hp.com</email>) for his simple
dedicated mode setup documentation which I have used
repeatedly on FreeBSD-questions.</para>
</listitem>
<listitem>
<para>&a.jkh; for making sysinstall useful for this type of task.
</para>
</listitem>
<listitem>
<para>John Fieber (<email>jfieber@indiana.edu</email>) for
making information and examples of the DocBook DTD on which
this document is based.</para>
</listitem>
<listitem>
<para>&a.grog; for checking my work and pointing out inaccuracies,
as well as miscellaneous support.</para>
</listitem>
</itemizedlist>
</sect1>
</article>