<!-- $NetBSD: chap-misc.xml,v 1.7 2026/10/12 13:46:56 nia Exp $ -->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>
<!DOCTYPE chapter [
<!ENTITY os "NetBSD">
<!ENTITY rprompt "#">
<!ENTITY man.cp.1 "<citerefentry><refentrytitle>cp</refentrytitle><manvolnum>1</manvolnum></citerefentry>">
<!ENTITY man.boot.8 "<citerefentry><refentrytitle>boot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.installboot.8 "<citerefentry><refentrytitle>installboot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.fdisk.8 "<citerefentry><refentrytitle>fdisk</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.mbr.8 "<citerefentry arch='x86'><refentrytitle>x86/mbr</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.x86boot.8 "<citerefentry arch='x86'><refentrytitle>x86/boot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.sun3boot.8 "<citerefentry arch='sun3'><refentrytitle>sun3/boot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.macppcboot.8 "<citerefentry arch='macppc'><refentrytitle>macppc/boot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.macppcofwboot.8 "<citerefentry arch='macppc'><refentrytitle>macppc/ofwboot</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
<!ENTITY man.gpt.8 "<citerefentry><refentrytitle>gpt</refentrytitle><manvolnum>8</manvolnum></citerefentry>">
] >

<chapter id="chap-misc">
  <title>Miscellaneous operations</title>

  <para>This chapter collects various topics, in sparse order</para>

  <sect1 id="chap-misc-bootmanager">
    <title>Installing the boot manager</title>

    <para>The boot manager is tied to the machine firmware, and not
      tied to an operating system.
      It loads and runs a boot loader, not necessarily the &os; boot
      loader.</para>

    <sect2 id="chap-misc-bootmanager-efi">
      <title>
        (U)EFI systems
      </title>

      <para>On systems with UEFI firmware, the boot manager comes with the
        firmware, and there is no &os; boot manager involved.</para>

    </sect2>

    <sect2 id="chap-misc-bootmanager-ofw">
      <title>
        OpenFirmware systems
      </title>

      <para>On systems with OpenFirmware firmware, the boot manager is part of
        the firmware, and there is no &os; boot manager involved.
        See &man.macppcofwboot.8;.</para>

    </sect2>

    <sect2 id="chap-misc-bootmanager-nonefi">
      <title>
        &os; boot manager on PC/AT compatible non-(U)EFI systems
      </title>

      <para>&os; provides boot managers for PC/AT and compatible systems with a
        "BIOS" instead of UEFI firmware.
        In the past, such systems had no real boot manager to speak of,
        although more recent systems often have menus for at least selecting
        which disk to boot from and in what order to attempt them.</para>

      <para>Sysinst, the &os; installation program usually installs the &os;
        boot manager on the hard disk.</para>

      <para>The &os; boot manager lives in unpartitioned space right in the
        first sector(s) of the disk.
        The installation programs of other operating systems, particularly if
        they re-partition the hard disk as part of their installation process,
        will usually overwrite this area with one of their own boot
        managers.</para>

      <sect3 id="chap-misc-bootmanager-nonefi-gpt">
        <title>
          with a GPT partitioned disk
        </title>

        <para>When a disk has the GUID partition table, the &os; boot manager
          can be re-installed or reconfigured at a later time, if needed, with
          the &man.gpt.8; command.
          For example, assuming that your hard disk is <filename>wd0</filename>
          and the &os; root partition is the partition with index 1:</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>gpt biosboot -i 1 wd0
</userinput></screen>

        <para>See &man.gpt.8; for other ways in which the &os; root partition
          can be specified.
          Substitute <filename>sd0</filename> for <filename>wd0</filename> if
          you have a SCSI disk, and change numbers as appropriate.</para>

      <note>
        <para>This is unrelated to GUID partitions of type <quote>biosboot</quote>.
          Those have nothing to do with the &os; boot manager.</para>
      </note>

      </sect3>

      <sect3 id="chap-misc-bootmanager-nonefi-mbr">
        <title>
          with a "MBR" partitioned disk
        </title>

        <para>When a disk has the "MBR"-style partition table, the &os; boot
          manager can be re-installed or reconfigured at a later time, if
          needed, with the &man.fdisk.8; command.
          For example:</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>fdisk -B wd0
</userinput></screen>

        <para>This installs the default boot manager.
          There are several others that can be chosen with
          <command>fdisk</command>'s <arg choice='plain'>-c</arg> option.
          The choices of boot manager are listed in &man.mbr.8;.
          Again, substitute <filename>sd0</filename> for
          <filename>wd0</filename> if you have a SCSI disk, and change numbers
          as appropriate.</para>

        <note>
          <para>Sometimes <command>fdisk -B</command> doesn't give the expected
            result (at least it happened to me), probably if you
            install/remove other operating systems.
            <!-- I have no idea which of the previous authors is "me" here.  JdeBP 2026-10-18 -->
            In this case, try running <command>fdisk -i</command> and
            then run again <command>fdisk</command> from &os;.</para>
        </note>

      </sect3>

      <sidebar>
        <title>Rescuing from when the boot manager does not boot</title>

        <para>If &os; doesn't boot from the hard disk, you can boot it from
          the installation disk/USB device and start the kernel on the hard
          disk.
          Insert the installation disk/USB device and, at the boot prompt,
          give the following command:</para>

<screen><prompt>&gt;</prompt> <userinput>boot wd0a:netbsd
</userinput></screen>

        <para>This boots the kernel on the hard disk.  (Use the correct device,
          for example <filename>sd0a</filename> for a SCSI disk.)</para>
      </sidebar>

    </sect2>

    <sect2 id="chap-misc-bootmanager-other">
      <title>
        non-firmware-built-in non-&os; boot managers
      </title>

      <para>Non-&os; boot managers (e.g. OS/2 Boot Manager, Partition Magic
        Boot Manager, Microsoft Windows Boot Manager, and the GNU GRand Unified
        Bootloader) are not in scope for this guide.
        See their own documentation for how to install and configure them.
        They are expected to load and run the &os; boot loader from a &os; root
        filesystem, in some fashion.</para>

    </sect2>

  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-bootloader">
    <title>Installing the boot loader</title>

    <para>The boot manager loads and runs the &os; boot loader.
      This program is generally described in &man.boot.8;, with extra
      architecture-specific information to be found on pages such as
      &man.x86boot.8;, &man.sun3boot.8;, or &man.macppcboot.8;.</para>
      <!-- CAUTION: These macros for */boot(8) seems to be missing from man-refs.ent . -->

    <sect2 id="chap-misc-bootloader-efi">
      <title>
        (U)EFI systems
      </title>

      <para>On systems with UEFI firmware, the UEFI Boot Manager finds and
        runs the &os; boot loader.
        Either you will have explicitly added an entry to the UEFI Boot
        Manager that points to a copy of the &os; boot loader, or UEFI will be
        looking in the well-known place that it looks for a fallback boot
        loader.
        In both cases, the &os; boot loader is a file stored on the EFI System
        Partition.</para>

      <para>A master copy of the &os; boot loader for UEFI can be found in
        <filename>/usr/mdec</filename>, and is named after the processor
        architecture, something like <filename>bootia32.efi</filename>,
        <filename>bootx64.efi</filename>, or
        <filename>bootaa64.efi</filename>.
        UEFI specifies the exact filename, and usually just the one(s)
        appropriate to your machine's processor architecture will exist in
        <filename>/usr/mdec</filename>.</para>

      <para>This file is usually copied to the <filename>/EFI/boot</filename>
        directory on the EFI System Partition, the place that UEFI looks for a
        fallback boot loader; and if it is missing from there, copy it
        back.
        For example, assuming that <filename>/dev/dk2</filename> is your EFI
        System Partition:</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>mount -t msdos /dev/dk2 /mnt
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>cp -i /usr/mdec/boot*.efi /mnt/EFI/boot/
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>umount /mnt
</userinput></screen>

      <para>If, rather, you have explicitly added the &os; boot loader as an
        entry on the UEFI Boot Manager menu, copy the file to where that entry
        points.</para>

      <note>
        <para>If you are multi-booting &os; and some other operating system,
          they cannot both use the
          <filename>/EFI/boot/boot<replaceable>arch</replaceable>.efi</filename>
          file.
          This is the case where you must have explicit entries in the EFI
          Boot Manager, and the &os; boot loader should be copied into
          <filename>/EFI/NetBSD</filename> on the EFI System Partition with an
          entry pointing at it.</para>
      </note>
    </sect2>

    <sect2 id="chap-misc-bootloader-non-efi">
      <title>
        non-(U)EFI systems
      </title>

      <para>On non-UEFI systems, Sysinst, the &os; installation program again
        usually installs the &os; boot loader on the hard disk.
        It can also be re-installed or reconfigured at a later time, if
        needed.</para>

      <para>The &os; boot loader on these systems comes in two parts, a
        <quote>primary</quote> part and a <quote>secondary</quote> part.
        Each can be re-installed separately, according to need.</para>

      <para>The <quote>secondary</quote> part lives in a file (usually in the
        root directory) on the boot filesystem.
        A master copy of it is in the <filename>/usr/mdec</filename>
        directory.
        Re-install it by copying it into the root directory of whatever
        filesystem you are making bootable.
        For example, assuming that you are (re-)installing the loader on your
        <filename>dk3</filename> disk wedge (and that is not your current root
        partition):</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>mount /dev/dk3 /mnt
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>cp -i /usr/mdec/boot /mnt/
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>umount /mnt
</userinput></screen>

      <para>The <quote>secondary</quote> part is specific to the machine
        type, and that is supposed to be part of its filename.
        Fortunately, the file can also be referred to by the generic name
        <filename>boot</filename> and the <quote>primary</quote> part knows to
        also look there.</para>

      <para>For best results, re-install the <quote>primary</quote> part after
        installing the <quote>secondary</quote>.
        It lives in a special area of the filesystem, not in any file.
        A master copy of it is in the <filename>/usr/mdec</filename>
        directory.
        It is installed with the &man.installboot.8; command.
        For example, assuming that <filename>/dev/dk3</filename> is your root
        partition and that it is a FFSv2 partition:</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>installboot /dev/dk3 /usr/mdec/boot_ffsv2 /boot
