Hello! Recently, I faced a simple at first glance task - to increase the “hot disk size” on a Linux server.
There is a server in the cloud. In my case, this is Google Cloud - Compute Engine. The operating system is Ubuntu, the ext4 file system (suitable for all ext). A 30 GB disk is now connected. The base grows, files swell, so you need to increase the size of the disk, say, up to 50 GB. At the same time, we do not disconnect anything, do not reload anything.
Warning! Before you begin, we backup all important information!
1. First, let's check how much free space we have. In the Linux console, we write:
In simple terms, I have 30 GB in total and 7.9 GB are now free. Need to increase.
2. Then I go and connect a little more GB through the console of my host. In Google Cloud, this is done easily, without rebooting. I go to Compute Engine - & gt; Drives - & gt; I’ll select my server disk and change its size:
I go inside, click "Edit" and increase the size of the disk to the size I need (in my case, up to 50 GB).
3. So now we have 50 GB. Check it on the server with the command:
We see our new 50 GB, but for now we can only use 30 GB.
sudo fdisk -l
4. Now we will delete the current 30 GB disk partition, create a new one with 50 GB. You may have several sections. You may need to create several new sections. For this operation, we will use the fdisk
program, which allows you to manage hard disk partitions. It is also important to understand what disk partitions are and what they are for - read here
. To run the program fdisk
we use the command:
5. Inside the interactive mode of the fdisk
program, we perform several operations.
First we drive in:
The team displays a list of our current sections. In my case, one section of 30 GB and another 20 GB in free floating, if I may say so.
6. Then we drive in:
Delete the current partition in order to create a new one for all 50 GB. Before the operation, we check once again whether we made important information backup!
7. Next, indicate the program:
The team creates a new section. All parameters should be set by default - you can simply press Enter. If you have a special case, then specify your options. As you can see from the screenshot, I created a 50 GB partition - what I need.
8. In the end, I specify the program:
This command writes changes and exits from fdisk . We are not afraid that the reading of the partition table failed. The following command will help fix this.It remains quite a bit.
9. We left fdisk
and returned to the main Linux line. Next, we drive in, as we were advised earlier:
If everything went well, then you will not see any message. If you don’t have partprobe installed, install it. It is the partprobe that will update the partition tables, which will allow us to expand the partition to 50 GB online. Go ahead.
Hint! You can install partprobe like this:
apt-get install partprobe
10. Now it remains to redefine the size of the partition using the program resize2fs
. She will do it online - even at that moment I had scripts working and writing to disk.
program will overwrite the file system metadata. To do this, use the following command:
Here, sda1 is the name of your partition. In most cases, this is sda1, but exceptions are possible. Be careful. As a result, the program has changed the size of the section. I think this is a success.
11. Now let's make sure that the size of the partition has changed and now we have 50 GB. To do this, repeat the very first command: