System Administration & Network Administration
centos partition disk-volume
Updated Sat, 10 Sep 2022 11:44:31 GMT

How to resize partition to maximum size on Debian 8?


My question is how to resize partition on Debian 8 without losing any data? I have 90 GB partition but my disk has 150 GB space on VPS server, so 50 GB is free and I want to add this 50 GB without losing any data, this is how it presents:

2

I've tried using resize2fs command but this didn't helped me because it shows me an error :

Filesystem is already n blocks long. Nothing to do!

I've already extended a partition on Debian 11 with resize2fs and everything was fine, here I don't know why but It doesn't want to work.

EDIT

enter image description here




Solution

According to your disk layout, you have to

(0) move away the swap partition to leave space for extending vda1; partition space must be contiguous. for this purpose:

  • disable swap, with swapoff /dev/vda2 (/dev/vda2 is your swap device file. Always check my arguments)
  • remove swap partition using parted /dev/vda rm partno where partno is the swap partition number according to parted /dev/vda, (it should 2 ?)
  • recreate the swap partition at the end of the disk, with /dev/parted /dev/vda mkpart -4G -1s. Negative numbers here are references from the end of the disk, meaning that the partition spans the last 4GiB of the disk (-1s means the partition ends at the last sector of disk, which is impossible as this will overwrite the secondary GPT header, so parted will modify the exact start/end and alignment of the partition (you'll be prompted). The partition will be created with the same number 2. So the device file will be named /dev/vda2. You have to check it.
  • re-enable the swap, with mkswap /dev/vda2 then swapon /dev/vda2
  • update the line having RESUME= in /etc/initramfs-tools/conf.d/resume if any. This line specifies the partition used for hibernation, and it is identified either with UUID=... or LABEL=.... You can find the swap partition UUID or label using blkid
  • update the line describing the swap partition in the fs table /etc/fstab. Just update UUID, label or partition number (depending on how the swap partition is designated in the file)

Once swap is moved away, you have to

(1) resize your root partition, which now has free space next to it. You can use command growpart (from package cloud-utils) which makes a partition use all the available space. If you cannot get this package on your system, you can do it manually with the subcommand resizepart of parted, telling only partition number (1?) and the END position (in blocks). Refer to parted /dev/vda to get expected END position. parted will prevent you from accidentally overwrite the swap.

(2) resize the filesystem (ext4 can be grown online, no need to unmount it) using resize2fs /dev/vda1

These steps will solve your issue, normally with no dataloss. However it is recommended to backup the most important data.







External Links

External links referenced by this document: