Score:2

How to Root volume partition without losing the data

cn flag

We have this scenario : I to increase the disk space of one of our VM,

Disk details :

root@Test-01:~# blkid
/dev/vda2: UUID="0eae0eb4-92ed-45ec-aa99-6d606f17e70a" TYPE="swap" PARTUUID="06cf22a2-02"
/dev/vda1: UUID="b5e223df-9f41-4e4c-aa8d-e4529fa28424" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="06cf22a2-01"


root@Test-01:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    254:0    0  150G  0 disk
├─vda1 254:1    0   46G  0 part /
└─vda2 254:2    0  104G  0 part [SWAP]
As its a Not LVM I have tried the below , but its wont work

parted /dev/vda resizepart 1 100%

resize2fs /dev/vda1

root@Test-01:~# parted /dev/vda print free
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
        1024B   1049kB  1048kB           Free Space
 1      1049kB  49.4GB  49.4GB  primary  ext4
 2      49.4GB  161GB   112GB   primary  linux-swap(v1)

we need the swap to go in the last in memory block, swap is in between

we have 112GB primary Linux-swap(v1)

now we want to increase first partition end block to 156 instead of 49.4 gb

now we want to decrease 2nd partition start block to 156 instead of 49.4 gb

we want to increase the root volum with safe option without loosing any data ,

Is Performing the resize operation with parted alone is risky and could lead to data loss? So below doesn't look like safe for me.

sudo parted /dev/vda resizepart 1 100%
sudo parted /dev/vda move 2 100%

This is a virtual machine not a physical machine we are not a not able to use usb or cd drive there , its a Linux Debian machine .

what is the best way to perform this without losing the root volume data , any help would be apricated .

Jaromanda X avatar
ru flag
not sure how the parted commands you proposed will do anything - since there is no room for part 1 to grow
anx avatar
fr flag
anx
Are you certain that this is the machine you want to continue with? Possibly it has been setup with use cases in mind that are *wildly* different from the swap size you are aiming for now, or some severe disregard of the release notes for the OS installed. Both might cause trouble for its future maintenance in places yet to be revealed.
Score:0
fr flag
anx

The best way to not lose the root volume data is to use this excuse to do a complete backup restoration, on a freshly setup, unambiguously separate machine and the just switch over to that one when it turns out your backups are fine.


If you actually wanted to work on a live machine... just order the steps according to their dependencies.

Online add/remove of partition is supported. Online ext filesystem growing is supported. Partition table reloading is not fully supported for active filesystems, but costs only a reboot.

  1. verify your backup restoration routine
  2. comment out swap entry in fstab
  3. systemctl reload
  4. swapoff
  5. remove swap partition
  6. extend root partition into now unused space
  7. reboot as needed
  8. resize2fs /dev/vda1
  9. recreate swap partition (at new position)
  10. mkswap /dev/vda2
  11. update / re-enable swap entry in fstab
  12. reboot once more to verify automatic swap activation work again
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.