[EN] Create, mount, and make persistent a new ext4 filesystem on a new disk
![[EN] Create, mount, and make persistent a new ext4 filesystem on a new disk](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FHhTfeSKz4xQ%2Fupload%2F811a33114e2ca04eaf91b2af685a77e6.jpeg&w=3840&q=75)
When managing a Linux server, sometimes you need to add new partitions, e.g, directory to store your backup in a separate physical disk, or new place to put your files. In this article, I’ll create a new ext4 partition with the mkfs.ext4 command.
Preparing the partition
Here I have a new block device /dev/sdb of 5GB and will create one partition on it.
# List all block devices
vagrant@vagrant:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 64G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 62G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 31G 0 lvm /
sdb 8:16 0 5G 0 disk
# Create a new partition
vagrant@vagrant:~$ sudo fdisk /dev/sdb
# Let's see all the block devices again
# There should be /dev/sdb1 if that's the only partition
vagrant@vagrant:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
...
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 5G 0 part
Creating the filesystem
Then let’s create an ext4 filesystem on top of that new partition.
vagrant@vagrant:~$ sudo mkfs.ext4 /dev/sdb1
...
Writing superblocks and filesystem accounting information: done
# Let's create a /backup directory and try to mount that FS onto that
vagrant@vagrant:~$ sudo mkdir /backup
vagrant@vagrant:~$ sudo mount /dev/sdb1 /backup/
# Check what's inside the partition. It's empty ofc
vagrant@vagrant:~$ ls /backup/
lost+found
# Check the FS type, size, and the mount
vagrant@vagrant:~$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
...
/dev/sdb1 ext4 4.9G 24K 4.6G 1% /backup
Making it persistent between reboots
At this point if you reboot the server, the /backup won’t be mounted to the partition automatically. You need to make it persistent by adding a new entry into the /etc/fstab file.
vagrant@vagrant:~$ sudo nano /etc/fstab
...
# Let's mount /dev/sdb1 to /backup using the ext4 filesystem with standard options
# and don’t worry about backing it up or checking it during boot (it's the 0 0 at the end).
# Read more: https://www.redhat.com/en/blog/etc-fstab
/dev/sdb1 /backup ext4 defaults 0 0
Now you can safely reboot without worrying the disk mount is gone.
![[EN] Set Up Amazon ECR Pull-Through Cache for Docker Hub](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F631dd8693e8d6f3497ad63e7%2F1ca35a5a-6303-4a86-badb-91961cf65694.jpg&w=3840&q=75)
![[EN] Track progress of MySQL Import/Export process using PV](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2Fjf1EomjlQi0%2Fupload%2Fa7ee07f61c1dc2ad71b4cf2bb4523765.jpeg&w=3840&q=75)
![[EN] Lesson learned from using the wrong AWS ElastiCache Redis endpoint](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FemolMCqnKfg%2Fupload%2Fc7eb8197eb9ef632459ae6612b861cc6.jpeg&w=3840&q=75)
![[EN] My experience taking the KCNA certification](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FKXwPJtAJLfU%2Fupload%2F3deba4b52e1b8e442179a495944ccb9e.jpeg&w=3840&q=75)
![[EN] How I Stopped Copy-Pasting AWS EC2 IPs and Started SSHing Smarter](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FDXRP2PKlsFQ%2Fupload%2F8767e91ce57fa7ff90bca9149c142626.jpeg&w=3840&q=75)