How to resize the root partition after disk upgrade

My YunoHost server

Hardware: VM running inside Proxmox
YunoHost version: 4.2.8.3
I have access to my server : Through SSH | through the webadmin |
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

I would to like to resize the root partition after a disk upgrade (increased size from 30 to 40 GiB). I have ran out of space and cannot install new apps, do backups or even do updates.

I have found a very similar post in the forum, but the solution does not work for me: https://forum.yunohost.org/t/added-extra-diskspace-is-not-used/12537/9

ROOT_DEV=$(findmnt / -o source -n)
resize2fs $ROOT_DEV

Here the info from the command line:

root@yuno:/home/admin# fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4e9597bd

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 62916607 62914560 30G 83 Linux
/dev/sda2 62918654 67106815 4188162 2G 5 Extended
/dev/sda5 62918656 67106815 4188160 2G 82 Linux swap / Solaris
root@yuno:/home/admin# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.9G 0 2.9G 0% /dev
tmpfs 597M 16M 581M 3% /run
/dev/sda1 30G 24G 4.2G 86% /
tmpfs 3.0G 36K 3.0G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.0G 0 3.0G 0% /sys/fs/cgroup
tmpfs 597M 0 597M 0% /run/user/1007

Identify the root partition

findmnt / -o source -n

You should get something like /dev/sda1 or /dev/vda2. If you receive /dev/mapper/something, you probably use lvm, and this tutorial won’t be enough.

Display the partition table with some information

root@vps:~# parted /dev/vda
GNU Parted 3.2
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                         
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  5369MB  5368MB  primary  ext4         boot

Resize the partition

(parted) resizepart
Partition number? 1    << the number of the partition you want resize
Warning: Partition /dev/vda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End?  [5369MB]? 100%    << 100% means we want use all the space available

Check the change has been done correctly

(parted) print                      
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  6442MB  6441MB  primary  ext4         boot

(parted) q                
Information: You may need to update /etc/fstab.

Resize the file system

root@vps:~# resize2fs /dev/vda1                        
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vda1 is now 1572608 (4k) blocks long.
2 Likes

Thank you for the quick reply and this very detailed solution. I got stuck at the “resize” part of the instructions, see below the details, I do not know how to proceed… it seems there is an overlap… parted is not seeing the extra disk space over which extend the root partition or the extended partition/swap is getting on the way?

root@yuno:/home/admin# findmnt / -o source -n
/dev/sda1
root@yuno:/home/admin# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 32.2GB 32.2GB primary ext4 boot
2 32.2GB 34.4GB 2144MB extended
5 32.2GB 34.4GB 2144MB logical linux-swap(v1)

(parted) resizepart
Partition number? 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes
End? [32.2GB]? 100%
Error: Can’t have overlapping partitions.
(parted)

It’s because you have the swap partition in the middle of your disk (between 32.2GB and 34.4GB).

So you probably should turn off the swap with swapoff --all and delete this extended partition before.

I see, that is what I thought… is it not a bad idea to delete the swap partition? do I need it? can it be re-built later on? and how do I delete it anyway? with parted?

The swap partition could be replace by a swapfile if you need it. https://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/

I guess it’s possible to delete your swap patition with parted (see the help command when you are in parted).

thank you, i deleted the swap partition and your instructions solved my problem. cheers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.