You are not logged in.

#1 2016-12-30 14:44:39

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Removing SWAP partition and give its capacity to filesystem's one

I've made a 5gb useless (for me) SWAP partition during the installation of Arch. I'm quoting ArchWiki, which writes this:

Swap space is generally recommended for users with less than 1 GB of RAM

Since I never do hibernate and archey3 tells me I have 8/9 GB of RAM:

RAM: 980 MB / 7853 MB # 980 + 7853 = 8833 MB

that partition is superfluous and I want to delete it.

How can I remove the swap partition and give its capacity to filesystem's one, precisely?

Last edited by Dudl3y (2016-12-30 14:45:06)

Offline

#2 2016-12-30 15:01:59

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,806
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

what is your partition layout? what filesystems? LVM? LUKS?


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#3 2016-12-30 15:04:04

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Re: Removing SWAP partition and give its capacity to filesystem's one

ugjka wrote:

what is your partition layout? what filesystems? LVM? LUKS?

yep . sorry lsblk:
sr0     11:0    1  1024M  0 rom 
sda      8:0    0 223,6G  0 disk
├─sda2   8:2    0 218,1G  0 part /
├─sda3   8:3    0     5G  0 part [SWAP]
└─sda1   8:1    0   512M  0 part /boot

sda2 = filesystem . sda3 = useless swap partition to delete

Last edited by Dudl3y (2016-12-30 15:04:38)

Offline

#4 2016-12-30 15:09:41

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

Best way in my opinion is NOT to try resizing but to simply copy in the data from the partition (/dev/sda2 in your case) else where, then delete both the partition and the swap partition, then create a new partition to take up the space of the two and copy the data back over.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2016-12-30 15:13:18

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Re: Removing SWAP partition and give its capacity to filesystem's one

graysky wrote:

Best way in my opinion is NOT to try resizing but to simply copy in the data from the partition (/dev/sda2 in your case) else where, then delete both the partition and the swap partition, then create a new partition to take up the space of the two and copy the data back over.

Why not simply resizing?

Offline

#6 2016-12-30 15:17:10

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,806
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

you could delete the swap partition with something like parted and the run resize2fs on sda2 if it is ext* type of partition. Obviously you need some live iso to do this


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#7 2016-12-30 15:20:39

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Re: Removing SWAP partition and give its capacity to filesystem's one

graysky wrote:

Best way in my opinion is NOT to try resizing but to simply copy in the data from the partition (/dev/sda2 in your case) else where, then delete both the partition and the swap partition, then create a new partition to take up the space of the two and copy the data back over.

However I would still end up resizing.

@ugjka

ugjka wrote:

you could delete the swap partition with something like parted and the run resize2fs on sda2 if it is ext* type of partition. Obviously you need some live iso to do this

Can't I do it from virtual console?

Last edited by Dudl3y (2016-12-30 15:21:00)

Offline

#8 2016-12-30 15:42:27

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

Resizing is slow and pointless since you will have your data backup-ed anyway (you do have it backed up right)?  Save yourself the time and just repartiton, format, restore.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#9 2016-12-30 15:50:20

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Re: Removing SWAP partition and give its capacity to filesystem's one

graysky wrote:

Resizing is slow and pointless since you will have your data backup-ed anyway (you do have it backed up right)?  Save yourself the time and just repartiton, format, restore.

Best way in my opinion is NOT to try resizing but to simply copy in the data from the partition (/dev/sda2 in your case) else where, then delete both the partition and the swap partition, then create a new partition to take up the space of the two and copy the data back over.

If I copy my data from sda2 to sda4, sda2 should be resized. sda4 = remaining free space , another filesystem. If I remove then sda2 and sda3, sda4 must be resized again.
What do you mean?

Offline

#10 2016-12-30 16:04:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

Defintely have a backup before doing anything.  But as you are only expanding an ext4 filesystem, this should be very easy.

Use fdisk/parted/whatever to remove sda2 and sda3.  Recreate sda2 with the same starting position it previously had (this should be the default option), then give it the remaining size (this also should be the default option).

Then use resize2fs - on an ext4 partition when only expanding, this can even be done on a mounted filesystem.  You shouldn't need to copy anything anywhere nor should you need to restore from a backup if this is done properly (but again, defintely have a back up; if this is not done properly you will need to restore).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2016-12-30 16:54:53

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Removing SWAP partition and give its capacity to filesystem's one

@OP - My preference is not to resize but that is just my opinion.  You can try resizing but something could go wrong with the operation and thus cause you to restore a backup, so just cut out the middle man.  That said, my experiencing resizing was years ago using the gparted live CD and it took overnight to complete.  Hardware is faster now and I don't remember what the filesystem was that I was resizing.

To answer your quesiton about sda2 and sda4: backup means a totally separate disk ideally.  I didn't see an sda4 in your original output.  If you can partition to that and have enough to hold the contents of sda2 then yes.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#12 2016-12-30 17:02:05

Dudl3y
Member
Registered: 2016-12-28
Posts: 49

Re: Removing SWAP partition and give its capacity to filesystem's one

Thanks for your clear replies.

Trilby wrote:

Defintely have a backup before doing anything.  But as you are only expanding an ext4 filesystem, this should be very easy.

Use fdisk/parted/whatever to remove sda2 and sda3.  Recreate sda2 with the same starting position it previously had (this should be the default option), then give it the remaining size (this also should be the default option).

Then use resize2fs - on an ext4 partition when only expanding, this can even be done on a mounted filesystem.  You shouldn't need to copy anything anywhere nor should you need to restore from a backup if this is done properly (but again, defintely have a back up; if this is not done properly you will need to restore).

Regarding that, am I able to do the operation by virtual console? Do I really need a live iso?

Offline

#13 2016-12-31 15:56:58

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: Removing SWAP partition and give its capacity to filesystem's one

You can not remove partitions that are currently in use. As such, you need to boot a system that does not use the partition(s) in question.
This can be accomplished with a live ISO, a network boot or potentially a dual-boot OS if that OS does not share the target partition(s).

A resize should theoretically work from the system using the partition, though I've never actually done that myself so I can't guarantee it actually works.
In this case you'd have to take the resize route instead of the remove/recreate route; disable swap (don't forget to remove any fstab entries), remove the swap partition (since it's no longer used it can be removed) and resize the root partition.

Last edited by Omar007 (2016-12-31 16:02:30)

Offline

Board footer

Powered by FluxBB