Mounting and Unmounting Partitions

To attach filesystems to your directory tree, or mount them, use mount(8). If you’ve never manually mounted filesystems before, boot your OpenBSD machine into single-user mode (see Chapter 5) and follow along.

In single-user mode, OpenBSD mounts only one partition: the root partition, which it mounts read-only. The root partition contains just enough of the system to perform basic setup, establish core services, and find the other filesystems.

Because filesystems other than the root are not mounted, their content is not accessible. Look in, say, /usr on a system in single-user mode, and you’ll find that it’s empty. OpenBSD hasn’t lost the files; it just hasn’t mounted the partition containing those files.

To get any real work done in single-user mode, you probably need to mount other filesystems.

Mounting Standard Filesystems

To manually mount a single filesystem listed in /etc/fstab, give mount(8) the name of the filesystem you want to mount. Here, we’ll mount our /usr partition:

# mount /usr

This mounts the partition exactly as described in /etc/fstab, with all the options specified therein.

To mount all of the partitions listed in /etc/fstab, give mount the -a flag:

# mount -a

All of your filesystems (except those not listed in /etc/fstab and those with the noauto option) should now be mounted.

Mounting at Nonstandard Locations

Perhaps you must mount a filesystem at a location not specified in /etc/fstab. I do this most commonly when adding a disk to a machine. To mount a partition at a location other than that specified in /etc/fstab, or to mount a partition without an /etc/fstab entry, give the partition device name and the mount point.

# mount /dev/sd0d /mnt

You must use the full path for the device node, not just the brief device node name.

Instead of the path to the device node, you could use the DUID, a period, and the partition letter, but on the command line, that’s more painful than using the path to the device node.

Unmounting Partitions

To disconnect a filesystem from the directory tree, use umount(8) on a mount point. (Note that there is only one n in this command.) Here, we’ll use umount to unmount our /usr partition:

# umount /usr

You cannot unmount filesystems that are in use by any program. Even a command prompt in the mounted directory will prevent you from unmounting the partition.

To unmount all partitions except the root partition, pass umount the -a flag:

# umount -a

As programs almost certainly have files open on every partition, this probably works only in single-user mode. Note that you don’t need to unmount all partitions to leave single-user mode.

Mounting with Options

Suppose you pull a disk from a decommissioned OpenBSD machine and you need to retrieve some files from it. You want to mount the disk read-only so that you don’t change any of the files on the disk. To manually mount a partition with options not specified in /etc/fstab, use the -o flag.

For example, if the disk shows up as /dev/sd0 and you want to mount partition a, run this command:

# mount -o ro /dev/sd0a /mnt

To prevent old software from running on your newer system, it might be a good idea to use some of the options we covered earlier, such as noexec, nodev, and nosuid.

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

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