Introduction
Disk and file system issues can be critical in FreeBSD systems. This guide will help you troubleshoot common problems related to disks, partitions, and file systems in FreeBSD environments.
1. Checking Disk Status
1.1 Viewing Disk Information
Use the following commands to view disk information:
# List all disks
$ geom disk list
# Show detailed SMART information for a specific disk
$ smartctl -a /dev/ada0
1.2 Checking Disk Usage
To check disk usage and available space:
# Show file system disk space usage
$ df -h
# Display disk usage for a specific directory
$ du -sh /path/to/directory
2. File System Checks and Repairs
2.1 Running fsck
Use fsck to check and repair file systems:
# Check UFS file system
$ fsck -y /dev/ada0p2
# Check ZFS file system
$ zfs scrub zroot
Warning: Always unmount the file system before running fsck, except for the root file system which should be checked in single-user mode.
2.2 Mounting and Unmounting File Systems
To mount or unmount file systems:
# Mount a file system
$ mount /dev/ada0p2 /mnt
# Unmount a file system
$ umount /mnt
3. Dealing with Bad Sectors
If you suspect bad sectors on your disk:
- Use badblocks to check for bad sectors:
$ badblocks -sv /dev/ada0
- If bad sectors are found, consider replacing the disk as soon as possible.
- For temporary measures, you can mark bad sectors:
$ fsck -c /dev/ada0p2
4. ZFS-specific Troubleshooting
4.1 Checking ZFS Pool Status
# View ZFS pool status
$ zpool status
# Check ZFS pool health
$ zpool list
4.2 Repairing ZFS Issues
To repair ZFS issues:
# Clear ZFS errors
$ zpool clear poolname
# Attempt to repair ZFS pool
$ zpool repair poolname
5. Recovering Deleted Files
If you accidentally delete files:
- Immediately unmount the file system if possible.
- Use a tool like 'testdisk' or 'photorec' for file recovery:
$ testdisk /dev/ada0
- For ZFS, you might be able to recover from snapshots if enabled:
$ zfs list -t snapshot
6. Disk Replacement Procedure
- Identify the failing disk using the methods in section 1.
- If using ZFS, replace the disk:
$ zpool replace zroot old_disk new_disk
- For UFS, create a new partition table and file systems on the new disk, then restore from backup.