Partition and format hard disk drive to ext4
How to format a brand new hdd from the command line interface (CLI), easy steps. Instructions to make a properly aligned partition that uses the whole device. Perform theses operations as root.
First, find out block name (/dev/sdX) with
Make sure you pick the right device, or you could end up wiping all your data !
We need to populate the partition table before we can proceed further. Run parted for the device you want to format
Once you are in parted :
GNU Parted 3.2 Using /dev/sdX Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt Warning: The existing disk label on /dev/sdX will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes (parted) mkpart Partition name? ? storage File system type? [ext2]? ext4 Start? 0% End? 100% (parted) quit
Mkfs, tune2fs, e2label
Now we need to format the volume to be able to use it
You probably want to be able to use 100% of your storage space, so let's remove root allocated space witch uses 5% of the disk by default
tune2fs -m 0 /dev/sdX1
Then we give a name to the partition (optional)
e2label /dev/sdX1 storage
If you want your new volume to be mounted automatically when you restart your machine.
First find your device block id with
Then open fstab with text editor
Add this line at the end of the file (change UUID value to match your disk, change /storage if you want to use another mount point)
UUID=0c0514c1-4fe3-41b4-ac7b-61a019481356 /storage auto noatime 0 0
You may need to
mkdir /storage (or other mount point) before you can mount with