User Tools

Site Tools


tech:linux_server_new_drive

This is an old revision of the document!


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.

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 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.

The entry follows this format:

UUID=FILESYSTEM-UUID /mnt/NAME ext4 defaults,nofail 0 2

Example:

UUID=a28ee7c4-9f5a-468a-a7aa-c82acdb2c798 /mnt/media8 ext4 defaults,nofail 0 2

9. Reload systemd

After changing /etc/fstab, run:

sudo systemctl daemon-reload

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

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

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.

tech/linux_server_new_drive.1788703208.txt.gz · Last modified: by katsimbris