Latest Updates

Increase And Decrease Size Of Static Linux partitions


 

Task Objective:-

Statement: In Linux, find how to increase and decrease the size of static Linux partitions without losing our data

Disk Partitioning in Linux?

large storage devices are divided into separate sections called partitions. Linux Partitioning also allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive.


Let’s get started

To perform this practical you need basic knowledge of Linux partitions so, in this part, we will increase our static storage.

right now I have a device that has a size of 10GB

Device Name : /dev/sdb

we have one partition in this device of the following size.

current Partition : /dev/sdb1 with size 2.5GB


We also had Some important data as you can see in the following image


Now according to our requirement, we need to increase the size of this Partition without losing our important data.

first, we need to umount this device using the following command

umount "device name"


Now we will delete this partition so we can increase its size using the following command

fdisk "your device name"

so It will ask for a command

d: to delete partition in the device

w: To save all settings



Now our partition of size 2.5GB is deleted and now we have to create a new partition with a new volume as you want

To do this run the following command again

fdisk "device name"

give option “n” to create a new partition of size as you want “ex.10GB”

n: for the new partition

if you go with “n” then

p: for primary partition

if you directly give “p” it will show partition tables in the device

e: for extended partition

after this give size as they asking in the form of start sector and end sector if you press “Enter” without specifying they will take all the volume

w: To save all settings


To check it is been created or not run the following command

lsblk

Now device /dev/sdb1 having 10GB storage

it is changed from 2.5 GB to 10GB

we also need to check the filesystem is it ok or some errors are there so for this we have the following command

e2fsck -f "device name"

-f: to forcefully check

after checking we got to know everything is ok and we good to go further

now we have to resize our file system so new blocks will sync with the older one

To do this we have the following command

resize2fs "device name"

no errors come up we can go further now

Now, we will mount it using the following command

mount "device name"  "mount point"

Note: we will not format the device because it having an old “inode table” already while creating new partitions they asked us to remove signatures so we gave input as NO so the inode table remains their




Finally, you can see our data has remained untouched But we know that we have increased our partition size without losing data

so in this way, you can increase the size of static  Linux partitions


Decrease the static partition in Linux

Let’s get started

right now I have a device that has a size of 10GB

Device Name : /dev/sdb

we have one partition in this device of the following size.

current Partition : /dev/sdb1 with size 10GB

Note: always umount your device before you run any partition related command

first, we need to check the filesystem is it ok or some errors are there using the following command

e2fsck "device name"

no errors come up we can go further now

To decrease the Static Partition size we need to resize our file system first

Run the following command to do this

resize2fs “device name” “size to decrese”

then we will delete the current partition “/dev/sdb1” partition and we will create a new partition with a decreased size using “fdisk” command.



Now, again we have to create a new partition with a new volume as you want

To do this run the following command again

fdisk “device name”

give option “n” to create a new partition of size as you want “ex.5GB”

give the option that is required we have discussed all the option in The first section of the blog(increase the size of a partition)

after this give size as they asking in the form start sector and end sector if you press “Enter” without specifying they will take all the volume

so we have given the last sector as +5G so it will consume space only up to 5GB

w : To save all settings

we just checking partition is created or not


we also need to check the filesystem is it ok or some errors are there so for this we have the following command

e2fsck -f “device name”

f : to forcefully check

here we don't need to resize our partition again because we did this in the above steps

Finally, you can see our data has remained untouched But we know that we have decreased our partition size without losing data

so in this way, you can decrease the size of static partitions



so we can use this concept in the Hadoop cluster especially in the “slave node” where our storage often get filled very fast you can use the LVM concept as well we will see this method in the next blog

Conclusion:-

So with help of the concept of Linux Partitions we able to increase and decrease the storage of the Linux partitions without losing our important data.


No comments