Recently I got a new hard drive (3TB) for my Linux box at work. I didn’t realize that it is problematic / nightmare to do such a simple work.
First, if you try to use fdisk to add the drive, it won’t work. Or I should say… it works, but it only give you a 2TB usable space. This is a limitation of fdisk, because it can handle up to 2^32 -1 sectors (or 2TB). That’s why fdisk is not a solution here.
It seems that the only solution is using parted.
sudo parted /dev/sdd
It will return something like this:
GNU Parted 2.3 Using /dev/sdd Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
First, we want to create a label:
(parted) mklabel gpt Warning: The existing disk label on /dev/sdd will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes
Then, we want to specify the unit:
(parted) unit TB
And tell parted to use all available space:
(parted) mkpart primary 0 -0
Next, we need to review the summary:
(parted) print Model: ATA WDC WD30EZRX-00M (scsi) Disk /dev/sdd: 3.00TB Sector size (logical/physical): 512B/4096B Partition Table: gpt Number Start End Size File system Name Flags 1 0.00TB 3.00TB 3.00TB ext2 primary
As you can see, the size is 3TB. Don’t worry about the file system for now (ext2). If it looks good to you, now we need to leave parted.
(parted) quit Information: You may need to update /etc/fstab.
Next, we need to format the partition:
#CentOS 6 sudo mkfs.ext4 /dev/sdd1 #CentOS 7 sudo mkfs.xfs /dev/sdd1
After few seconds, it will give you some more information about your drive:
mke2fs 1.41.14 (22-Dec-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=1 blocks, Stripe width=1 blocks 183148544 inodes, 732566272 blocks 36628313 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 22357 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Now you can use your drive, such as mounting or putting it into /etc/fstab
sudo mount /dev/sdd1 /mnt/ df /dev/sdd1 2.8T 42G 2.6T 2% /mnt
That’s it! Enjoy your new disk.