How to create Static Partition in Linux Operating System ?
What is storage ?
Storage is a process through which digital data is saved within a data storage device by means of computing technology. Storage is a mechanism that enables a computer to retain data, either temporarily or permanently.
Type of storage ?
Storage is among the key components of a computer system and can be classified into several forms, although there are two major types:
· Volatile Storage (Memory): Requires a continuous supply of electricity to store/retain data. It acts as a computer’s primary storage for temporarily storing data and handling application workloads. Examples of non-volatile storage include cache memory and random access memory (RAM).
· Non-Volatile Storage: A type of storage mechanism that retains digital data even if it’s powered off or isn’t supplied with electrical power. This is often referred to as a secondary storage mechanism, and is used for permanent data storage requiring I/O operations. Examples of volatile storage include a hard disk, USB storage and optical media.
What is Disk ?
A part of the computer that operates the disks that store information.
Disk drives are called “storage devices” because they store information on portable or permanent disks (e.g., floppy disks, hard disks and Zip disks). A disk drive spins the disk around at high speeds as it reads and writes data on the disk.
Before starting this practice we need to know what static partition. So I want to discuss some vocabulary that is related to today’s practical.
What is a static partition?
->According to geek for geeks
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.
Static V/S Dynamic Partitioning
💁🏻♀️In most cases, we can use dynamic partitioning. It provides us a lot of flexibility. The following table will help you understand the difference between Static and dynamic partitioning.
Let’s move towards practical part👇🏻
First of all, we focus on the agenda:
1. Attach a disk with OS
2. Create partition
To perform the whole particle we need to follow the steps given below:
We will start by adding a hard disk to an existing virtual machine. In the settings of the VM go to storage and add a hard disk of the desired size. I added a Hard Disk of 7 GB. Following are the images of the steps to follow while adding the disk.
Adding the Virtual Drive
Open Oracle VM Virtual Box Manager, select the Virtual Box for which you want to add the new disk and click on Settings.
Storage=>Add hard disk
In the Settings window, click the Storage section.
select hard drive and click on Add a hard disk.
Click on create
Select VDI (Virtual Disk Image)
· What is the means of VDI?
Normally, Oracle VM VirtualBox uses its own container format for guest hard disks. This is called a Virtual Disk Image (VDI) file. This format is used when you create a new virtual machine with a new disk.
Then tap next
Click on Dynamically allocated
· What is the means of Dynamically allocated?
For more flexible storage management, use a dynamically allocated image. This will initially be very small and not occupy any space for unused virtual disk sectors, but will grow every time a disk sector is written to for the first time, until the drive reaches the maximum capacity chosen when the drive was created. While this format takes less space initially, the fact that Oracle VM VirtualBox needs to expand the image file consumes additional computing resources, so until the disk file size has stabilized, write operations may be slower than with fixed size disks. However, after a time the rate of growth will slow and the average penalty for write operations will be negligible.
Then tap next
Now give a name to your new H.D & specify a size you wish for it.
1. type the name of the new virtual hard disk file into the box below or click on the folder icon to select a different folder to create a file in
2. select the size of virtual hard disk in megabytes. This size the limit on the amount of file data that the virtual machine will be able to store on the hard disk.
3. Click Create
Here our H.D is created but still, it is not attached to our VM or RHEL8 O.S.
Attach the not attached harddisk.
To attach just click on choose that’s it our H.D name & size you specified will pop-up there tap ok! as you can see in above snapshot.
Now it’s time to go inside VM O.S & do this task
To Check & verify new H.D attached or not use the below command
Step 2 :- create a partition
We can see that a hard disk of 20 GB is attached to the virtual machine. Now we have to create a partition
For the partition, we have to go in the /dev/sdb. Follow the below commands to create partitions.
After you reach inside the disk then follow the steps given below
1. Press n to create new partition.
2. Press p to make primary partition.
3. Press 1 is created first partition on selected disk.
4. There are 1–4 partition number. We can type any one number from them.
5. Press enter to leave first cylinder as default.
6. Now assign space to partition. Use + to assign space e.g.
+7G and press enter.
7. Press p to print partition table.
8. Press W to save and exit.fw
To check partition create or not repeat the same command.
Step 2 :- Format partition :
Now we have to format our partition. To format partition we use mkfs command
syntax is mkfs.<file-system-type> <partition>
We have formatted our newly created partition with ext4 file system.
Step 3:- Creating the mount point
Now we have to mount our partition on any directory. For that i am creating one directory called mount_point.
After we successfully format the partition now we have to mount it to a directory. So first we need to create a directory. To create a directory using the below command:
Syntax is => mkdir (directory_name)
you can create any directory.
Step 4:- Mount the disk
Mount /( partition ) /( dir name )
mount /dev/sdb1 mount_point/lsblk
Now we are done with mounting. Let’s keep some test files in the directory created so that we can prove that the data is retrieved on disk format or deleted.
cat > text1.txt
cat > text2.txt
Here in my case I have put some data inside these files
Step 5- Unmount the Created Partition
Now, In order to increase the partition We will unmount this directory from partition
Command used for this is :- umount /directory-name
Step 6:- Delete and create new partition :
Now, delete the old partition and create new partition using command
First to delete press d option
Then create new partition of 10G as created earlier and use w option at last to save/write
Press d- To delete partition
Step 7:- Repair the old inode table
Now we have to clean the partition to avoid unwanted values hence we can use the below command
e2fsck -f /dev/sdb1
Step 8- Mount the partition
Now, In order to use this partition and to retrieve our old data we need to mount it again to a directory
mount /partition-name /directory-name
mount /dev/sdb1 mount_point/
So Now our Partition size is increased and our data is still there you can check using ls and df-hT command
Mount the new partition again using the previously used commands and now we can see that the data we had created for testing remains safe and there is no data loss even if we delete the partition.
The final results will be like as follows:
Thanks for reading