Adding New Hard Disks


When you first install OpenBSD, the install program handles formatting and partitioning your hard disks and walks you through partitioning and mounting them. When you have to add disks to an existing system, you'll need to run the commands to perform these actions. The good news is, if you can install OpenBSD you already know how to work the commands — the only hard part will be learning which commands to run.

We'll cover two examples: creating an empty /usr/obj partition for upgrading your system and moving /home to a new disk. Just as if you were starting an install, write down how you want your new hard drive to be partitioned.

Note

Before you start, be absolutely certain you have backed up your system!

fdisk

Do you want your new hard drive to be dedicated to OpenBSD? If so, fdisk(8) will easily let you initialize the MBR partition table. Here, we're dedicating the first SCSI hard disk to OpenBSD partitions. fdisk(8) requires access to the raw device, and we want to work on the entire disk, so we're using device node /dev/rsd0c.

 # fdisk -i /dev/rsd0c         -----------------------------------------------------         ------ ATTENTION - UPDATING MASTER BOOT RECORD ------         ----------------------------------------------------- Do you wish to write new MBR and partition table? [n] y # 

Answer "y", and your disk will be updated. If you're not certain, enter "n" to cancel.

If you have a multiboot system, you may want to split your hard drive between multiple operating systems. Just as if you're doing an install, you want to use an operating system's native tools to create MBR partitions for that operating system.

 # fdisk -e /dev/rsd0c Enter 'help' for information fdisk: 1> 

This is the same fdisk(8) prompt we saw during a multiboot installation. See Chapter 4 for detailed instructions on how to use it.

Once you have MBR partitions on your disk, you can proceed to assign OpenBSD partitions.

Partitioning

If you used fdisk to dedicate this hard drive to OpenBSD, the drive automatically has one large "a" partition that covers the entire drive. If this is what you want, you're done. If not, you must use disklabel(8) to divide the hard disk into partitions. You can use disklabel(8) to partition the drive in two ways: a straight text menu or the same interactive process that we used during the install.

If you know exactly what you want and are comfortable with cylinder/head/ sector calculations, you can jump straight into a text editor and make the changes directly to the label. The "-e" flag to disklabel(8) will bring up a text editor containing the current disklabel, letting you make whatever changes you like.

 # disklabel -e /dev/rsd0c 

Personally, I find calculating cylinder boundaries to be a waste of time when disklabel(8) will do it for me. The "-E" flag will dump you in the same interactive disklabel(8) editor we used in the install.

 # disklabel -E /dev/rsd0c # using MBR partition 3: type A6 off 198 (0xc6) size 8302932 (0x7eb154) Treating sectors 198-8303130 as the OpenBSD portion of the disk. You can use the 'b' command to change this. Initial label editor (enter '?' for help at any prompt) > 

This should look fairly familiar from Chapter 3.

Once you're done, you can check your work by asking disklabel(8) to print out the complete label on the disk. Running disklabel with only one argument, the disk name, will print out the label currently on the disk.

 # disklabel /dev/rsd0c 

Once you're satisfied with your partitioning, you can create a file system on the new partitions.

Creating File Systems

Use newfs(8) to create file systems on each of your new OpenBSD partitions. If you're an very experienced UNIX administrator, you may wish to specify your own block and fragment sizes, and fdisk(8) describes the flags you need to use for that. (On the other hand, if you're an experienced UNIX administrator, you know better than to specify your own block and fragment sizes on most hardware most of the time.) The rest of us can just run newfs(8), telling it the device name for the partition we want to format.

 # newfs /dev/rsd0a /dev/rsd0a:     8302932 sectors in 8387 cylinders of 5 tracks, 198 sectors         4054.2MB in 525 cyl groups (16 c/g, 7.73MB/g, 1856 i/g) super-block backups (for fsck -b #) at:  32, 16080, 32128, 48176, 64224, 80272, 96320, 112368, 126752, 142800, 158848, ... 

You will see quite a few lines giving alternate superblocks for this drive, as newfs(8) crawls over the disk and prepares the file system. Once it's finished, you have a file system and the disk is ready to use.

Mounting Your New Drive

If this new disk is going to be placed on an empty mount point, just mount it! In this case, I'm using this old SCSI disk for my /usr/obj directory.

 # mount /dev/sd0 /usr/obj 

Then you just need an appropriate entry for /etc/fstab, and you're done.

Moving Data to a New Partition

If this drive is intended to hold data that is elsewhere on the drive, you'll need to move the data before mounting the drive. (Read "Stackable Mounts" later this chapter for more notes on this.) If the files are in use (e.g., log files), you'll need to boot into single-user mode to move them.

Start by mounting your new partition at a temporary location.

 # mount /dev/sd0a /mnt 

You can then use tar(1) or cpio(1) to copy the files to the temporary location. Here, I'm moving /usr/ports to the partition temporarily mounted at /mnt.

 # (cd /usr/ports && tar cf - .) | (cd /mnt && tar xpf -) 

This does not delete the files from their original location. Once you're certain that they've been copied correctly, use "rm -rf" to remove them. Once the new mount point is empty, you can unmount the drive from /mnt and mount it at its permanent home. Be sure to update /etc/fstab for the new drive.

Stackable Mounts

OpenBSD file systems are stackable, which means that you can mount one partition over another. Suppose you have followed the example above, and copied /usr/ports onto a new partition, and then mount the new partition without removing the data from the old one. The old partition will not gain any free space; the data from the old /usr/ports is still there! Because your new partition is mounted "above" the old disk you cannot access the old data, but it's still there. Unmount the new /usr/ports and remove the old /usr/ports to gain the space back.




Absolute Openbsd(c) Unix for the Practical Paranoid
Absolute OpenBSD: Unix for the Practical Paranoid
ISBN: 1886411999
EAN: 2147483647
Year: 2005
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net