File:  [NetBSD Developer Wiki] / wikisrc / guide / misc.mdwn
Revision 1.4: download - view: text, annotated - select for diffs
Fri Jun 19 19:18:31 2015 UTC (5 years, 1 month ago) by plunky
Branches: MAIN
CVS tags: HEAD
replace direct links to manpages on netbsd.gw.com with templates

    1: **Contents**
    2: 
    3: [[!toc levels=3]]
    4: 
    5: # Miscellaneous operations
    6: 
    7: This chapter collects various topics, in sparse order
    8: 
    9: ## Installing the boot manager
   10: 
   11: ### fdisk
   12: 
   13: Sysinst, the NetBSD installation program, usually installs the NetBSD boot
   14: manager on the hard disk. The boot manager can also be installed or reconfigured
   15: at a later time, if needed, with the
   16: [[!template id=man name="fdisk" section="8"]]
   17: command. For example:
   18: 
   19:     # fdisk -B wd0
   20: 
   21: If NetBSD doesn't boot from the hard disk, you can boot it from the installation
   22: floppy and start the kernel on the hard disk. Insert the installation disk and,
   23: at the boot prompt, give the following command:
   24: 
   25:     > boot wd0a:netbsd
   26: 
   27: This boots the kernel on the hard disk (use the correct device, for example sd0a
   28: for a SCSI disk).
   29: 
   30: *Note*: Sometimes `fdisk -B` doesn't give the expected result (at least it
   31: happened to me), probably if you install/remove other operating systems like
   32: Windows 95 or Linux with LILO. In this case, try running `fdisk -i` (which is
   33: known as `fdisk /mbr` from DOS) and then run again `fdisk` from NetBSD.
   34: 
   35: ### installboot
   36: 
   37: There is another tool for installing a bootloader, named
   38: [[!template id=man name="installboot" section="8"]].
   39: Depending on the platform you are using, its usage differs, so you should read
   40: the manpage and its extensive *EXAMPLES* section.
   41: 
   42: E.g., if you want to install the bootloader for a ffs filesystem to the
   43: partition you have your NetBSD in (in this case, `sd0c`), you would use:
   44: 
   45:     installboot -v /dev/rsd0c /usr/mdec/bootxx_ffs
   46: 
   47: ## Deleting the disklabel
   48: 
   49: Though this is not an operation that you need to perform frequently, it can be
   50: useful to know how to do it in case of need. Please be sure to know exactly what
   51: you are doing before performing this kind of operation. For example:
   52: 
   53:     # dd if=/dev/zero of=/dev/rwd0c bs=8k count=1
   54: 
   55: The previous command deletes the disklabel (not the MBR partition table). To
   56: completely delete the disk, the whole device `rwd0d` must be used. For example:
   57: 
   58:     # dd if=/dev/zero of=/dev/rwd0d bs=8k
   59: 
   60: The commands above will only work as expected on the i386 and amd64 ports of
   61: NetBSD. On other ports, the whole device will end in c, not d (e.g. `rwd0c`).
   62: 
   63: ## Speaker
   64: 
   65: I found this tip on a mailing list (I don't remember the author). To output a
   66: sound from the speaker (for example at the end of a long script) the
   67: [[!template id=man name="spkr" section="4"]]
   68: driver can be used in the kernel config, which is mapped on `/dev/speaker`. For
   69: example:
   70: 
   71:     echo 'BPBPBPBPBP' > /dev/speaker
   72: 
   73: *Note*: The `spkr` device is not enabled in the generic kernel; a customized
   74: kernel is needed.
   75: 
   76: ## Forgot root password?
   77: 
   78: If you forget root's password, not all is lost and you can still recover the
   79: system with the following steps: boot single user, mount `/` and change root's
   80: password. In detail:
   81: 
   82: 1. Boot single user: when the boot prompt appears and the five seconds
   83:    countdown starts, give the following command:
   84: 
   85:        > boot -s
   86: 
   87: 2. At the following prompt
   88: 
   89:        Enter pathname of shell or RETURN for sh:
   90: 
   91:    press Enter.
   92: 
   93: 3. Write the following commands:
   94: 
   95:        # fsck -y /
   96:        # mount -u /
   97:        # fsck -y /usr
   98:        # mount /usr
   99: 
  100: 4. Change root's password:
  101: 
  102:        # passwd root
  103:        Changing local password for root.
  104:        New password: (not echoed)
  105:        Retype new password: (not echoed)
  106:        #
  107: 
  108: 5. Exit the shell to go to multiuser mode.
  109: 
  110:        # exit
  111: 
  112: 
  113: If you get the error `Password file is busy`, please see the section below.
  114: 
  115: ## Password file is busy?
  116: 
  117: If you try to modify a password and you get the mysterious message `Password
  118: file is busy, it probably means that the file `/etc/ptmp` has not been deleted
  119: from the system. This file is a temporary copy of the `/etc/master.passwd` file;
  120: check that you are not losing important information and then delete it:
  121: 
  122:     # rm /etc/ptmp
  123: 
  124: *Note*: If the file `/etc/ptmp` exists you can also receive a warning message at
  125: system startup. For example:
  126: 
  127:     root: password file may be incorrect - /etc/ptmp exists
  128: 
  129: ## Adding a new hard disk
  130: 
  131: This section describes how to add a new hard disk to an already working NetBSD
  132: system. In the following example a new SCSI controller and a new hard disk,
  133: connected to the controller, will be added. If you don't need to add a new
  134: controller, skip the relevant part and go to the hard disk configuration. The
  135: installation of an IDE hard disk is identical; only the device name will be
  136: different (`wd#` instead of `sd#`).
  137: 
  138: As always, before buying new hardware, consult the hardware compatibility list
  139: of NetBSD or ask on a mailing list to make sure the new device is supported by
  140: NetBSD.
  141: 
  142: When the SCSI controller has been physically installed in the system and the new
  143: hard disk has been connected, it's time to restart the computer and check that
  144: the device is correctly detected, using the
  145: [[!template id=man name="dmesg" section="8"]]
  146: command. This is the sample output for an NCR-875 controller:
  147: 
  148:     ncr0 at pci0 dev 15 function 0: ncr 53c875 fast20 wide scsi
  149:     ncr0: interrupting at irq 10
  150:     ncr0: minsync=12, maxsync=137, maxoffs=16, 128 dwords burst, large dma fifo
  151:     ncr0: single-ended, open drain IRQ driver, using on-chip SRAM
  152:     ncr0: restart (scsi reset).
  153:     scsibus0 at ncr0: 16 targets, 8 luns per target
  154:     sd0(ncr0:2:0): 20.0 MB/s (50 ns, offset 15)
  155:     sd0: 2063MB, 8188 cyl, 3 head, 172 sec, 512 bytes/sect x 4226725 sectors
  156: 
  157: If the device doesn't appear in the output, check that it is supported by the
  158: kernel that you are using; if necessary, compile a customized kernel (see
  159: [[Compiling the kernel|guide/kernel]]).
  160: 
  161: Now the partitions can be created using the
  162: [[!template id=man name="fdisk" section="8"]]
  163: command. First, check the current status of the disk:
  164: 
  165:     # fdisk sd0
  166:     NetBSD disklabel disk geometry:
  167:     cylinders: 8188 heads: 3 sectors/track: 172 (516 sectors/cylinder)
  168:     
  169:     BIOS disk geometry:
  170:     cylinders: 524 heads: 128 sectors/track: 63 (8064 sectors/cylinder)
  171:     
  172:     Partition table:
  173:     0: sysid 6 (Primary 'big' DOS, 16-bit FAT (> 32MB))
  174:         start 63, size 4225473 (2063 MB), flag 0x0
  175:             beg: cylinder    0, head   1, sector  1
  176:             end: cylinder  523, head 127, sector 63
  177:     1: <UNUSED>
  178:     2: <UNUSED>
  179:     3: <UNUSED>
  180: 
  181: In this example the hard disk already contains a DOS partition, which will be
  182: deleted and replaced with a native NetBSD partition. The command
  183: `fdisk -u sd0` allows to modify interactively the partitions. The modified data
  184: will be written on the disk only before exiting and fdisk will request a
  185: confirmation before writing, so you can work relaxedly.
  186: 
  187: **Disk geometries**
  188: 
  189: The geometry of the disk reported by fdisk can appear confusing. Dmesg reports
  190: 4226725 sectors with 8188/3/172 for C/H/S, but 8188\*3\*172 gives 4225008 and
  191: not 4226725. What happens is that most modern disks don't have a fixed geometry
  192: and the number of sectors per track changes depending on the cylinder: the only
  193: interesting parameter is the number of sectors. The disk reports the C/H/S
  194: values but it's a fictitious geometry: the value 172 is the result of the total
  195: number of sectors (4226725) divided by 8188 and then by 3.
  196: 
  197: To make things more confusing, the BIOS uses yet another *fake* geometry (C/H/S
  198: 524/128/63) which gives a total of 4225536, a value which is a better
  199: approximation to the real one than 425008. To partition the disk we will use the
  200: BIOS geometry, to maintain compatibility with other operating systems, although
  201: we will lose some sectors (4226725 - 4225536 = 1189 sectors = 594 KB).
  202: 
  203: To create the BIOS partitions the command `fdisk -u` must be used; the result is
  204: the following:
  205: 
  206:     Partition table:
  207:     0: sysid 169 (NetBSD)
  208:         start 63, size 4225473 (2063 MB), flag 0x0
  209:             beg: cylinder    0, head   1, sector  1
  210:             end: cylinder  523, head 127, sector 63
  211:     1: <UNUSED>
  212:     2: <UNUSED>
  213:     3: <UNUSED>
  214: 
  215: Now it's time to create the disklabel for the NetBSD partition. The correct
  216: steps to do this are:
  217: 
  218:     # disklabel sd0 > tempfile
  219:     # vi tempfile
  220:     # disklabel -R -r sd0 tempfile
  221: 
  222: If you try to create the disklabel directly with
  223: 
  224:     # disklabel -e sd0
  225: 
  226: you get the following message
  227: 
  228:     disklabel: ioctl DIOCWDINFO: No disk label on disk;
  229:     use "disklabel -I" to install initial label
  230: 
  231: because the disklabel does not yet exist on the disk.
  232: 
  233: Now we create some disklabel partitions, editing the `tempfile` as already
  234: explained. The result is:
  235: 
  236:     #      size   offset   fstype [fsize bsize   cpg]
  237:     a:  2048004       63   4.2BSD   1024  8192    16 # (Cyl.  0*- 3969*)
  238:     c:  4226662       63   unused      0     0       # (Cyl.  0*- 8191*)
  239:     d:  4226725        0   unused      0     0       # (Cyl.  0 - 8191*)
  240:     e:  2178658  2048067   4.2BSD   1024  8192    16 # (Cyl.  3969*- 8191*)
  241: 
  242: *Note*: When the disklabel has been created it is possible to optimize it
  243: studying the output of the command `newfs -N /dev/rsd0a`, which warns about
  244: the existence of unallocated sectors at the end of a disklabel partition. The
  245: values reported by newfs can be used to adjust the sizes of the partitions with
  246: an iterative process.
  247: 
  248: The final operation is the creation of the file systems for the newly defined
  249: partitions (`a:` and `e:`).
  250: 
  251:     # newfs /dev/rsd0a
  252:     # newfs /dev/rsd0e
  253: 
  254: The disk is now ready for usage, and the two partitions can be mounted. For
  255: example:
  256: 
  257:     # mount /dev/sd0a /mnt
  258: 
  259: If this succeeds, you may want to put an entry for the partition into
  260: `/etc/fstab`.
  261: 
  262: ## How to rebuild the devices in /dev
  263: 
  264: First shutdown to single user, partitions still mounted `rw` (read-write); You
  265: can do that by just typing `shutdown now` while you are in multi user mode, or
  266: reboot with the `-s` option and make `/` and `/dev` read-writable by doing.
  267: 
  268:     # mount -u /
  269:     # mount -u /dev
  270: 
  271: Then:
  272: 
  273:     # mkdir /newdev
  274:     # cd /newdev
  275:     # cp /dev/MAKEDEV* .
  276:     # sh ./MAKEDEV all
  277:     # cd /
  278:     # mv dev olddev
  279:     # mv newdev dev
  280:     # rm -r olddev
  281: 
  282: Or if you fetched all the sources in `/usr/src`:
  283: 
  284:     # mkdir /newdev
  285:     # cd /newdev
  286:     # cp /usr/src/etc/MAKEDEV.local .
  287:     # ( cd /usr/src/etc ; make MAKEDEV )
  288:     # cp /usr/src/etc/obj*/MAKEDEV .
  289:     # sh ./MAKEDEV all
  290:     # cd /
  291:     # mv dev olddev; mv newdev dev
  292:     # rm -r olddev
  293: 
  294: You can determine $arch by
  295: 
  296:     # uname -m
  297: 
  298: or
  299: 
  300:     # sysctl hw.machine_arch
  301: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb