File:  [NetBSD Developer Wiki] / wikisrc / guide / misc.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Tue Mar 5 22:57:52 2013 UTC (8 years, 4 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
 * Add credits to Mingzhe Wang
 * Add misc section from the guide to the wiki

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

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