Using parted
Below the instructions to create a new ext4 partition on a new hard drive with parted
(tested on Ubuntu 14.04.4 LTS x64). parted
supports GUID Partition Table (GPT) and subsequently can be used for partitions above 2TB, unlike fdisk
.
Use sudo lshw -C disk *-disk
to see the logical name of your new hard drive:
description: ATA Disk
product: ST6000NM0024-1HT
vendor: Seagate
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/sdb
version: SN05
serial: Z4D30T30
size: 5589GiB (6001GB)
configuration: ansiversion=5 sectorsize=4096
The logical name is /dev/sdb
. We can get started:
sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
With sudo parted /dev/sdb print
, we can see the GPT got created:
username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
We also need to know the size of the disk (we will use MB as the unit):
sudo parted /dev/sdb print unit MB print free
which indicates:
Disk /dev/sdb: 6001175MB
We can now create the primary partition so that it takes the entire hard drive space. To set the partition label:
sudo parted --align optimal /dev/sdb mkpart primary ext4 0% 6001175MB
(see https://unix.stackexchange.com/a/49274/16704 if you want to know why we use --align optimal
)
With sudo parted /dev/sdb print
, we can see the primary partition label got created:
username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 6001GB 6001GB xfs primary
We then need to use mkfs to actually create the partition:
sudo mkfs.ext4 /dev/sdb1
The partition is now created, we need to mount it. To do so, sudo nano /etc/fstab
and add the following line (/crimea
is the folder in which we choose to mount the new partition):
/dev/sdb1 /crimea ext4 defaults 0 0
We create the folder and reload /etc/fstab
:
sudo mkdir /crimea
sudo mount -a # Remount /etc/fstab without rebooting in Linux
You can see the new mounted partition using df -h
:
/dev/sdb1 5.5T 58M 5.2T 1% /crimea
In sudo nano /etc/fstab
, instead of using /dev/sdb1
you could use its UUID
, which you can find with sudo lshw -C volume
:
*-volume
description: EXT4 volume
vendor: Linux
physical id: 1
bus info: scsi@1:0.0.0,1
logical name: /dev/sdb1
logical name: /crimea
version: 1.0
serial: c3559307-795b-66db-9844-8e974c88a1cf
size: 200MiB
capacity: 5589GiB
capabilities: journaled extended_attributes huge_files dir_nlink extents ext4 ext2 initialized
configuration: created=2016-06-24 14:56:55 filesystem=ext4 lastmountpoint=/boot modified=2016-07-01 17:15:55 mount.fstype=ext4 mount.options=rw,relatime,data=ordered mounted=2016-07-01 17:07:19 name=primary state=mounted
Otherwise you could simply do sudo blkid /dev/sdb1
:
/dev/sdb1: UUID="c3559307-795b-66db-9844-8e974c88a1cf" TYPE="ext4"
The new line /etc/fstab
will be:
UUID=c3559307-795b-66db-9844-8e974c88a1cf 5.5T 58M 5.2T 1% /crimea
https://unix.stackexchange.com/a/137868/16704 explains why it's best to use UUID (liquidat, cc by-sa 3.0):
The advantage of using the UUID is that it is independent from the actual device number the operating system gives your hard disk. Image you add another hard disk to the system, and for some reason the OS decides that your old disk is now sdb
instead of sba
. Your boot process would be screwed up if fstab would point to the device name. However, in case of the UUIDs, it would be fine.
Summary:
sudo lshw -C disk # Checking the location of the new drive. It is /dev/sdb.
sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
sudo parted /dev/sdb print # Checking that the GPT has been created
sudo parted /dev/sdb print unit MB print free # see 6001175MB size
sudo parted --align optimal /dev/sdb mkpart primary ext4 0% 6001175MB # Creating partition label
sudo mkfs.ext4 /dev/sdb1 # Creating the partition
sudo nano /etc/fstab # Add line `/dev/sdb1 /crimea ext4 defaults 0 0`
sudo mount -a # Remount /etc/fstab without rebooting