Extending the static partition in Linux
Introduction
In this article i am going you the way to increase the size of static partition in linux well i am not going to saying that this is the only way but this way works fine for very good reason which I explain later after showing the demo.
Setup
Before proceeding any further let me explain my setup that i was using for this article
- Windows Host os
- Red hat enterprise linux (RHEL) as a guest os
- connected one virtual hard disk of size 10GB
- created one partition of size 2G (name /dev/sdb1)
- formatted with ext4
- mounted on folder /one
- used 100% storage hard disk with garbage data
Expending
So let expand static partition in such a way that our data is not lost and partition size is also increases well this way is only work if you have continuous free space in hard disk because we can only be created in continuous manner we can’t create partition in non continuous manner
Step 1:- Unmounting /dev/sdb1
- before proceeding any further let first unmount the partition so that it not give any further use
umount /one
command
note :- unmount command is written as umonut
in early stage of unix OS a command, program and file name can be as big as eight character only due to memory constraints many program at that time is written in C language they have .c extension that left only six character for actually name unmount has seven character long that why they omit n and make it six character and give name as umount this is sometimes also known as 9th commandment of c language
read all ten commandment of c in this site http://www.lysator.liu.se/c/ten-commandments.html
Step 2:- Creating /dev/sdb2
- now create new partition name use
fdisk /dev/sdb
command - use
n
option - then click 3 times enter
- then give size in mycase i am giving size of 2GB use
+2G
- then use
w
to save and quite
- verify using
lsblk
command
Step 3:- Creating PV
- now next step to create /dev/sdb2 to pv(physical volume) for this use
pvcreate /dev/sdb2
command
Step 4:- deleting all the existing partition
- now use
fdisk /dev/sdb
command - delete both partition with option
d
Step 5:- Creating new partition of 4G
- now use option
n
and create new partition - three times enter
- then size in my case i am giving size of 4Gb write
+4G
- the use
n
(for no don’t worry i will explain what is the meaning of this in my demo explanation part)
- use option
w
to save and quite all our changes
Step 6:- The real process of extending
- use
e2fsck -f /dev/sdb1
command (i will explain this command at later section)
- now use
resize2fs /dev/sdb1
command
Step 7:- Mounting and verify
- now mount the /dev/sdb1 in any folder i am my old folder /one because after expanding its common to use same folder use
mount /dev/sdb1 /one
command and verify usingdf -hT
command
- to verify again whether we garbage data or real data see the content of the folder using
ls -lh /one
command
- we have our old data with the same creation time
We successfully completed our task to extend the size of static partition without losing data
Demo Explanation
Now let start explanation form:-
1 e2fsck:-
- this command used to check for any error in the file system
- this only work with the ext2, ext3 and ext4 file format
- for example if os terminated due to some error you can use this command to find the root cause
- this command is used to find bad block(block which are damage and can’t be used any more) and use you hard disk without any problem this command does not fix bad block it only create table that tell os not to store data on that blocks
- in our case this command find that partition size is four 4GB but is also find that only first 2GB hard disk is formatted in a version that I known which is ext4 another 2GB in some unknown format which I have no knowledge so that create a entry in super block
- -f option is used force check a disk if we not use this option superblock tell there is no error
super block:- A superblock is a record of filesystem, including its size, the block size, the empty and the filled blocks and their respective counts, the size and location of the inode tables, the disk block map and usage information, and the size of the block group. read more about super in http://www.linfo.org/superblock#:~:text=A%20superblock%20is%20a%20record,size%20of%20the%20block%20groups.
2. resize2fs
- this command is used to resize file system by updating superblock entry is increases or decreases the size but if you run this command alone there may be good chance that this command will fail and said there in no error
- this is the reason why we use e2fsck command to tell there is error
3. creating pv
- the whole reason to create a new pv named /dev/sdb2 is to create the following error in super block entry
4. no asked when we create /dev/sdb1 again
- when we create any partition fdisk give create a partition table for us automatically but in our case we already have partition table so fdisk asking us to delete old partition table and create new table in place of this which we said no we want to retain our old partition table
- if we as yes its deleted our old partition table our all data will be lost
Conclusion
In the end I only say this we create an error and solve that error to do the thing that we want to achieve this kind of thing is only possible when we know the concept behind it.
This task is only possible because we know how the partition work, what is inode table, what is real meaning of file system and what actually happen when we create or delete files/folder in hard disk
Thank for everyone to reading my article till end if you have any doubt please comment if you have any suggestion please mail all comment both positive and negative is more than welcomed
Contact Detail
LinkeDin [https://www.linkedin.com/in/suyash-garg-50245b1b7]
Additional Tags
#linux #elasticity #partition #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeudcation #arthbylw