</userinput></screen>

      <para>The <quote>primary</quote> part is specific to the filesystem
        format, and must match it.
        The list of possible files to use in place of
        <filename>boot_ffsv2</filename> can be found on the
        &man.installboot.8; page.</para>

    </sect2>
  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-delete-disklabel">
    <title>Deleting the disklabel</title>

    <para>Though this is not an operation that you need to perform
      frequently, it can be useful to know how to do it in case of
      need.
      Please be sure to know exactly what you are doing before
      performing this kind of operation.
      For example:</para>

    <screen>&rprompt; <userinput>dd if=/dev/zero of=/dev/rwd0c bs=8k count=1</userinput></screen>

    <para>The previous command deletes the disklabel (not the MBR partition
      table).
      To completely delete the disk, the whole device <filename>rwd0d</filename>
      must be used.
      For example:</para>

    <screen>&rprompt; <userinput>dd if=/dev/zero of=/dev/rwd0d bs=8k</userinput></screen>
    <para>The commands above will only work as expected on the i386 and amd64 ports
    of &os;. On other ports, the whole device will end in c, not d (e.g.
    <filename>rwd0c</filename>).</para>

    <sect2 id="chap-misc-delete-gpt">
      <title>
        Deleting the GPT instead
      </title>

      <para>When the disk is partitioned with the GUID Partition Table (GPT),
        clearing the partition table is done with the &man.gpt.8;
        command:</para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>gpt destroy -r wd1
