Linux Partition: Static Partition Scaling without any data loss
In this blog, we are going to see how to increase or decrease the size of the static partition in Linux without compromising any data loss and how to do that in Online mode without unmounting.
I already explained the basic concepts of partition in very detail in my previous blog. You can refer to that blog by clicking here.
In this practical, the Oracle VirtualBox is used for hosting the Redhat Enterprise Linux (RHEL8) Virtual Machine (VM).
The first step is to attach one hard disk. So, I attached one virtual hard disk with the size of 40GiB. That disk is named โ/dev/sdcโ. You can check the disk name and all other disks present in your VM by running the following command.
fdisk -l
Then, we have to do partition by using โfdiskโ command.
fdisk /dev/sdc
Then, enter โnโ in order to create a new partition. Then enter the partition number and specify the number of sectors or GiB. Here, we entered 20 GiB in order to utilize that much storage unless we do partition, we canโt utilize any storage.
We had created one partition named as โ/dev/sdc1โ. Next step is to format the partition. Here, we used Ext4 filesystem(format) to create an inode table.
Next step is to create one directory using โmkdirโ command and mount that partition in that directory since we canโt directly use the hardware device no matter it is either real or virtual.
One file should be created inside that directory in order to check the data loss after Live scaling of static partition.
Ok, now the size of the static partition is 20 GiB, we are going to do scaling up to 30GiB without unmounting the partition. For this, again we have to run the following command.
fdisk /dev/sdc
Then delete the partition. Donโt bother about the data, it wonโt lose.
Then enter โnโ to create the new partition and specify your desired size. Here, I like to scale up to 30GiB. And then one warning will come and it says that โPartition 1 contains an ext4 signatureโ and ask us what to do with that either remove the signature or retain.
If you donโt want to lose the data, then enter โNโ. Then enter โwโ to save the partition. you can verify your partition size by running โfdisk -lโ command in terminal. Finally, you increased the size of static partition.
First part is done. Then next step is to format the partition in order to create the file system. But this time, we will not use โmkfsโ command, since it will delete all the data. We donโt need it. We have to do format without comprising the data. For that we have to run the following command.
resize2fs /dev/sdc1
Finally, we done format without comprising the data. We can check this by going inside that mount point and check whether the data is here or not.
Yes, data is here. It is not lost even though we created new partition and formatted the partition.
Live Linux Static Partition scaling without any dataย loss
In this blog, we are going to see how to increase or decrease the size of the static partition in Linux without compromising any data loss and done in Online mode.
I already explained the basic concepts of partition in very detail in my previous blog. You can refer to that blog by clicking here.
In this practical, the Oracle VirtualBox is used for hosting the Redhat Enterprise Linux (RHEL8) Virtual Machine (VM).
The first step is to attach one hard disk. So, I attached one virtual hard disk with the size of 40GiB. That disk is named โ/dev/sdcโ. You can check the disk name and all other disks present in your VM by running the following command.
fdisk -l
Then, we have to do partition by using โfdiskโ command.
fdisk /dev/sdc
Then, enter โnโ in order to create a new partition. Then enter the partition number and specify the number of sectors or GiB. Here, we entered 20 GiB in order to utilize that much storage unless we do partition, we canโt utilize any storage.
We had created one partition named as โ/dev/sdc1โ. Next step is to format the partition. Here, we used Ext4 filesystem(format) to create an inode table.
Next step is to create one directory using โmkdirโ command and mount that partition in that directory since we canโt directly use the hardware device no matter it is either real or virtual.
One file should be created inside that directory in order to check the data loss after Live scaling of static partition.
Ok, now the size of the static partition is 20 GiB, we are going to do scaling up to 30GiB without unmounting the partition. For this, again we have to run the following command.
fdisk /dev/sdc
Then delete the partition. Donโt bother about the data, it wonโt lose.
Then enter โnโ to create the new partition and specify your desired size. Here, I like to scale up to 30GiB. And then one warning will come and it says that โPartition 1 contains an ext4 signatureโ and ask us what to do with that either remove the signature or retain.
If you donโt want to lose the data, then enter โNโ. Then enter โwโ to save the partition. you can verify your partition size by running โfdisk -lโ command in terminal. Finally, you increased the size of static partition.
First part is done. Then next step is to format the partition in order to create the file system. But this time, we will not use โmkfsโ command, since it will delete all the data. We donโt need it. We have to do format without comprising the data. For that we have to run the following command.
resize2fs /dev/sdc1
Finally, we done format without comprising the data. We can check this by going inside that mount point and check whether the data is here or not.
Yes, data is here. It is not lost even though we created new partition and formatted the partition.
Reduce the size of the Static Partition
You can also reduce the Static Partition size. For this, you have to follow the below steps.
- Unmount
- Cleaning bad sectors
- Format
- Mount
First step is to unmount your mount point since it is online, somebody will using it.
umount /partition1
Then we have to clean the bad sectors by running the following command
e2fsck -f /dev/sdc1
Then we have to format the size you want. Here we want only 20 GiB and we will reduce the remaining 10 GiB space. This is done by running following command.
resize2fs /dev/sdc1 20G
Then we have to mount the partition.
Finally, we reduced the static partition size.
Above figure shows that Data is also not lost during scaling down.
Thank you all for your reads. Stay tuned for my next article, because it is Endless.