| |

How to enlarge root partition and filesystem size of cloud Linux VM at runtime without rebooting Linux

It is common that the root disk space is not enough when running a Virtual Machine in the cloud such as Amazon Web Service (AWS). The cloud storage usually provides tools or facilities to enlarge a virtual disk size. However, to make the Linux recognize and and use the enlarged disks without rebooting the OS, some actions are needed. In this post, we will use Ubuntu 18.04 as one example, to show how to enlarge Linux root partition and filesystem sizes at runtime without rebooting Linux.

hard drive photo

Please note that filesystem and partitions resizing are dangerous operations and may lead to data lost. Please backup you data first before doing so by using snapshoting mechanism in the cloud service or using common backup tools.

Here is one example on a AWS EC2 node, named n8, which has 20GB root storage while it is almost used up as shown by df -hT:

root@n8:/var/log# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs     3.1G  8.8M  3.1G   1% /run
/dev/nvme0n1p1 ext4       20G   20G  1.5M 100% /
tmpfs          tmpfs      16G     0   16G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/loop0     squashfs   88M   88M     0 100% /snap/core/5328
/dev/loop2     squashfs   17M   17M     0 100% /snap/amazon-ssm-agent/734
/dev/loop1     squashfs   88M   88M     0 100% /snap/core/5548
/dev/loop3     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/295
/dev/loop4     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/495
/dev/loop5     squashfs   87M   87M     0 100% /snap/core/5145
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1000

In the AWS Volume management console, we increased the size of the root partition disk to 100GB. Now, let’s look at the steps to add the storage to the root filesystem (/).

First, use growpart to grow the partition size. Here, the root partition is the partition number 1 of disk /dev/nvme0n1, we run the command:

root@n8:/var/log# growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2048 old: size=41940959 end=41943007 new: size=209713119,end=209715167

From the STDOUT, the size has been changed.

However, the filesystem size is still the same although the partition size changed. We need to update the filesystem to use the more storage capacity available.

We can sue the resizee2fs command as follows.

root@n8:/var/log# resize2fs /dev/nvme0n1p1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/nvme0n1p1 is now 26214139 (4k) blocks long.

After it executed successfully, we can check the filesystem size by df -hTgain.

root@n8:/var/log# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs     3.1G  724K  3.1G   1% /run
/dev/nvme0n1p1 ext4       97G   20G   78G  20% /
tmpfs          tmpfs      16G     0   16G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/loop0     squashfs   88M   88M     0 100% /snap/core/5328
/dev/loop2     squashfs   17M   17M     0 100% /snap/amazon-ssm-agent/734
/dev/loop1     squashfs   88M   88M     0 100% /snap/core/5548
/dev/loop3     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/295
/dev/loop4     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/495
/dev/loop5     squashfs   87M   87M     0 100% /snap/core/5145
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1000

Now you can see the new root partition size is around 100GB now. Cheers.

Similar Posts

  • Sybil Attack 101

    Distributed systems, such as peer-to-peer networks, , and other decentralized platforms, have become increasingly popular due to their potential to offer more robust, scalable, and secure solutions. However, these systems face unique challenges and vulnerabilities, one of which is the Sybil attack. Named after the psychiatric case study “Sybil,” in which a person exhibits multiple…

  • |

    Set up and Run Linux Xen Dom0 and DomU VMs

    The Xen solutions including installing and configuring Dom0 and DomU are summarized here. LVM volumes as backing for DomU’s file system is an appealing solution to Xen VBD. LVM volumes can dynamically grow/shrink and snapshot. These features make it simple and fast to duplicate DomU and adding storage to DomU. LVM backed DomU is recommended….

  • |

    Hadoop MapReduce Tutorials

    Here is a list of tutorials for learning how to write MapReduce programs on Hadoop, the opensource MapReduce implementation with HDFS. MapReduce Tutorials The official tutorial on Hadoop MapReduce framework: http://hadoop.apache.org/docs/r1.0.4/mapred_tutorial.html. Yahoo! Hadoop Tutorial A comprehensive tutorial on Hadoop from Yahoo! Developer Network: http://developer.yahoo.com/hadoop/tutorial/. More about MapReduce To better understand the design behind MapReduce, it…

  • Fedora 中文字体设置

    Fedora 一直有中文字体难看的问题, 尤其是在英文环境中. 使用本文中的配置方法可以得到令人满意的中文效果. 此方案中使用字体都为开源且在Fedora源中自带. 此方案对 Fedora 9 – 20 有效. 对于后续版本支持我会确认并更新此文章. 此方案对Gnome, KDE都有效. Firefox 中也有中文难看的问题, 后面会提到. 快速配置方法 如果你想马上配置好,请使用如下命令。此方法测试使用效果良好。 # yum install cjkuni-ukai-fonts cjkuni-uming-fonts # wget https://raw.githubusercontent.com/zma/config_files/master/others/local.conf \ -O /etc/fonts/local.conf 相关英文字体配置可以参考:Improving Fedora Font Rendering with Open Software and Fonts Only. Fedora 系统中文字体的配置方案 使用uming和ukai字体,即AR PL UMing CN等. 中文字体和等宽字体效果如图所示(点击看大图, Firefox 中文字体设置在后面会提到). 方法如下: 安装字体 首先安装这两个字体: cjkuni-ukai-fonts cjkuni-uming-fonts (在Fedora…

  • Installing Fedora 19, Error “you have not created a bootloader stage1 target device”

    Installing Fedora 19, Error “you have not created a bootloader stage1 target device” . It seems appear from Fedora 15: http://forums.fedoraforum.org/showthread.php?t=271743 This can be solved by adding noefi nogpt to the kernel parameters when booting the Linux for installation in grub as follows. Note: the “_” between nogpt and root is the cursor, not the…

Leave a Reply

Your email address will not be published. Required fields are marked *