Increase or Decrease the Size of Static Partition in Linux.
In operating systems, Memory Management is the function responsible for allocating and managing the computer’s main memory. Memory Management function keeps track of the status of each memory location, either allocated or free to ensure effective and efficient use of Primary Memory.
There are two Memory Management Techniques: Contiguous, and Non-Contiguous. In Contiguous Technique, the executing process must be loaded entirely in the main memory. Contiguous Technique can be divided into:
- Fixed (or static) partitioning
- Variable (or dynamic) partitioning
Fixed Partitioning:
This is the oldest and simplest technique used to put more than one process in the main memory. In this partitioning, a number of partitions (non-overlapping) in RAM is fixed but the size of each partition may or may not be the same. As it is a contiguous allocation, hence no spanning is allowed. Here partition is made before execution or during system configure.
So first we have created a fixed partition in sdb hard disk of size 5G and mounted it to the /ld mount point.

Now we would unmount sdb1 partition from the folder and reun e2fsck command. The e2fsck command is used to check the ext2/ext3/ext4 family of file systems. For ext3 and ext4 filesystems that use a journal, if the system has been shut down uncleanly without any errors, normally, after replaying the committed transactions in the journal, the file system should be marked as clean.
Then we would delete the 5G partition.

After deleting the 5G partition we would create a new partition of new required size(in this case 7G). In the process of deleting the file we would not delete the ext4 signature in the partition.

Now we have created a new partition of 7G and now we have to mount it.

First we would run resize2fs command to format it in a special way such that no data is lost. Then we would mount it to the desired folder.

In the above picture we could clearly see the size of partition has increased to 7G without losing the internal data within.
Here is the list of all commands used:-
First created a 5G partition
cat /ld/cat.txt ===> meow
df -h ===> sdb1==5G
umount /dev/sdb1
e2fsck -f /dev/sdb1
fdisk /dev/sdb
d
n
p
+7G
N(do not delete ext4 signature)
resize2fs /dev/sdb1 +7G
mount /dev/sdb1 /ld
cat /ld/cat.txt ===> meow
lsblk ===> sdb1==7G
df -h ===> sdb1==7G