Partitioning, Formatting, and Mounting a Hard Drive in Linux Ubuntu 18.04 (2020)
I have a brand new 4-TB harddisk to add to my computer recently. So I need to mount it in Linux. (Sik-Ho Tsang @ Medium)
To do this, I need to do the following:
- A. Partitioning Using Parted (for > 2GB Harddisk) (New) (Updated on 18 Jan 2020)
- B. Formatting
- C. Mounting (including auto mount after reboot)
- D. Checking whether the hard drive is mounted
- E. Unmounting (Updated on 05 May 2020)
- F. Partitioning Using fdisk (for < 2GB Harddisk) (Old)
To partition a Harddisk larger than 2GB, GPT is needed, A > B > C > D.
To partition a Harddisk smaller than 2GB, fdisk already can help, E > B > C > D.
A. Partitioning (for >2GB Harddisk) (New) (Updated on 18 Jan 2020)
- 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
Note: You may have a different name other than sdb!!! The name sdb needs to be changed in the following steps!!!
2. But we cannot mount it right now, if we mount it now, errors will come out. We need to partition it first, we use parted to partition:
sudo parted /dev/sdb
3. Within the parted, type the following to have gpt partition, gpt can allow partition larger than 2GB:
mklabel gpt
4. Set the size for partition, I here partition from 0GB to 4GB:
mkpart primary 0GB 4GB
5. Then quit the parted:
quit
B. Formatting
- Format the newly partitioned harddisk:
sudo mkfs.ext4 /dev/sdb
C. Mounting (including auto mount after reboot)
- 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
To check if the drive sdb, is mounted? Use mount command:
- mount
mount | grep sdb
E. Unmounting (Updated on 05 May 2020)
To unmount, simply using the umount command:
sudo umount /dev/sdb
But sometimes, the mounted harddisk maybe still in use which makes you cannot unmount. To unmount under this condition, there is a lazy mode:
sudo umount -l /dev/sdb
F. Partitioning Using fdisk (for <2GB Harddisk) (Old)
- 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
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 1 for only one partition number.
6. Enter w to write the partition table to disk.
References
- New disk mount to Ubuntu (2016, Simplified Chinese)
http://huifeng.me/2016/04/19/new-disk-mount-to-Ubuntu/ - How do I check where devices are mounted
https://askubuntu.com/questions/583909/how-do-i-check-where-devices-are-mounted - 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 - How to Add a New Disk Larger Than 2TB to An Existing Linux
https://www.tecmint.com/add-disk-larger-than-2tb-to-an-existing-linux/