Ubuntu Server 2TB Hard Drive Partition and Format Guide
- Fact : I got a newly installed 2TB hard drive on an Ubuntu server.
- Problem : Needs to be partition and formated.
- Hypothese : Using the buildin command like fdisk and mkfs, will be set up with a single partition formatted as ext4.
Prerequisites
A 2TB hard drive installed on the Ubuntu server. Administrative (root) access or sudo privileges.
Steps
1. Identify the New Hard Drive
-
Open a terminal or SSH in your device.
-
Run the following command to list all disk devices:
lsblk -
Identify the new 2TB drive (e.g.,
/dev/sdb). It will typically show as unmounted with no partitions or look for the right size. Note the device name (e.g.,/dev/sdb).Caution: Double-check the device name to avoid accidentally modifying the wrong drive.
2. Partition the Drive
-
Start the
fdiskutility for the new drive (replace/dev/sdbwith your drive’s device name):sudo fdisk /dev/sdb -
At the
fdiskprompt, type the following commands:gto create a new GPT partition table (suitable for 2TB drives).nto create a new partition.- Press
Enterto accept the default partition number (1). - Press
Enterto accept the default first sector. - Press
Enterto accept the default last sector (uses the entire drive).
- Press
wto write the changes and exit. (It might say : The partition table has been altered)
-
Verify the new partition:
lsblkYou should see a new partition (e.g.,
/dev/sdb1).
3. Format the Partition
- Format the new partition as ext4 (replace
/dev/sdb1with your partition’s name):sudo mkfs.ext4 /dev/sdb1 - Wait for the formatting to complete (this may take a few minutes).
4. Mount the Drive
- Create a mount point (e.g.,
/mnt/newdrive):sudo mkdir /mnt/newdrive - Mount the formatted partition:
sudo mount /dev/sdb1 /mnt/newdrive - Verify the drive is mounted:
You should see the new drive listed with its mount point.
df -h
5. Configure Automatic Mounting
To ensure the drive mounts automatically on boot:
- Find the UUID of the new partition:
Note the UUID for
sudo blkid /dev/sdb1/dev/sdb1(e.g.,1234-5678-9012-3456). - Edit the
/etc/fstabfile:sudo nano /etc/fstab - Add the following line at the end of the file (replace
UUIDwith your partition’s UUID):/dev/disk/by-uuid/1234-5678-9012-3456 /mnt/newdrive ext4 defaults 0 2 - Save and exit (
Ctrl+O,Enter,Ctrl+X). - Test the
fstabconfiguration:If no errors appear, the configuration is correct.sudo mount -a
6. Set Permissions (Optional)
To allow a specific user or group to access the drive:
- Change ownership (replace
usernamewith the desired user):sudo chown -R username:username /mnt/newdrive - Adjust permissions as needed:
sudo chmod -R 755 /mnt/newdrive
Verification
- Check the drive’s status:
lsblk
df -h - Ensure you can read/write to the mount point:
touch /mnt/newdrive/testfile
ls /mnt/newdrive