scripts/config.drives.homelab.md
2025-05-05 11:58:47 -06:00

283 lines
8.1 KiB
Markdown

This guide will walk you through the process of setting up your drives to automatically mount when your Ubuntu system boots up.
>[!note] Use a LLM
>Drive set up is something that can be easily walked through and automated with the help of a LLM. We used Claude 3.7 Sonnet to set our drives and write this manual.
In the following are system specific instructions for the bnk homelab and generic instructions for any other system.
## Generic Instructions
- An Ubuntu system (this guide uses Ubuntu 24.04)
- Administrator (sudo) privileges
- Basic terminal knowledge
- The drives you want to mount
### Step 1: Identify Your Drives
First, you need to identify the drives you want to mount. There are two ways to do this:
#### Option A: Use the GUI Disk Utility (Easiest for Beginners)
1. Open the "Disks" application from your applications menu
2. Click on each disk on the left sidebar to view its details
3. Note down the following information for each drive:
- Device path (e.g., `/dev/sda`, `/dev/nvme0n1`)
- UUID (a long string like `96ebca52-2696-4e79-bbf9-69a596f3be2d`)
- File system type (usually ext4, ntfs, or fat32)
#### Option B: Use Terminal Commands
If you prefer using the terminal:
```bash
# List all block devices
sudo lsblk -f
# Get more detailed information
sudo blkid
```
Write down the UUID, device name, and filesystem type for each drive you want to mount.
### Step 2: Create Mount Points
Mount points are directories where your drives will be accessible. You need to create these directories:
```bash
# Create mount points (adjust names as desired)
sudo mkdir -p /mnt/drive1 /mnt/drive2 /mnt/drive3
```
Choose meaningful names for your mount points that help you remember what's on each drive.
### Step 3: Backup Your Current fstab File
The `/etc/fstab` file controls how drives are mounted at boot. Always backup this file before editing:
```bash
sudo cp /etc/fstab /etc/fstab.backup
```
### Step 4: Edit the fstab File
Now you'll add entries for your drives:
```bash
sudo nano /etc/fstab
```
Add a line for each drive using this format:
```
UUID=your-drive-uuid /mnt/your-mount-point filesystem-type mount-options 0 2
```
Example:
```
# 2TB Storage Drive
UUID=1c51b55f-c89a-417e-bcc3-eb5f29caa92c /mnt/storage2tb ext4 defaults 0 2
```
Here's what each field means:
- **UUID**: The unique identifier for your drive
- **Mount point**: The directory where you want to access the drive
- **Filesystem type**: Usually ext4 for Linux drives, ntfs for Windows drives
- **Mount options**: "defaults" works for most situations
- **Dump**: Set to 0 (backup utility flag, rarely used)
- **Pass**: Set to 2 for non-system drives (controls fsck order)
For external drives that may not always be connected, add `nofail` to the options:
```
UUID=abcd1234-5678-90ef /mnt/external ext4 defaults,nofail 0 2
```
Save the file by pressing Ctrl+O, then Enter, then exit with Ctrl+X.
### Step 5: Test Your Configuration
Test that your configuration works without rebooting:
```bash
# Reload systemd to recognize the new fstab entries
sudo systemctl daemon-reload
# Try mounting all entries in fstab
sudo mount -a
```
If there are no error messages, your configuration is correct.
### Step 6: Verify the Drives are Mounted
Check that your drives are properly mounted:
```bash
df -h
```
You should see all your drives listed with their mount points.
### Step 7: Set Appropriate Permissions (Optional)
If you want to make the drives writable for your user:
```bash
# Replace username with your username and /mnt/drivename with your mount point
sudo chown -R username:username /mnt/drivename
```
### Troubleshooting
#### Drive Not Mounting
If a drive doesn't mount with `mount -a`:
1. Check for syntax errors in fstab:
```bash
sudo cat /etc/fstab
```
2. Verify the UUID is correct:
```bash
sudo blkid
```
3. Verify the filesystem type:
```bash
sudo lsblk -f
```
#### Restore Backup If Needed
If you've made a mistake and can't boot properly:
1. Boot into recovery mode (hold Shift during boot)
2. Mount the filesystem as read-write:
```bash
mount -o remount,rw /
```
3. Restore your backup:
```bash
cp /etc/fstab.backup /etc/fstab
```
### Common Mount Options
- **defaults**: Standard options (rw, suid, dev, exec, auto, nouser, async)
- **noauto**: Don't mount at boot (must be mounted manually)
- **nofail**: Don't report errors if the device doesn't exist
- **ro**: Mount read-only
- **rw**: Mount read-write
- **user**: Allow non-root users to mount
- **exec/noexec**: Allow/prevent execution of binaries on the filesystem
### Example fstab File
```
# /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=96ebca52-2696-4e79-bbf9-69a596f3be2d /mnt/samsung500 ext4 defaults 0 2
UUID=1c51b55f-c89a-417e-bcc3-eb5f29caa92c /mnt/storage2tb ext4 defaults 0 2
UUID=510f0afc-1dae-4da5-969e-2b9f31c72498 /mnt/storage4tb ext4 defaults 0 2
UUID=ABCD-EF12 /mnt/usb-drive vfat defaults,nofail 0 2
```
### Congratulations!
Your drives are now set up to mount automatically every time you boot your Ubuntu system. You can access your files through the mount points you created.
## System Specific Configuration
This is a step-by-step summary of the exact process we followed to configure automatic mounting for the four drives on this specific Ubuntu 24.04 system:
### Drive Details
- 500GB Samsung SSD 970 EVO Plus (`/dev/nvme0n1p1`, UUID: `96ebca52-2696-4e79-bbf9-69a596f3be2d`)
- 2.0TB Seagate Hard Disk (`/dev/sda1`, UUID: `1c51b55f-c89a-417e-bcc3-eb5f29caa92c`)
- 4.0TB Seagate Hard Disk (`/dev/sdb1`, UUID: `510f0afc-1dae-4da5-969e-2b9f31c72498`)
### Step-by-Step Instructions
1. **Backup the fstab file**
```
sudo cp /etc/fstab /etc/fstab.backup
```
2. **Edit the fstab file**
```
sudo nano /etc/fstab
```
3. **Add the following lines to the end of the file**
```
# 500GB Samsung SSD
UUID=96ebca52-2696-4e79-bbf9-69a596f3be2d /mnt/samsung500 ext4 defaults 0 2
# 2.0TB Hard Drive
UUID=1c51b55f-c89a-417e-bcc3-eb5f29caa92c /mnt/storage2tb ext4 defaults 0 2
# 4.0TB Hard Drive
UUID=510f0afc-1dae-4da5-969e-2b9f31c72498 /mnt/storage4tb ext4 defaults 0 2
```
4. **Create the mount point directories**
```
sudo mkdir -p /mnt/samsung500 /mnt/storage2tb /mnt/storage4tb
```
5. **Reload systemd configuration to recognize the changes**
```
systemctl daemon-reload
```
6. **Mount all drives according to fstab**
```
sudo mount -a
```
7. **Verify that all drives are properly mounted**
```
df -h
```
### Confirmation
The successful output from `df -h` showed:
```
/dev/nvme0n1p1 458G 28K 435G 1% /mnt/samsung500
/dev/sda1 1.8T 533G 1.2T 31% /mnt/storage2tb
/dev/sdb1 3.6T 2.6M 3.4T 1% /mnt/storage4tb
```
This confirms that all three drives are mounted correctly with the expected space available.
### What This Accomplishes
- All three drives will now automatically mount at the same locations when the system boots
- The drives are mounted with standard read/write permissions
- The system will check these filesystems for errors during boot (but after the root filesystem)
### If You Need to Make Changes Later
To modify mount points or options:
1. Edit the fstab file again: `sudo nano /etc/fstab`
2. Make your changes
3. Run `sudo systemctl daemon-reload`
4. Test with `sudo mount -a`
### Recovery Option
If anything goes wrong and the system won't boot properly after these changes:
1. Boot into recovery mode (hold Shift during boot)
2. Restore the backup: `cp /etc/fstab.backup /etc/fstab`
3. Reboot normally
### Plex Media Permissions
For fresh installs, we need to set permissions for drives for plex:
```
# Make the storage4tb directory accessible to the bunker-admin group
sudo chmod 770 /mnt/storage4tb
# Restart Plex service
sudo systemctl restart plexmediaserver
# Test access again
sudo -u plex ls -la /mnt/storage4tb/mediastack/media
```