Increase And Decrease Size Of Static Linux partitions
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_iykM8qMPVVrNAsiCJQ3eUm6nnEnjBYXWMMr-b3R4sYKeGUTJ847IqQ_1hdA0msqAoGMkOG0lZbgk4tPfEBDNZJeL0Fj902PNwRwznnLXMEmaFU43cN0NUDc2pwm_HV-dggYlq5sT5jE/s16000/1_gJ8Vk1J4DJL4CdBaLzoCIA.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhANThdtnLC9IvojCZJ-X0v9sg6-obdpeMCqeFwQOnvUoGotsOinhQrztV2UWhIHV1T_g12Oi5uoyRFIUA_zROqtEG0OUXs8_wMP_VnN1lDdZdphuyj9Mg26vuEax9PvBzkn6AtJP2hE6M/w640-h544/1_mcxsWKVl8gnN9bEQbWmBYg.png)
We also had Some important data as you can see in the following image
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhE-Gx1_i4ML0a80Cf_9guTn4eJauD9-fEosIqdGncYTlFdsLTYhglk4CGgywfxpI4oNqR8RZj4KxlUU8clWoy7UeqUoIUAC87Top_EDemyWfug2zaRGrdMxeudP4te0yeWpF-lN27MaY/w640-h568/1_81EJuQJ_CN4iT3uEXpcpmg.png)
first, we need to umount this device using the following command
umount "device name"
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3sHHk6iMeyxEF3CEbNbJM7g1VXJTY-sdTO2zTg05tLKRbMXZMGAfOM3eOu5Ce_mSaefNh4Z2qT5ZEaKlZzOYSyLjUCbxKWgSQCo3ywfIn_a0pYQ3cIaJ3rIhqvds5PKbqhKAKQDSSrVg/w640-h544/1_i8g_igRMxnkYtzZxY_AZvA.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtpTC4olcZx1-vXDWxgsUcGY3e5kEaY2JYIuKHwnCV6RsxfE5dLdgVLJwvF4wWWJcKHadUE_dTjbuc47vICgSkMl0ZjdB_C6rcusHnfbR1GTWVVK6aQp7HsBGGH6l28uCTKrjqFE7Yv6c/w640-h540/1_QJEFxEhNqDFu7geg01mEGg.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgzOtczg5RxsArO2f7_fXfygIAwkK0XbT9q6kqy0_Is4JOUUdH6W6BGr-MSgJgWwRw5Qgl0HOMqJgq7h7Lowh3MigZYrL7B1SvyW2uraC2qYBuDCSCZKPq21ePHRFlOtLWk_sw6Aab4es/w640-h100/1_R2Nntg9LKkUh0OAO81j2Pw.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNJZgAUWqnBcdZyDt6fI7khkLD8fOey8i7nN-TQiBzsNNfpg7KCTFSvONH7A9UXoxydZWoguiqYPUO1dPj03qWjMiXiCQD5otFvpkby4fcnzAEVhVad6aT9RsDAsvotBf6g5jR-azzt6A/w640-h540/1_nSMpK5VkKRLaPUzIb15oZg.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgzOtczg5RxsArO2f7_fXfygIAwkK0XbT9q6kqy0_Is4JOUUdH6W6BGr-MSgJgWwRw5Qgl0HOMqJgq7h7Lowh3MigZYrL7B1SvyW2uraC2qYBuDCSCZKPq21ePHRFlOtLWk_sw6Aab4es/w640-h100/1_R2Nntg9LKkUh0OAO81j2Pw.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDMSQRpnC85I_Zcnmop8SotODUIVrNNNLECBkzfwKRfC-Egxdnzrv86Cw6P828yqZ5_rpTlyu2lQzFKQCB4WTQdxj0K3T9WDM0Uaurbcf0fyvqPlX3DuoSJv-Z19re5GwNdqPvbp_G9A8/w640-h544/1_UuBb1WQv9MJj9DXQf2d9Kw.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW-o2FFL-kXVlv1hsJ60AOd2iXVfZYPiSbuHQFnW58KexBGC7GIkct4ZjzBVvoCkfwwaRIiMM6CzFoLXBvAaI1HdTqJhYSO680s2i3PLppVzGizuiT68OkhBb-patHGoLpiwLZJOyCeW8/w640-h546/1_tcKzeC-5Wk0BacuUQglxrA.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEGJJLw7kWzWIliruNIT-UOJPGOtE27bZM27wGl1R2M4aEwwQOfBAuO9jfW4TZoGRgPsqKyTpzL651brN-eueSCGKtZ60gWwxyVVGGdApzxfSPA6iW6KTC-nNswQL4xcflIhPUgOYjfFE/w640-h548/1_r9tOMEy2heBy3gL2yMLAjA.png)
so in this way, you can increase the size of static Linux partitions
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJOxYYtCZMEYFntJv1wdfuDbTsiTAhXc37EMWmf2LFYD9UHONO_GZ5kj6bCoifs7NrtvCaremTfoozYVEl80QYLjCQGjIks7A_HkbkO2mPzmmv_D9TCDhUcpBNlOy3Bt1u6xLC9U7zHFA/w640-h564/1_AtzYW6T7Zi0uEOWssYzRXQ.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir8DyQtHZm481cCMC4MoipB7NX4Jd8RD9-MTLmCLleWtfliW8VxmS2duhk1oziZasXtcbaBicRO-cyOng1BdXnkCm3cfhfFsQuWXok5qD3ObXCDH_u7_wXdHmV2ePAwblFZ3UN36WV5d4/w640-h530/1_jqP9zFxo3pwXD0zAS10lqg.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjBz8E1Xvyg7YnrZj_RVQ8NWuwZJ610qGInRIx-bWJP-G2tIoVoHzdNBbTZA_h4c6vwFl5wJXRiAhALxJF9kI3xukKNeJC6znM0OGOGJM2ve2hO9Q28T9VGMoYMA9d7eFjhbT7aiUxLs8/w640-h540/1_QJEFxEhNqDFu7geg01mEGg.png)
we just checking partition is created or not
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSYam-JP399grMPd5CFYhIJbwzKqy1MgAos8T1h_zTKomol0xYZpIM4-HOWi3flmbaJ_pzJn940V9N-TtPcXZQvhq-oslm_0uV_rN_bOfOO14B4nyCmnsAuH_Nz82sjgVfi8Q1d_i2oCw/w640-h516/1_Npr_rSUz3ImMqgMmv-is3w.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpKPJswP6dWxHXU1l0H403Qitey9votkz2F_RTJ1tZWPlnvwIH1k1qI2-HCoun1xi9bpUuWL17grEggXZjOBCoRxpxpJkLWVrqDp-xZSJPOk8mQTce4Elpx3Sxu1og2aOz4jjXrwXstHM/w640-h562/1_b6aOm5GqTEWTQJ4xkA1k8w.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH6Cw2WNB5s5wM7lGF1qlkBpq_dt4RludFsQg24TJ1nVbxFY7iWgquudcBgB1CJJkbGBoVstgImxtqkGbYFaF94EjgHJvcUBvEjO8cs40UCtz9IzEjMbE67U9Ixajk5pO4vg2rKWPkiF8/w640-h556/1_uGd81t4lSQgOaoOl_PVOHg.png)
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