You are not logged in.

#1 2024-01-17 14:02:25

ntldr
Member
Registered: 2017-01-04
Posts: 67

Resizing main partition

Hello,

Is it possible to grow ext4 main partition without losing data on it in this case?

Device        Start       End   Sectors   Size Type
/dev/sda1      2048   4095999   4093952     2G EFI System
/dev/sda2   4096000  17827839  13731840   6.5G Linux swap
/dev/sda3  17827840 976773119 958945280 457.3G Linux filesystem

Basically I want to delete swap sda2 from the middle and grow sda3 a bit then recreate swap with 8gb. But I am thinking is that possible because all the data is at the beginning of sda3 so it would get more space on that disk a bit then shrink again to make the swap bigger.

Offline

#2 2024-01-18 14:21:02

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,044

Re: Resizing main partition

Growing to the left implies to move the partition, which is a somewhat risky process.
gparted abstracts that w/ a GUI and they also provide a live distro (you *will* have to do this offline, you cannot do this while any of the involved partitions is mounted anywhere)
Backups are mandatory still.

Sanity check: your idea is to remove sda2, grow sda3 and "recreate swap with 8gb", I assume you're talking about a swap file?
If the plan is to have more swap space, unless for hibernation, swap doesn't have to be continous and you can add a swap file to your existing partition in increase the total swap (eg. if you temporarily need more memory)
You can likewise use a dedicated swapfile only for hibernation that you can keep free from daily-swap-stuff.

Offline

#3 2024-01-18 18:30:35

ntldr
Member
Registered: 2017-01-04
Posts: 67

Re: Resizing main partition

Yeah my idea was to remove sda2 (swap) then grow sda3 to remove unallocated space from the middle then shrink sda3 enough to create 8GB swap partatition. I am just wondering is this safe to do it since all the data is at the beginning of sda3 partition so when the partition grows and shrinks 8GB what would happen.

Offline

#4 2024-01-18 18:36:14

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,044

Re: Resizing main partition

Growing a partition to the right is save.
Shrinking a partition is not.
Growing a partition to the left is not a thing. You've to move it and then grow it to the right.
Moving a partition is as risky as it gets.

What you want to do is move the partition and then shrink it by 2GB, that's two opportunities to fudge it.
Which is why I highly recommend to use the GUI abstraction here (if you want to do this at all, the benefit seems the 2GB additional swap) - it's less likely to screw up than you.
And you still better have a backup before you start!

Offline

#5 2024-01-19 10:32:30

ntldr
Member
Registered: 2017-01-04
Posts: 67

Re: Resizing main partition

https://pixeldrain.com/u/sq5v5thL

Just to be clear and visualize this partition better here's a screenshot from gparted. Yes I know it's not gparted live disk how I would do it but I can't upload screenshot from there to here.

Buut from what you are telling me sounds like it's not a good idea to risk it. Of course I'd shrink sda3 partition from the right side where there isn't data and create 8GB swap partition from there but I am worried how the partition would react to growing a bit first then shrinking down. As the swap partatition is in the middle and all the data on the left side where it needs to grow.

Offline

#6 2024-01-19 10:43:13

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,044

Re: Resizing main partition

You're not growing and shrinking anything - you're shrinking the partition by ~2GB and then move it 6GB to the left.
Unless you get impatient and push the power button but let gparted do its job, it's very likely to succeed w/o breakage.
But it's still a very good idea to have a backup when doing this.

Whether it's worth the effort is for you to decide? Why do you (think you) need the swap partition to be 2GB bigger?

Offline

Board footer

Powered by FluxBB