Properly partitioning 3TB Western Digital HDD on GNU/Linux

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Properly partitioning 3TB Western Digital HDD on GNU/Linux

Post by ^rooker »

Since the disk is larger than 2TB, we need to use the new partition table type: GPT (See Rod Smith's "GPT fdisk Tutorial" for more information)

In order to find out if your harddisk has 4k (4096 Bytes) blocks or 512 Bytes, use the command "hdparm" (In my setup, the 3TB disk is /dev/sdd. You must change that to fit yours):

Code: Select all

$ sudo hdparm -I /dev/sdd
Here's an example of how the output on a 3 TB Western Digital (red edition) drive might look like:
(I only copy/pasted the beginning of the output here, as it contains the important information about cylinders, sector size, etc)

Code: Select all

Model Number:       WDC WD30EFRX-68AX9N0                    
	Serial Number:      WD-WMC1T1244880
	Firmware Revision:  80.00A80
	Transport:          Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
	Supported: 9 8 7 6 5 
	Likely used: 9
Configuration:
	Logical		max	current
	cylinders	16383	16383
	heads		16	16
	sectors/track	63	63
	--
	CHS current addressable sectors:   16514064
	LBA    user addressable sectors:  268435455
	LBA48  user addressable sectors: 5860533168
	Logical  Sector size:                   512 bytes
	Physical Sector size:                  4096 bytes
	Logical Sector-0 offset:                  0 bytes
	device size with M = 1024*1024:     2861588 MBytes
	device size with M = 1000*1000:     3000592 MBytes (3000 GB)
	cache/buffer size  = unknown
For this WDC red-edition harddisk, we seem to be lucky as it tells the truth about its logical and physical sector size being: 512/4096 - Some WDC models seem to be "lying" about that, claiming to have "512/512".

CAUTION: If you use "fdisk" on >2TB disks with GPT, they will claim that the disk has 512/512, as well tell you that the partition starts at sector #1. This is not true!
fdisk doesn't read GPT correctly and therefore the information displayed is inaccurate.

For example, running "fdisk -l /dev/sdd" returns the following:

Code: Select all

WARNING: GPT (GUID Partition Table) detected on '/dev/sdd'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdd: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1  4294967295  2147483647+  ee  GPT
In order to display your partition table in a way familiar from classic fdisk, but GPT-aware, use the "sgdisk" commandline utility:

Code: Select all

sudo sgdisk -p /dev/sdd
The result for the unpartitione WDC 3TB drive looks like this:

Code: Select all

Disk /dev/sdd: 5860533168 sectors, 2.7 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): D6A65FFD-D1B0-4FEA-BE3A-2DB964B82C29
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 2048-sector boundaries
Total free space is 5860533101 sectors (2.7 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
Now we create one large partition on the drive:

Code: Select all

sudo sgdisk -a 2048 -n 1:2048:5860532224 -t 1:8300 -c 1:"My stuff"  /dev/sdd
  • "-a 2048" tell sgdisk to align the sectors in a multiple of 2048
  • "-n 1:2048:5860532224" creates a partition number 1, from sector 2048 to 5860532224
  • "-t 1:8300": Partition type will be "Linux filesystem"
  • "-c 1:"My stuff"" is just a human readable name you can give the partition.

Let's see how to get the values for this command:
  • The end sector is calculated, by taking the last usable sector (from "sgdisk -p" output), which is "5860533134", then divide this by 4096 (=your sector size) and multiply the result (without decimal places) again with 4096 and subtract "1". As formular it might look like: (int(last_usable_sector/4096) * 4096) -1
    The result is: "5860532223"
  • The partition types can be listed with "sgdisk -L". There you have a line saying: "8300 Linux filesystem"
If everything was correct, the final result should be checked and verified with "sgdisk -p /dev/sdd".
The output should look like this:

Code: Select all

Disk /dev/sdd: 5860533168 sectors, 2.7 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): D6A65FFD-D1B0-4FEA-BE3A-2DB964B82C29
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2925 sectors (1.4 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      5860532223   2.7 TiB     8300  My stuff
Final step is to format it, using the ext4 filesystem:

Code: Select all

sudo mkfs.ext4 -m 0 -b 4096 /dev/sdd1
  • "-b 4096" sets a blocksize of 4096
  • "-m 0" is used to reserve 0% for root. The default value would be 5%.
    To reserve space for root is a great feature for system partitions, but not for storage. Since this disk is intended for pure user-storage, 5% would be 135 GiB unusable by anyone else but root.
Last edited by ^rooker on Sat Mar 08, 2014 1:23 am, edited 2 times in total.
Reason: Fixed typo: missing "s" in "sudo"
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Re: Properly partitioning 3TB Western Digital HDD on GNU/Lin

Post by ^rooker »

Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply