You are not logged in.

#1 2020-02-02 10:02:40

jakub
Member
Registered: 2013-09-14
Posts: 151

[SOLVED] Wo to extract swap partition from unallocated ext4fs space?

I have unallocated (but partitioned into root ext4fs partition) space for swap. How to shrink a partition and take out the unallocated space to turn it into swap? I assume it's possible to do it without data loss.

https://i.imgur.com/CeOxhvP.png

➜  ~ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238,5G  0 disk 
├─sda1   8:1    0   200M  0 part 
├─sda2   8:2    0   500M  0 part 
├─sda3   8:3    0    76G  0 part /
└─sda5   8:5    0 161,8G  0 part 

➜  ~ df -h                          
Filesystem      Size  Used Avail Use% Mounted on
dev             7,8G     0  7,8G   0% /dev
run             7,8G  1,7M  7,8G   1% /run
/dev/sda3        59G   46G   11G  81% /
tmpfs           7,8G  147M  7,7G   2% /dev/shm
tmpfs           7,8G     0  7,8G   0% /sys/fs/cgroup
tmpfs           7,8G  720K  7,8G   1% /tmp
tmpfs           1,6G   12K  1,6G   1% /run/user/1000

moderator edit -- replaced oversized image with link.
Pasting pictures and code

Last edited by 2ManyDogs (2020-02-02 14:17:58)

Offline

#2 2020-02-02 10:36:03

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,397

Re: [SOLVED] Wo to extract swap partition from unallocated ext4fs space?

Your partition should be unmounted, do it from a live disk, it's trivial to do with gparted, otherwise https://wiki.archlinux.org/index.php/Pa … ning_tools

Last edited by V1del (2020-02-02 10:40:34)

Offline

#3 2020-02-02 11:00:53

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Wo to extract swap partition from unallocated ext4fs space?

Or just use a swap file instead.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#4 2020-02-02 11:16:10

jakub
Member
Registered: 2013-09-14
Posts: 151

Re: [SOLVED] Wo to extract swap partition from unallocated ext4fs space?

I followed your instruction and did it with gparted. I didn't expect that this way is "safe" as gparted does not visually distinguish free space on partition from unallocated space on file system. So now I assume even if I would like to take more from /dev/sda3 - it would be still safe (by saying "more" I mean taking not only unallocated space in file system = 16GB, but let's say 2GB of free space on that partition).
Thank you for quick reaction. Marking as solved.

➜  ~ swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/sda4 partition  16G   0B   -2

Offline

#5 2020-02-03 18:13:30

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,397

Re: [SOLVED] Wo to extract swap partition from unallocated ext4fs space?

Literally on the screenshot you posted, gray is unallocated, white is used by filesystem but free, yellow is used. Yes it would technically still be safe to take more.

Offline

Board footer

Powered by FluxBB