</userinput></screen>

    </sect2>
  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-speaker">
    <title>Speaker</title>

    <para>To output a sound from the speaker (for example at the end of a
      long script) the <emphasis>spkr</emphasis> driver can be used in
      the kernel config, which is mapped on
      <filename>/dev/speaker</filename>. For example:</para>

    <screen>echo 'BPBPBPBPBP' &gt; /dev/speaker</screen>

    <note>
      <para>The <emphasis>spkr</emphasis> device is not enabled in the
        generic kernel; a customized kernel is needed.</para>
    </note>

  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-forgot-root-password">
    <title>Forgot root password?</title>

    <para>If you forget root's password, not all is lost and you can still
      recover the system with the following steps: boot
      single user, mount / and change root's password.
      In detail:</para>

    <orderedlist>
      <listitem>
	<para>Boot single user: when the boot prompt appears and the five
	  seconds countdown starts, give the following command:</para>

        <screen><prompt>&gt;</prompt> <userinput>boot -s</userinput></screen>
      </listitem>

      <listitem>
	<para>At the following prompt</para>

        <screen>Enter pathname of shell or RETURN for sh:</screen>

        <para>press Enter.</para>
      </listitem>

      <listitem>
	<para>Write the following commands:</para>

        <screen>&rprompt; <userinput>fsck -y /</userinput>
&rprompt; <userinput>mount -u /</userinput>
&rprompt; <userinput>fsck -y /usr</userinput>
&rprompt; <userinput>mount /usr</userinput></screen>
      </listitem>

      <listitem>
	<para>Change root's password:</para>

	<screen>&rprompt; <userinput>passwd root</userinput>
Changing local password for root.
New password: <userinput>(not echoed)</userinput>
Retype new password: <userinput>(not echoed)</userinput>
&rprompt; </screen>
      </listitem>

      <listitem>
	<para>Exit the shell to go to multiuser
	  mode.</para>

	<screen>&rprompt; <userinput>exit</userinput></screen>
      </listitem>
    </orderedlist>
    <para>If you get the error <quote>Password file is busy</quote>,
    please see the section below.</para>
  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-password-file-busy">
    <title>Password file is busy?</title>

    <para>If you try to modify a password and you get the mysterious
      message <quote>Password file is busy</quote>, it probably
      means that the file <filename>/etc/ptmp</filename> has not
      been deleted from the system.  This file is a temporary copy
      of the <filename>/etc/master.passwd</filename> file; check
      that you are not losing important information and then
      delete it:</para>

    <screen> &rprompt; <userinput>rm /etc/ptmp</userinput> </screen>

    <note>
      <para>If the file <filename>/etc/ptmp</filename> exists you can
	also receive a warning message at system startup.  For
	example:</para>

      <screen>root: password file may be incorrect - /etc/ptmp exists</screen>
    </note>
  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-adding-new-disk">
    <title>Adding a new hard disk</title>

    <para>This section describes how to add a new hard disk to an
        already working &os; system.</para>

    <sect2 id="chap-misc-adding-new-disk-gpt">
      <title>
        A new SATA disk and GPT
      </title>

      <para>
        In the following example a new SATA hard disk will be added.
        Other disk types can also be used, e.g. NVMe/M.2 by substituting
        <filename>wd#</filename> for <filename>ld#</filename>.
      </para>

      <para>
        When the SATA disk is physically plugged in to the SATA port,
        it is time to restart the computer and check that the device
        is correctly detected, using the <command>dmesg</command>
	command.
	This example kernel message is with a Seagate Barracuda drive:
      </para>
