Mounting a hard drive in Ubuntu Server involves several steps, including identifying the drive, creating a mount point, and updating the filesystem table to ensure the drive mounts automatically at boot. Here’s a step-by-step guide:
- List all drives: Run the following command to list all connected drives:
sudo fdisk -l
or
lsblk
This will show a list of all block devices. Identify your new hard drive (e.g., /dev/sdb
).
If your hard drive is new and unpartitioned, you'll need to create a partition on it:
Run fdisk
:
sudo fdisk /dev/sdb
Replace /dev/sdb
with the correct drive identifier.
Inside fdisk
:
- Press
n
to create a new partition. - Follow the prompts to create a primary partition.
- Press
w
to write the changes and exit.
Format the partition with the desired filesystem, for example, ext4
:
sudo mkfs.ext4 /dev/sdb1
Replace /dev/sdb1
with the correct partition identifier.
Choose or create a directory where you want to mount the hard drive. For example, to create a mount point in /mnt/storage
:
sudo mkdir -p /mnt/storage
Mount the drive to the created mount point:
sudo mount /dev/sdb1 /mnt/storage
Replace /dev/sdb1
and /mnt/storage
with your actual partition and mount point.
To ensure the drive mounts automatically on boot, you need to update the /etc/fstab
file:
- Open
/etc/fstab
in a text editor:
sudo nano /etc/fstab
- Add a new entry: Add the following line to the end of the file:
/dev/sdb1 /mnt/storage ext4 defaults 0 2
- Save and Exit.
You can verify the mount by unmounting and remounting using fstab
:
- Unmount the drive
sudo umount /mnt/storage
sudo systemctl daemon-reload
- Mount all filesystems in
fstab
:
sudo mount -a
- Check the mount:
df -h
This should display your newly mounted hard drive under /mnt/storage
.
These steps outline the process of identifying, partitioning, formatting, creating a mount point, mounting, and configuring the hard drive to mount automatically on an Ubuntu Server. Adjust the commands to fit your specific drive identifiers and desired mount points.