Adding New Hard Disks

The OpenBSD installer walks you through formatting and partitioning your initial hard disks. If you need to add a disk to an existing system, however, you must run these commands yourself. The good news is that if you can install OpenBSD, you already know how to use the commands, and the only hard part is learning which commands to run.

I’ll show you how to move /home to a new disk as an example. You could create a new partition on your existing disk if you have some empty space, but that would eliminate the need for this example, so I’m going to pretend I never gave you that advice. (Also, moving partitions to a separate disk controller channel will improve performance.)

Warning

Before touching anything involving disk partitioning or filesystems, back up your system. Verify that backup before starting. You have been warned.

Creating an MBR Partition

The i386 and amd64 platforms require disks to have MBR partitions as well as OpenBSD partitions. A standard new disk needs a single OpenBSD MBR partition covering the entire disk. Passing the -i argument to fdisk does exactly this. Let’s create a new MBR partition on wd1, our new disk:

# fdisk -i wd1
Do you wish to write new MBR and partition table? [n] y
Writing MBR at offset 0.

Once you have an MBR partition on your disk, you can create disklabel partitions.

Creating a Disklabel

All OpenBSD platforms use disklabel partitions. To activate the same disklabel editor we used during the install process, give disklabel the -E flag and the disk name:

# disklabel -E wd1

This should look familiar from earlier in this chapter. Use the interactive disklabel editor to create your new partitions. For a single /home directory, we’ll use one large partition, wd1a. The new label should look like this:

#                size           offset  fstype [fsize bsize  cpg]
  a:         33543648               64  4.2BSD   2048 16384    1
  c:         33554304                0  unused

When you’ve finished editing partitions, check your work by printing the disklabel. This should also give you the DUID of the new disk.

When you’re satisfied with the partitioning, use newfs to create a filesystem on the new partition:

# newfs wd1a

You’re now ready to add the filesystem to your computer.

Moving Partitions

Moving data from one disk to another is slightly more complex than adding new partitions. You must first mount the new drive in a temporary location, copy files to that location, remove them from the old location, and mount the new drive in its previous home.

Our new /home filesystem is on disk partition wd1a. The default “temporary mount” location is /mnt, so mount it there. This is strictly temporary, so there’s no need to mount it via the DUID or make an /etc/fstab entry for this.

# mount wd1a /mnt

You can then use tar(1), cpio(1), or dump(8) and restore(8) to copy the files to the temporary location. Here, we copy everything in /home to /mnt.

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

You could also use cp(1) or mv(1) for this, but these commands don’t guarantee that file permissions and ownership will copy intact. OpenBSD’s versions of these programs have never given me errors when I copy or move files, but I’ve learned from other Unix-like operating systems that tar and cpio are both more reliable when moving entire file hierarchies. If you’re using file flags for security (see Chapter 10), you must use dump(8) and restore(8) to retain those flags.

Using tar or cpio does not delete files from their original location. This means that if a user changes files in his home directory after you copy them but before you change the mount point, he will lose his changes as you shuffle disks around.[20]

Now update /etc/fstab to reflect your new disk.

Adding New Filesystems

Look at the disklabel for the new disk and get the disk’s DUID. This new disk has a DUID of fea9194ee78362d8. Use the DUID and the partition letter to make an /etc/fstab entry for your new partitions.

fea9194ee78362d8.a /home ffs rw,nodev,nosuid,softdep 1 2

You might want to keep the old partition available at a new location, such as /oldhome.

If you’re not sure about the mount options to use for your new partitions, the options nodev, nosuid, and softdep are generally safe. You probably want the partition mounted read-write (rw) as well.

Now unmount the old and mount the new.

# umount /home
# mount /oldhome
# mount /home

When you unmount a partition, umount doesn’t check /etc/fstab. You tell it to unmount a partition, and it unmounts that partition.

Stackable Mounts

OpenBSD filesystems are stackable, which means that you can mount one partition over another. The partition on top hides any files in the filesystem below.

Look at your system in single-user mode. By default, only the root partition is mounted. You can go look in the /home directory, and it will be empty. There’s no reason you can’t put files in the /home directory, even when /home isn’t mounted. Suppose you copy a couple of core files into /home while in single-user mode, and then go into multiuser mode. All the usual partitions are mounted. If you then look in /home, you won’t find your core files.

What happened? Where did those files go?

The files are in the directory /home, but on the root partition. The /home partition is mounted above that directory, so the /home partition obscures the files in the /home directory on the root partition. To access those hidden files, you must unmount the /home partition. Those hidden files continue to take up space on the root partition, however.

This happens more commonly when splitting a partition. For example, if you find that your /var partition is too small, you might move /var/www into its own partition on a separate disk. To free up space on the original /var, delete the files you copied to /var/www.

With the basics of filesystem management under your belt, you’re now ready to look at some of OpenBSD’s more interesting filesystem tricks.



[17] If it’s buffered aspirin, then you’re doing buffered buffered aspirin transfers. But let’s not go there.

[18] OpenBSD is not the only operating system that still uses the BSD 4.4 filesystem or a descendant thereof. If a Unix vendor doesn’t specifically tout its “improved and advanced” filesystem, it’s almost certainly running a derivative of FFS.

[19] Hi, Henning!

[20] Presumably you warn your users before doing maintenance. Or at least during maintenance. Or … maybe afterward.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.100.89