Skip to content

setting up a fresh hdd with ext4 in linux

Fresh ext4 partitions have 2 issues:

  • 5% reserved space for root that is not needed on large drives: 5% of a 20TB is 1TB wasted.
  • days or weeks of waiting for the drive to complete the ext4lazyinit process, which is a waste of electricity and time.

Here's the steps to set up and mount a new hard drive with ext4 in linux:

  1. find the drive you want to format:
shell
lsblk -o NAME,MOUNTPOINT,SIZE,MODEL | grep -E '^\w+' | grep -v '/$' | grep -v '^loop'

In the output, look for the drive that has no mountpoint and the size and name you expect.

  1. Create the partition, replace /dev/sdX with the correct drive
shell
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0 /dev/sdX
  1. Create a mount point
shell
sudo mkdir /media/YOURMOUNTPOINTNAME
  1. find the UUID of the drive, copy the UUID of the drive you just formatted (e.g. sdX)
shell
ls -lha /dev/disk/by-uuid
  1. Open the fstab file sudo nano /etc/fstab, then add the following line to the end of the file:
shell
/dev/disk/by-uuid/UUID /media/YOURMOUNTPOINTNAME ext4 defaults,nofail 0 2
  1. Mount the drive
shell
sudo mount -a

That's it! You now have a fresh ext4 partition with no wasted space and no waiting for the ext4lazyinit process to complete. Enjoy.

Exisiting partitions

If you missed to force the lazy_itable_init=0,lazy_journal_init=0 options during the mkfs.ext4 command, you can still force the lazy init process to complete by running the following commands:

  1. unmount the drive
shell
sudo umount /dev/sdXXX
  1. force the lazy init process to complete
shell
sudo mount -o init_itable=0 /dev/sdXXX /media/YOURMOUNTPOINTNAME

The command might take a couple of minutes to complete, but it will finish the lazy init process immediately. Then your drive will behave as expected. via

I've probably stumbled across this post 20 times so I include it here for reference.


Clicking this button loads third-party content from utteranc.es and github.com