Mount and Share an external disk drive in Linux Ubuntu
Let's see how to mount and share an external disk drive in Linux Ubuntu, so we can use it as a NAS
Replace /dev/sdX1 with your device (e.g., /dev/sdb1).
Plug in the disk.
Just connect the drive via USB. Linux will expose it as a block device under
/dev(e.g.,/dev/sdb). “Block” means data is read/written in fixed‑size blocks.
Run the following command to see the disks & filesystems.
sudo lsblk -fRun the following command to create a mount point.
sudo mkdir -p /mnt/externalYou can also add support for NTFS and exFAT by running the following commands
sudo apt update && sudo apt install -y ntfs-3g exfat-fuse exfatprogsNow, let's mount the disk to the mounting point that we created in step 3
If your partition is in ext4 format:
sudo mount /dev/sdX1 /mnt/externalIf your partition is in ntfs format:
sudo mount -t ntfs-3g -o uid=$(id -u),gid=$(id -g) /dev/sdX1 /mnt/externalIf your partition is in exfat format:
udo mount -t exfat -o uid=$(id -u),gid=$(id -g) /dev/sdX1 /mnt/externalVerify the mount with diskfree command
df -h | grep /mnt/externalNow we need to auto-mount the external disks so we don't have to mount the disk every time. In order to do that, let's get the UUID first with the following command
sudo blkid /dev/sdX1 Open the /etc/fstab with Nano and add a line at the bottom, replace the UUID we got from step 7
sudo nano /etc/fstabIf your partition is in ext4 format:
UUID=YOUR-UUID /mnt/external ext4 defaults 0 2If your partition is in ntfs format:
UUID=YOUR-UUID /mnt/external ntfs-3g defaults,uid=1000,gid=1000,umask=022 0 0If your partition is in exfat format:
UUID=YOUR-UUID /mnt/external exfat defaults,uid=1000,gid=1000,umask=022 0 0Let's mount all filesystems mentioned in fstab to ensure our configuration is correct. You should see no error after running the following command.
sudo mount -aShare the Disk over the Network (Samba)
We need to install Samba first. Samba implements Microsoft’s SMB/CIFS protocol
sudo apt install -y sambaEnsure you own the mount path
sudo chown -R $USER:$USER /mnt/externalCreate a share
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bakprintf "\n[external]\n path = /mnt/external\n browseable = yes\n read only = no\n create mask = 0644\n directory mask = 0755\n" | sudo tee -a /etc/samba/smb.confAdd a Samba password for your user
sudo smbpasswd -a $USERRestart service & open firewall
sudo systemctl restart smbdsudo ufw allow 'Samba' # if UFW is enabled