Skip to main content

Partition and format a disk drive from command line with parted and mkfs ext4.

Updated by Tim Rabbetts on
disc, reader, reading arm

I have a Debian server and added a new drive to it but it needed to be ext4.  In the past I have used Gparted the graphical front end to parted, but now I figured it worth me doing from the command line, like anything, simple when you know how, but took a while to figure out.

parted
d
mkpart
primary
ext4
0%
100%

The tricky bit was the start and end, I trired using print free to do it in bytes but would keep getting warning which should not be ignored:

Warning: The resulting partition is not properly aligned for best performance

Percentage for start and end works great.

This worked okay but the partition didn't have a UUID when using blkid which I needed to mount using fstab.

I used mkfs.ext4 to format the partition.

sudo mkfs.ext4 /dev/sdc

Finally, added /etc/fstab entry to mount at boot. 

/dev/disk/by-uuid/54e5cf14-d1c4-44db-b965-63fbf6ddd71c /media/disk7 ext4 defaults 0 0

To test /etc/fstab works okay without reboot, which is important cause if you mess it up you will have to hook up monitor, keyboard etc to your server.

sudo mount -a

This command tries to mount all disks in fstab.

Should mount okay, hope this saves someone a bit of time.

 

 

Add new comment