Topic 712: Storage Devices and BSD Filesystems
This topic covers partitioning and disk labels, creating and maintaining file systems, mounting and unmounting, managing file permissions, using links, and finding files. Understanding these fundamentals is crucial for effective BSD system administration.
712.1: BSD Partitioning and Disk Labels
-
fdisk
manages MBR (legacy). -
disklabel
(orbsdlabel
) manages BSD labels. -
GPT-based systems often use
gpart
(FreeBSD).
gpart show # Show partitions
disklabel -E sd0 # OpenBSD: edit disklabel on sd0
installboot # Install bootstrap on a disk
Note on partition types
- MBR (Master Boot Record): Traditional partitioning, often limited to 4 primary partitions.
- GPT (GUID Partition Table): Modern scheme with a larger partition limit and better data redundancy.
- BSD label: Overlay inside one of these partitions to carve out additional BSD-specific partitions.
712.2: Create File Systems and Maintain Their Integrity
UFS Examples
newfs /dev/ada0p2 # Create UFS on FreeBSD
fsck -y /dev/ada0p2 # Check and repair
df -h # Disk usage
du -sh /home # Show usage of /home
ZFS Examples (FreeBSD, NetBSD)
zpool create mypool /dev/ada1 # Create ZFS pool
zpool status # Check pool status
zfs snapshot mypool/usr@backup # Create snapshot
Tip: ZFS on NetBSD
NetBSD supports ZFS but might require additional configuration or kernel options depending on release. Always consult official documentation for compatibility.
712.3: Control Mounting and Unmounting of File Systems
-
View all currently mounted filesystems:
mount
-
Mount UFS:
mount -t ufs /dev/ada0p2 /mnt
-
Unmount:
umount /mnt
-
/etc/fstab
example:/dev/ada0p2 /usr ufs rw 2 2
ZFS Mounts
zfs mount mypool/usr # Mount a ZFS filesystem
zfs unmount mypool/usr # Unmount a ZFS filesystem
Note on mount options
-
Common flags include
rw
(read-write),ro
(read-only), and others likenoexec
,nodev
, etc. -
Some BSD flavors might have slight variations in how UFS is referenced (e.g.,
ufs
,ffs
).
712.4: Manage File Permissions and Ownership
-
View permissions:
ls -l file.txt
-
Change permissions (symbolic):
chmod u+x file.txt
-
Change permissions (octal):
chmod 755 file.txt
-
Change owner/group:
chown user file.txt chgrp group file.txt
-
umask
:umask 022
SUID, SGID, and sticky bit
-
SUID:
chmod u+s file
executes with the owner’s privileges. -
SGID:
chmod g+s dir
can affect group permissions on directories. -
Sticky Bit:
chmod +t dir
used on/tmp
to prevent users from deleting each other’s files.
712.5: Create and Change Hard and Symbolic Links
-
Hard link:
ln original.txt hardlink.txt
-
Symbolic link:
ln -s original.txt symlink.txt
-
Remove link:
rm symlink.txt
Hard vs. soft links
- Hard link: Points to the same inode as the original file. Not valid across different filesystems or for directories (on most BSDs).
- Symbolic (soft) link: References a path. Can cross filesystems but breaks if the target is moved.
712.6: Find Files and BSD Directory Layout
find / -name httpd.conf
find /var/log -type f -size +10M
find /home -mtime -1
locate config.php
locate.updatedb
whereis python
which sshd
-
hier(7)
: The manual page for the BSD filesystem hierarchy (e.g.,/bin
,/usr
,/usr/local
, etc.).
Tips on searching
-
find /path -exec command {} \;
can run commands on found items. -
-ls
prints detailed attributes for each found file. -
locate
relies on a periodically updated database, so runlocate.updatedb
if needed.