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:
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
Best Answer
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:swapoff /dev/vda2
(/dev/vda2
is your swap device file. Always check my arguments)parted /dev/vda rm partno
where partno is the swap partition number according toparted /dev/vda
, (it should 2 ?)/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, soparted
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.mkswap /dev/vda2
thenswapon /dev/vda2
RESUME=
in/etc/initramfs-tools/conf.d/resume
if any. This line specifies the partition used for hibernation, and it is identified either withUUID=...
orLABEL=...
. You can find the swap partition UUID or label usingblkid
/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 packagecloud-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 subcommandresizepart
ofparted
, telling only partition number (1?) and the END position (in blocks). Refer toparted /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.