<screen><computeroutput>wd1 at atabus0 drive 1: &lt;ST380013AS&gt;
wd1: drive supports 16-sector PIO transfers, LBA48 addressing
wd1: 76293 MB, 155010 cyl, 16 head, 63 sec, 512 bytes/sect x 156250080 sectors
wd1: 32-bit data port
wd1: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 6 (Ultra/133)
</computeroutput></screen>

      <para>
        Now the partitions can be created using the <command>gpt</command>
	command.
	First, check the current status of the disk:
      </para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>gpt show wd1
</userinput><computeroutput>start         size  index  contents
         0  156250080
</computeroutput></screen>

      <para>
        In this example the hard disk is blank, with no partition tables or
        disk labels.
        To create, for example, an EFI System Partition followed by a &os;
        partition, the commands are:
      </para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>gpt create wd1
</userinput><computeroutput>&rprompt; </computeroutput><userinput>gpt add -t efi -l EFI -s 1m wd1
</userinput><computeroutput>Partition 1 added, use:
  dkctl wd1 addwedge &lt;wedgename&gt; xxx yyyyyyy &lt;type&gt;
to create a wedge for it
&rprompt; </computeroutput><userinput>gpt add -t ffs -l netbsd-data wd1
</userinput><computeroutput>Partition 2 added, use:
  dkctl wd1 addwedge &lt;wedgename&gt; xxx yyyyyyy &lt;type&gt;
to create a wedge for it
</computeroutput> </screen>

      <para>
        For simplicity, tell &os; to automatically re&#x2010;make the
	disk wedges for the newly defined partitions. This may not be
        necessary depending on the kernel configuration in use:
      </para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>dkctl wd1 makewedges
</userinput><computeroutput></computeroutput> </screen>

      <para>
	Let us assume that the resultant disk wedges are <filename>dk2</filename> 
	and <filename>dk3</filename>. The device node names can be
        seen with <command>dkctl wd1 listwedges</command>.
        Most commands can also accept
        <userinput>NAME=xxx</userinput> where <userinput>xxx</userinput>
        is a GPT partition label.
      </para>
      <para>
        The final operation is the creation of the file systems for
        the newly defined partitions:
      </para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>newfs_msdos -F 32 -L EFISYS dk2
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>newfs -O2ea dk3
</userinput><computeroutput>
</computeroutput> </screen>

      <para>
        The disk is now ready for usage, and the partitions can
        be mounted.
	For example:
      </para>

<screen><computeroutput>&rprompt; </computeroutput><userinput>mount /dev/dk3 /mnt
</userinput><computeroutput>
&rprompt; </computeroutput><userinput>mount /dev/dk2 /boot/efi
</userinput></screen>

    </sect2>

    <!-- ============================================================= -->

    <sect2 id="chap-misc-adding-new-disk-disklabel">
      <title>A new SCSI disk and disklabel</title>

      <para>In the following example a
        new SCSI controller and a new hard disk, connected to the
        controller, will be added.  If you don't need to add a new
        controller, skip the relevant part and go to the hard disk
        configuration.  The installation of an IDE/SATA hard disk
        using disklabel is identical; only the device name will be
        different (<filename>wd#</filename> instead of
        <filename>sd#</filename>).</para>

      <para>As always, before buying new hardware, consult the hardware
        compatibility list of &os; and make sure that the new device
        is supported by the system.</para>
  
      <para>When the SCSI controller has been physically installed in the
        system and the new hard disk has been connected, it's time to
        restart the computer and check that the device is correctly
        detected, using the <command>dmesg</command> command.  This
        is the sample output for an NCR-875 controller:</para>

      <screen>ncr0 at pci0 dev 15 function 0: ncr 53c875 fast20 wide scsi
ncr0: interrupting at irq 10
ncr0: minsync=12, maxsync=137, maxoffs=16, 128 dwords burst, large dma fifo
ncr0: single-ended, open drain IRQ driver, using on-chip SRAM
ncr0: restart (scsi reset).
scsibus0 at ncr0: 16 targets, 8 luns per target
sd0(ncr0:2:0): 20.0 MB/s (50 ns, offset 15)
sd0: 2063MB, 8188 cyl, 3 head, 172 sec, 512 bytes/sect x 4226725 sectors</screen>

      <para>If the device doesn't appear in the output, check that it is
        supported by the kernel that you are using; if necessary,
        compile a customized kernel (see  <xref
        linkend="chap-kernel" />).</para>

      <para>Now the partitions can be created using the <command>fdisk</command>
        command.  First, check the current status of the disk:</para>

      <screen>&rprompt; <userinput>fdisk sd0</userinput>
NetBSD disklabel disk geometry:
cylinders: 8188 heads: 3 sectors/track: 172 (516 sectors/cylinder)

BIOS disk geometry:
cylinders: 524 heads: 128 sectors/track: 63 (8064 sectors/cylinder)

Partition table:
0: sysid 6 (Primary 'big' DOS, 16-bit FAT (> 32MB))
    start 63, size 4225473 (2063 MB), flag 0x0
        beg: cylinder    0, head   1, sector  1
        end: cylinder  523, head 127, sector 63
1: &lt;UNUSED&gt;
2: &lt;UNUSED&gt;
3: &lt;UNUSED&gt;</screen>

      <para>In this example the hard disk already contains a DOS
        partition, which will be deleted and replaced with a native
        &os; partition.  The command <command>fdisk -u sd0</command>
        allows to modify interactively the partitions.  The modified
        data will be written on the disk only before exiting and fdisk
        will request a confirmation before writing, so you can work
        relaxedly.</para>

    <sidebar>
      <title>Disk geometries</title>

      <para>The geometry of the disk reported by fdisk can appear
	confusing.  Dmesg reports 4226725 sectors with 8188/3/172
	for C/H/S, but 8188*3*172 gives 4225008 and not 4226725.
	What happens is that most modern disks don't have a fixed
	geometry and the number of sectors per track changes
	depending on the cylinder: the only interesting parameter
	is the number of sectors.  The disk reports the C/H/S
	values but it's a fictitious geometry: the value 172 is the
	result of the total number of sectors (4226725) divided by
	8188 and then by 3.</para>

      <para>To make things more confusing, the BIOS uses yet another
	<quote>fake</quote> geometry (C/H/S 524/128/63) which gives
	a total of 4225536, a value which is a better approximation
	to the real one than 425008.  To partition the disk we will
	use the BIOS geometry, to maintain compatibility with other
	operating systems, although we will lose some sectors
	(4226725 - 4225536 = 1189 sectors = 594 KB).</para>
    </sidebar>

      <para>To create the BIOS partitions the command <command>fdisk -u</command>
        must be used; the result is the following:</para>

        <screen>Partition table:
0: sysid 169 (NetBSD)
    start 63, size 4225473 (2063 MB), flag 0x0
        beg: cylinder    0, head   1, sector  1
        end: cylinder  523, head 127, sector 63
1: &lt;UNUSED&gt;
2: &lt;UNUSED&gt;
3: &lt;UNUSED&gt;</screen>

      <para>Now it's time to create the disklabel for the &os;
        partition.  The correct steps to do this are:</para>

      <screen>&rprompt; <userinput>disklabel sd0 > tempfile</userinput>
&rprompt; <userinput>vi tempfile</userinput>
&rprompt; <userinput>disklabel -R -r sd0 tempfile</userinput></screen>

      <sidebar>
        <para>If you try to create the disklabel directly with</para>

        <screen>&rprompt; <userinput>disklabel -e sd0</userinput></screen>

        <para>you get the following message</para>

        <screen>disklabel: ioctl DIOCWDINFO: No disk label on disk;
use "disklabel -I" to install initial label</screen>

        <para>because the disklabel does not yet exist on the disk.</para>
    </sidebar>

      <para>Now we create some disklabel partitions, editing the
        <filename>tempfile</filename> as already explained.  The
        result is:</para>

      <programlisting>#      size   offset   fstype [fsize bsize   cpg]
a:  2048004       63   4.2BSD   1024  8192    16 # (Cyl.  0*- 3969*)
c:  4226662       63   unused      0     0       # (Cyl.  0*- 8191*)
d:  4226725        0   unused      0     0       # (Cyl.  0 - 8191*)
e:  2178658  2048067   4.2BSD   1024  8192    16 # (Cyl.  3969*- 8191*)</programlisting>

    <note>
      <para>When the disklabel has been created it is possible to
	optimize it studying the output of the command
	<command>newfs -N /dev/rsd0a</command>, which warns about
	the existence of unallocated sectors at the end of a
	disklabel partition.  The values reported by newfs can be
	used to adjust the sizes of the partitions with an
	iterative process.</para>
    </note>

      <para>The final operation is the creation of the file systems for
        the newly defined partitions (<emphasis>a</emphasis> and
        <emphasis>e</emphasis>).</para>

      <screen>&rprompt; <userinput>newfs /dev/rsd0a</userinput>
&rprompt; <userinput>newfs /dev/rsd0e</userinput></screen>

      <para>The disk is now ready for usage, and the two partitions can
        be mounted.  For example:</para>

      <screen>&rprompt; <userinput>mount /dev/sd0a /mnt</userinput></screen>
  
      <para>If this succeeds, you may want to put an entry for the partition
        into <filename>/etc/fstab</filename>.</para>
    </sect2>
  </sect1>

  <!-- ============================================================= -->

  <sect1 id="chap-misc-howto-rebuild-devices">
    <title>How to rebuild the devices in /dev</title>

    <para>First shutdown to single user, partitions still mounted
      <quote>rw</quote>
      (read-write); You can do that by just typing <command>shutdown
      now</command> while you are in multi user mode, or reboot with
      the <option>-s</option> option and make <filename>/</filename>
      and <filename>/dev</filename> read-writable by doing.</para>

    <screen>&rprompt; <userinput>mount -u /</userinput>
&rprompt; <userinput>mount -u /dev</userinput></screen>

    <para>Then:</para>

    <screen>&rprompt; <userinput>mkdir /newdev</userinput>
&rprompt; <userinput>cd /newdev</userinput>
&rprompt; <userinput>cp /dev/MAKEDEV* .</userinput>
&rprompt; <userinput>sh ./MAKEDEV all</userinput>
&rprompt; <userinput>cd /</userinput>
&rprompt; <userinput>mv dev olddev</userinput>
&rprompt; <userinput>mv newdev dev</userinput>
&rprompt; <userinput>rm -r olddev</userinput></screen>

    <para>Or if you fetched all the sources in
      <filename>/usr/src</filename>:</para>

    <screen>&rprompt; <userinput>mkdir /newdev</userinput>
&rprompt; <userinput>cd /newdev</userinput>
&rprompt; <userinput>cp /usr/src/etc/MAKEDEV.local .</userinput>
&rprompt; <userinput>( cd /usr/src/etc ; make MAKEDEV )</userinput>
&rprompt; <userinput>cp /usr/src/etc/obj*/MAKEDEV .</userinput>
&rprompt; <userinput>sh ./MAKEDEV all</userinput>
&rprompt; <userinput>cd /</userinput>
&rprompt; <userinput>mv dev olddev; mv newdev dev</userinput>
&rprompt; <userinput>rm -r olddev</userinput></screen>

    <para>You can determine $arch by</para>

    <screen>&rprompt; <userinput>uname -m</userinput></screen>

    <para>or</para>

    <screen>&rprompt; <userinput>sysctl hw.machine_arch</userinput></screen>
  </sect1>
</chapter>
