User Tools

Site Tools


tech:linux_server_new_drive

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tech:linux_server_new_drive [2026/09/06 10:00] – created katsimbristech:linux_server_new_drive [2026/10/01 16:33] (current) – add timeout katsimbris
Line 1: Line 1:
 ====== Adding a New Drive to the Ubuntu Server ====== ====== 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, and making the mount permanent.+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: The example below uses:
Line 186: Line 186:
  
 <code bash> <code bash>
-echo 'UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab+echo 'UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail,x-systemd.device-timeout=60 0 2' | sudo tee -a /etc/fstab
 </code> </code>
  
Line 192: Line 192:
  
 This prevents a failed, disconnected, or missing storage drive from preventing Ubuntu from booting. 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:
 +
 +<code>
 +nofail,x-systemd.device-timeout=60
 +</code>
 +
 +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: The entry follows this format:
  
 <code> <code>
-UUID=FILESYSTEM-UUID /mnt/NAME ext4 defaults,nofail 0 2+UUID=FILESYSTEM-UUID /mnt/NAME ext4 defaults,nofail,x-systemd.device-timeout=60 0 2
 </code> </code>
  
Line 202: Line 212:
  
 <code> <code>
-UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail 0 2+UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail,x-systemd.device-timeout=60 0 2
 </code> </code>
  
-===== 9. Reload systemd =====+===== 9. Reload systemd and Validate fstab =====
  
 After changing ''/etc/fstab'', run: After changing ''/etc/fstab'', run:
Line 211: Line 221:
 <code bash> <code bash>
 sudo systemctl daemon-reload sudo systemctl daemon-reload
 +</code>
 +
 +Validate the ''fstab'' configuration:
 +
 +<code bash>
 +sudo findmnt --verify --verbose
 +</code>
 +
 +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:
 +
 +<code>
 +userspace options: nofail,x-systemd.device-timeout=60
 </code> </code>
  
Line 251: Line 277:
 /mnt/media8 /dev/sdi2 ext4   rw,relatime /mnt/media8 /dev/sdi2 ext4   rw,relatime
 </code> </code>
 +
 +===== 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:
 +
 +<code>
 +[media8]
 +path = /mnt/media8
 +browseable = yes
 +read only = no
 +valid users = mike
 +force group = media
 +create mask = 0664
 +directory mask = 0775
 +</code>
 +
 +Append the new share to ''/etc/samba/smb.conf'':
 +
 +<code bash>
 +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
 +</code>
 +
 +Replace ''media8'' and ''/mnt/media8'' as needed for future drives.
 +
 +Validate the Samba configuration:
 +
 +<code bash>
 +sudo testparm
 +</code>
 +
 +A successful test should include:
 +
 +<code>
 +Loaded services file OK.
 +</code>
 +
 +The new share should also appear in the service definitions shown by ''testparm''.
 +
 +If the configuration is valid, reload Samba:
 +
 +<code bash>
 +sudo systemctl reload smbd
 +</code>
 +
 +Verify the underlying mount permissions:
 +
 +<code bash>
 +ls -ld /mnt/media8
 +</code>
 +
 +Expected ownership and permissions should look similar to:
 +
 +<code>
 +drwxrwsr-x mike media /mnt/media8
 +</code>
 +
 +The share can then be accessed from another computer using:
 +
 +<code>
 +smb://server/media8
 +</code>
 +
 +On macOS, use:
 +
 +<code>
 +Finder → Go → Connect to Server
 +</code>
 +
 +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 ===== ===== Useful Commands =====
Line 282: Line 394:
 <code bash> <code bash>
 sudo blkid /dev/sdi2 sudo blkid /dev/sdi2
 +</code>
 +
 +Check that all expected media mounts are currently mounted:
 +
 +<code bash>
 +for m in /mnt/media{1..8} /mnt/internal; do
 +  if mountpoint -q "$m"; then
 +    echo "OK      $m"
 +  else
 +    echo "MISSING $m"
 +  fi
 +done
 +</code>
 +
 +Validate ''/etc/fstab'':
 +
 +<code bash>
 +sudo findmnt --verify --verbose
 +</code>
 +
 +Validate the Samba configuration:
 +
 +<code bash>
 +sudo testparm
 +</code>
 +
 +Reload Samba after making a configuration change:
 +
 +<code bash>
 +sudo systemctl reload smbd
 </code> </code>
  
 ===== Important Notes ===== ===== Important Notes =====
  
-* Never format a drive until its identity has been confirmed using its size, model, serial number, existing filesystem, and mount status. \\ +  * 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. \\ +  * 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''. \\ +  * 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.+  * 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.
tech/linux_server_new_drive.1788703208.txt.gz · Last modified: by katsimbris