Extending Root Filesystem on IBM Cloud Server with Debian: Step-by-Step Guide
In this article, we will guide you through the process of extending the root filesystem on an IBM Cloud server running Debian. The server in question has the following disk layout:
root@hanyg6266:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 20G 0 disk /
vda1 252:1 0 500M 0 part /boot
vda2 252:2 0 19.5G 0 part /
vdb 252:16 0 10G 0 disk
vdb1 252:17 0 10G 0 partStep 1: Verify Current Disk Usage
Before extending the root filesystem, it's essential to verify the current disk usage. Run the following command to check the disk usage:
root@hanyg6266:~# df -hStep 2: Create a New Partition
To extend the root filesystem, we need to create a new partition on the available disk space. In this example, we will create a new partition on /dev/vdb.
root@hanyg6266:~# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Step 3: Format the New Partition
Format the new partition with the ext4 filesystem:
root@hanyg6266:~# mkfs.ext4 /dev/vdb1Step 4: Mount the New Partition
Create a new directory to mount the new partition:
root@hanyg6266:~# mkdir /mnt/newdiskMount the new partition to the new directory:
root@hanyg6266:~# mount /dev/vdb1 /mnt/newdiskStep 5: Copy Data from the Root Filesystem
Copy the data from the root filesystem to the new partition:
root@hanyg6266:~# rsync -aAXv / /mnt/newdisk/ --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}Step 6: Update the Fstab File
Add the new partition to the /etc/fstab file:
/dev/vdb1 /mnt/newdisk ext4 defaults 0 0Step 7: Reboot the Server
Reboot the server to apply the changes:
root@hanyg6266:~# rebootStep 8: Verify the Filesystem
After rebooting, verify that the new partition is mounted and that the data has been copied correctly:
root@hanyg6266:~# df -hStep 9: Extend the Root Filesystem
Finally, extend the root filesystem to use the new partition:
root@hanyg6266:~# resize2fs /dev/vda2- Verify the current disk usage
- Create a new partition on the available disk space
- Format the new partition with the ext4 filesystem
- Mount the new partition to a new directory
- Copy the data from the root filesystem to the new partition
- Update the fstab file
- Reboot the server
- Verify the filesystem
- Extend the root filesystem to use the new partition
References
-
Book: Michael Jang, "Debian Linux Bible," 8th edition, Wiley, 2019.
-
Article: "How to Resize a Linux Partition," IBM Knowledge Center, https://www.ibm.com/support/pages/how-resize-linux-partition
-
Online Resource: "Resize2fs - Online Manual Pages," https://man7.org/linux/man-pages/man8/resize2fs.8.html