====== Adding a New Drive to the Ubuntu Server ====== This process is for adding a new storage drive to the Ubuntu server, formatting it as ''ext4'', mounting it under ''/mnt'', setting the correct permissions, making the mount permanent, and optionally sharing it over SMB. The example below uses: Drive: /dev/sdi Partition: /dev/sdi2 Mount name: media8 Mount point: /mnt/media8 Replace those values as needed for future drives. ===== 1. Identify the New Drive ===== After connecting the drive, run: lsblk -o NAME,SIZE,MODEL,SERIAL,FSTYPE,LABEL,UUID,MOUNTPOINTS Look for the new drive by its size, model, serial number, label, or the fact that it is not currently mounted. Example: sdi 3.6T PSSD L98420 ├─sdi1 │ 16M └─sdi2 3.6T exfat T7 4095-6F3B In this example: Disk: /dev/sdi Partition: /dev/sdi2 **Be certain that the correct drive has been identified before formatting it.** ===== 2. Format the Partition as ext4 ===== Formatting will erase the existing filesystem and all data on the partition. For a permanent Linux server drive, use ''ext4'': sudo mkfs.ext4 -L media8 /dev/sdi2 If the drive already contains another filesystem, such as exFAT, Ubuntu may ask: Proceed anyway? (y,N) Answer ''y'' only after confirming that the correct drive is being formatted. The formatting process will create a new filesystem UUID. ===== 3. Create the Mount Point ===== Create the directory where the drive will be mounted: sudo mkdir -p /mnt/media8 The naming convention for storage drives is: /mnt/media1 /mnt/media2 /mnt/media3 ... /mnt/media8 ===== 4. Get the New Filesystem UUID ===== After formatting, run: sudo blkid /dev/sdi2 Example: /dev/sdi2: LABEL="media8" UUID="a28ee7c4-9f5a-468a-a7aa-c82acdb2c798" TYPE="ext4" Use the filesystem ''UUID'', not the ''PARTUUID''. Formatting changes the filesystem UUID, so do not reuse the UUID that existed before formatting. ===== 5. Mount the Drive Temporarily ===== Mount the partition manually: sudo mount /dev/sdi2 /mnt/media8 Verify that it mounted: df -h /mnt/media8 Example: Filesystem Size Used Avail Use% Mounted on /dev/sdi2 3.6T 2.1M 3.4T 1% /mnt/media8 ===== 6. Set Ownership and Permissions ===== The server's shared media drives use: Owner: mike Group: media Set ownership: sudo chown mike:media /mnt/media8 Set permissions: sudo chmod 2775 /mnt/media8 The leading ''2'' sets the setgid bit. This causes newly created files and directories to inherit the ''media'' group. Verify: ls -ld /mnt/media8 Expected permissions should look similar to: drwxrwsr-x mike media /mnt/media8 ===== 7. Create Media Folders ===== Create whatever folders will live on the drive. Example: mkdir "/mnt/media8/TV Torrents" Verify: ls -ld "/mnt/media8/TV Torrents" It should also belong to: mike media and normally inherit the setgid permissions. ===== 8. Add the Drive to /etc/fstab ===== Use the filesystem UUID so the drive mounts consistently even if its ''/dev/sdX'' device name changes. Example: echo 'UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail,x-systemd.device-timeout=60 0 2' | sudo tee -a /etc/fstab **Important:** ''nofail'' is intentionally included on media/data drives. This prevents a failed, disconnected, or missing storage drive from preventing Ubuntu from booting. ''x-systemd.device-timeout=60'' tells systemd to wait up to 60 seconds for the drive to become available during boot. This is useful for external USB storage, because some drives may take longer to initialize when several drives are connected. The combination: nofail,x-systemd.device-timeout=60 means that Ubuntu will give the drive up to 60 seconds to appear, but will still continue booting if the drive is missing or unavailable. The entry follows this format: UUID=FILESYSTEM-UUID /mnt/NAME ext4 defaults,nofail,x-systemd.device-timeout=60 0 2 Example: UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail,x-systemd.device-timeout=60 0 2 ===== 9. Reload systemd and Validate fstab ===== After changing ''/etc/fstab'', run: sudo systemctl daemon-reload Validate the ''fstab'' configuration: sudo findmnt --verify --verbose The important result is that there are no parse errors or errors. Warnings may still appear for certain filesystem types or the swap file and do not necessarily indicate an invalid ''fstab'' entry. For a media drive using the recommended settings, ''findmnt'' should show: userspace options: nofail,x-systemd.device-timeout=60 ===== 10. Test the Permanent Mount ===== Unmount the drive: sudo umount /mnt/media8 Then mount everything listed in ''/etc/fstab'': sudo mount -a If no errors appear, verify the drive: findmnt /mnt/media8 Check space: df -h /mnt/media8 Check the media folder: ls -ld "/mnt/media8/TV Torrents" Example successful result: TARGET SOURCE FSTYPE OPTIONS /mnt/media8 /dev/sdi2 ext4 rw,relatime ===== 11. Add the Drive as an SMB Share ===== If the new drive should be accessible over the network, add it to Samba. The media shares on this server use the following configuration: [media8] path = /mnt/media8 browseable = yes read only = no valid users = mike force group = media create mask = 0664 directory mask = 0775 Append the new share to ''/etc/samba/smb.conf'': sudo tee -a /etc/samba/smb.conf >/dev/null <<'EOF' [media8] path = /mnt/media8 browseable = yes read only = no valid users = mike force group = media create mask = 0664 directory mask = 0775 EOF Replace ''media8'' and ''/mnt/media8'' as needed for future drives. Validate the Samba configuration: sudo testparm A successful test should include: Loaded services file OK. The new share should also appear in the service definitions shown by ''testparm''. If the configuration is valid, reload Samba: sudo systemctl reload smbd Verify the underlying mount permissions: ls -ld /mnt/media8 Expected ownership and permissions should look similar to: drwxrwsr-x mike media /mnt/media8 The share can then be accessed from another computer using: smb://server/media8 On macOS, use: Finder → Go → Connect to Server The Samba settings work together with the filesystem permissions: * ''valid users = mike'' restricts access to the Samba user ''mike''. * ''force group = media'' causes files created through Samba to use the ''media'' group. * ''create mask = 0664'' allows the owner and group to write newly created files. * ''directory mask = 0775'' allows the owner and group to write newly created directories. * The setgid permission from ''chmod 2775'' helps newly created directories inherit the ''media'' group. ===== Useful Commands ===== Show all drives, filesystems, UUIDs, and mount points: lsblk -o NAME,SIZE,MODEL,SERIAL,FSTYPE,LABEL,UUID,MOUNTPOINTS Show mounted-drive disk usage: df -h --output=source,size,used,avail,pcent,target Show only ''/mnt'' storage: df -h --output=source,size,used,avail,pcent,target | grep -E 'Filesystem|/mnt/' Show information about one mount: findmnt /mnt/media8 Show a filesystem UUID: sudo blkid /dev/sdi2 Check that all expected media mounts are currently mounted: for m in /mnt/media{1..8} /mnt/internal; do if mountpoint -q "$m"; then echo "OK $m" else echo "MISSING $m" fi done Validate ''/etc/fstab'': sudo findmnt --verify --verbose Validate the Samba configuration: sudo testparm Reload Samba after making a configuration change: sudo systemctl reload smbd ===== Important Notes ===== * Never format a drive until its identity has been confirmed using its size, model, serial number, existing filesystem, and mount status. * Do not rely on names such as ''/dev/sdi'' remaining permanent. Linux device letters can change between boots or when USB drives are connected in a different order. * Permanent mounts should therefore use filesystem UUIDs in ''/etc/fstab''. * All external/data-drive mounts on this server should use ''nofail'' so that a missing storage drive cannot prevent the server from booting. * External/media drives should use ''x-systemd.device-timeout=60'' so that slower USB drives have enough time to become available during startup. * The recommended combination for media drives is ''nofail,x-systemd.device-timeout=60''. * SMB shares should be validated with ''sudo testparm'' before reloading Samba.