Friday, February 26, 2016

HOWTO create Partition larger than 2TB with parted

1- First we will find the Current Disk Size

fdisk -l /dev/sdb
Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table

2- Now, we will use parted’s mklabel command to set the disk label to GPT (GUID partition table format (GPT)):

parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) print
Error: /dev/sdb: unrecognised disk label

(parted) mklabel gpt

(parted) print
Model: Unknown (unknown)
Disk /dev/sdb: 3000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt


Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes

3- Next, set the default unit to TB, enter:

(parted) unit TB

4- Create a 3TB partition size:

(parted) mkpart primary 0 0
(parted) mkpart primary 0.00TB 3.00TB

5- To print the current partitions, enter:

(parted) print

Model: ATA ST33000651AS (scsi)
Disk /dev/sdb: 3.00TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      0.00TB  3.00TB  3.00TB  ext4         primary

Quit and save the changes, enter:

(parted) quit

Information: You may need to update /etc/fstab.

6- Format the filesystem:
# mkfs.ext4 /dev/sdb1

7- Edit fstab and mount the Filesystem:
vi /etc/fstab
# add the following line:
/dev/sdb1       /data   ext4    defaults    0   2

mkdir /data
mount /data
df -h

Filesystem             Size   Used  Avail Use% Mounted on
/dev/sdc1               16G   819M    14G   6% /
tmpfs                  1.6G      0   1.6G   0% /lib/init/rw
udev                   1.6G   123k   1.6G   1% /dev
tmpfs                  1.6G      0   1.6G   0% /dev/shm
/dev/sdb1              3.0T   211M   2.9T   1% /data

And that will do it :)