
If you have added a new disk to an Ubuntu server, you can use parted to create a partition and then format it ready for use.
This guide shows how to create a single GPT partition using the entire disk.
Warning: Double-check the disk device before partitioning. The commands below will modify the selected disk and can destroy existing data.
Identify the New Disk
First, list the disks attached to the server:
sudo lshw -C disk | grep 'logical name\|size'
For example:
logical name: /dev/sda
size: 60GiB
logical name: /dev/sdb
size: 100GiB
In this example, /dev/sdb is the new 100GB disk.
Create the Partition
Start parted against the new disk:
sudo parted /dev/sdb
Create a GPT partition table:
(parted) mklabel gpt
Set the unit to GB:
(parted) unit GB
Create a single partition using the available space:
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 0
End? 100
You can then verify the partition:
(parted) print
When everything looks correct, exit:
(parted) quit
The new partition should now be available as:
/dev/sdb1
Format the Partition
For a typical Ubuntu data disk, I would recommend ext4:
sudo mkfs.ext4 /dev/sdb1
If you specifically need FAT32 instead:
sudo mkfs.fat -F 32 /dev/sdb1
The partition is now created and formatted. The next step is to create a mount point and mount it, or add it to /etc/fstab if it needs to be mounted automatically after a reboot.