Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Resizing btrfs for swap
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
ct85711
Veteran
Veteran


Joined: 27 Sep 2005
Posts: 1696

PostPosted: Mon Nov 06, 2017 3:26 am    Post subject: Resizing btrfs for swap Reply with quote

I am unsure on what I should do, so I am hoping for some advice. I am needing to either make a swap file or swap partition for my system (already setup). The issue I am encountering, is the only partition I have room to allocate for the swap, but it is a btrfs raid 5 partition (of 3 drives). Now I am aware, having swap on a btrfs fs is unsafe. I am at the point that I don't know if I can or how I can shrink a btrfs subvolume/device (I already shrunk the fs, so that is taken care of) or is it better to just wipe the btrfs and recreate the partion to ext4 (and create a swap partition).

Code:
/dev/sda1               /boot/efi       vfat            noatime         1 2
/dev/sdc1               /               ext4            discard,noatime         0 1
/dev/sdc2               /home           btrfs           defaults        0 0

Note: /home is composed of /dev/sda2, dev/sdc2, and /dev/sdb1; sdb1 is the desired device that needs to be shrunk. (there is more than plenty of free space available, as in <25% is used).

Sadly, the root partition is too constrained on space to consider allocating space on that partition (I am frequently having to clear by space regularly as it is).
The raid 5 is setup only in btrfs and not through lvm, nor am I worried about keeping the raid 5 setup. I made that setup over 3 years ago for fun and have no requirement on sticking with btrfs any fashion.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5761

PostPosted: Mon Nov 06, 2017 5:29 am    Post subject: Reply with quote

Look up the device ID of your sdb1 (the first number on the bottom line of this command's output):
Code:
 # btrfs filesystem show /home/
[...]
        devid    1 size xxx.yyGiB used [...]

Use that to shrink it by 1.5-2x how much space you want for swap (it doesn't matter that this number is sloppy):
Code:
 # btrfs filesystem resize $devid:-4G /home/

Run fdisk or cfdisk to shrink the end of that partition (by the amount you actually want to use for swap).
Create the swap partition, then verify it shows up in /dev/. You may need to use hdparm -z if fdisk doesn't refresh it automatically, but it should.
After that, fix the btrfs so it's not wasting space:
Code:
 # btrfs filesystem resize $devid:max /home/
Back to top
View user's profile Send private message
nokilli
Apprentice
Apprentice


Joined: 25 Feb 2004
Posts: 195

PostPosted: Mon Nov 06, 2017 8:59 am    Post subject: Re: Resizing btrfs for swap Reply with quote

ct85711 wrote:
Now I am aware, having swap on a btrfs fs is unsafe.

The bigger issue is putting swap on a raid5. It's wrong on several levels.

Sometimes you just have to backup the system, reformat, and restore. You can still have the raid5. Just create standard partition tables for each disk, make one partition for swap (keeping in mind you'll have three and that you can have multiple swap partitions so they can be small) and the other for the raid array.
_________________
Today is the first day of the rest of your Gentoo installation.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum