Tuesday, December 24, 2019

Partitioning, Formatting, and Mounting a Hard Drive in Linux Ubuntu 18.04

I have a brand new 4-TB harddisk to add to my computer recently. So I need to mount it in Linux. To do this, I need to do the following:
A. Partitioning
B. Formatting
C. Mounting (including auto mount after reboot)
D. Checking whether the hard drive is mounted

A. Partitioning

  1. First, after connecting the harddisk to the computer by SATA and power cables, we can check the new 4-TB harddisk by:
sudo fdisk -l
/dev/sdb is the new harddisk
2. But we cannot mount it right now, if we mount it now, errors will come out. We need to partition it first:
sudo fdisk /dev/sdb
3. If we enter m for help, we can see the command list.
4. To check the partition table, enter p.
5. To partiton, enter n. I then just choose primary by entering p. And enter 1for only one partition number.
6. Enter w to write the partition table to disk.

B. Formatting

  1. Format the newly partitioned harddisk:
sudo mkfs.ext4 /dev/sdb

C. Mounting (including auto mount after reboot)

  1. Usually drive is mounted in /mnt/. Create a new directory in /mnt/ first.
sudo mkdir /mnt/sdb
2. Then we can mount it by:
sudo mount /dev/sdb /mnt/sdb
3. But we need to mount it for every time we reboot. To mount it automatically after each reboot, I use nano to modify the file /etc/fstab:
nano /etc/fstab
4. Enter following at the end of file:
/dev/sdb     /mnt/sdb      ext4        defaults      0       0
The first item is the path for the hard drive. The second one is the destination for the mounted drive, where we want to mount. The third one is the format type. The forth to sixth one I just kept as defaults, 0 and 0.
D. Checking whether the hard drive is mounted
There are 3 methods to check. Three of them can also find the mounted hard drive sdb.
  1. mount
mount | grep sdb
2. lsblk
lsblk
3. df
df

References

New disk mount to Ubuntu (2016, Simplified Chinese) 
http://huifeng.me/2016/04/19/new-disk-mount-to-Ubuntu/
What is the difference between ext3, ext4 from a generic users perspective
https://askubuntu.com/questions/44908/what-is-the-difference-between-ext3-ext4-from-a-generic-users-perspective

No comments:

Post a Comment