Merging unallocated space with root btrfs

Hello Garuda users.

I spent almost 2 days with this problem. I would like to merge my root partition with unallocated partition. Unallocated partition has been taken from win partition. If I remove swap file I am afraid I wont be able to use hibernation anymore which is very importatant. I can not find proper way how to move unallocated space behind my garuda partition so I can extend it. As a new user I cant post image how my gparted looks like.
I tried from live usb but also but each try was failure

─λ garuda-inxi
System:
Kernel: 6.2.2-2-cachyos-bore arch: x86_64 bits: 64 compiler: gcc v: 12.2.1
parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-cachyos-bore
root=UUID=5099f3fa-e09c-462d-9bcf-1364eb3c94d7 rw [email protected]
quiet quiet splash rd.udev.log_priority=3 vt.global_cursor_default=0
resume=UUID=4322e3c1-eaa9-4076-9fd4-08600b6e0f66 loglevel=3 ibt=off
Desktop: KDE Plasma v: 5.27.2 tk: Qt v: 5.15.8 wm: kwin_x11 vt: 1 dm: SDDM
Distro: Garuda Linux base: Arch Linux
Machine:
Type: Laptop System: Micro-Star product: Katana GF66 12UD v: REV:1.0
serial: <superuser required> Chassis: type: 10 serial: <superuser required>
Mobo: Micro-Star model: MS-1584 v: REV:1.0 serial: <superuser required>
UEFI: American Megatrends LLC. v: E1584IMS.108 date: 01/07/2022
Battery:
ID-1: BAT1 charge: 49.1 Wh (100.0%) condition: 49.1/52.0 Wh (94.5%)
volts: 12.9 min: 11.4 model: MSI BIF0_9 type: Li-ion serial: N/A
status: full
Device-1: hidpp_battery_0 model: Logitech Wireless Mouse M215 2nd Gen
serial: <filter> charge: 100% (should be ignored) rechargeable: yes
status: discharging
CPU:
Info: model: 12th Gen Intel Core i7-12700H bits: 64 type: MST AMCP
arch: Alder Lake gen: core 12 level: v3 note: check built: 2021+
process: Intel 7 (10nm ESF) family: 6 model-id: 0x9A (154) stepping: 3
microcode: 0x429
Topology: cpus: 1x cores: 14 mt: 6 tpc: 2 st: 8 threads: 20 smt: enabled
cache: L1: 1.2 MiB desc: d-8x32 KiB, 6x48 KiB; i-6x32 KiB, 8x64 KiB
L2: 11.5 MiB desc: 6x1.2 MiB, 2x2 MiB L3: 24 MiB desc: 1x24 MiB
Speed (MHz): avg: 2417 high: 4447 min/max: 400/4600:4700:3500 scaling:
driver: intel_pstate governor: performance cores: 1: 2700 2: 2017 3: 2523
4: 1231 5: 926 6: 1717 7: 3587 8: 1248 9: 501 10: 2774 11: 4447 12: 4295
13: 2700 14: 2700 15: 2700 16: 2700 17: 1486 18: 2700 19: 2700 20: 2700
bogomips: 107520
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Vulnerabilities: <filter>
Graphics:
Device-1: Intel Alder Lake-P Integrated Graphics vendor: Micro-Star MSI
driver: i915 v: kernel arch: Gen-12.2 process: Intel 10nm built: 2021-22+
ports: active: eDP-1 empty: HDMI-A-1 bus-ID: 00:02.0 chip-ID: 8086:46a6
class-ID: 0300
Device-2: NVIDIA GA107M [GeForce RTX 3050 Ti Mobile]
vendor: Micro-Star MSI driver: nvidia v: 525.89.02
alternate: nouveau,nvidia_drm non-free: 525.xx+
status: current (as of 2023-02) arch: Ampere code: GAxxx
process: TSMC n7 (7nm) built: 2020-22 pcie: gen: 1 speed: 2.5 GT/s
lanes: 8 link-max: gen: 4 speed: 16 GT/s lanes: 16 bus-ID: 01:00.0
chip-ID: 10de:25a0 class-ID: 0302
Device-3: Bison HD Webcam type: USB driver: uvcvideo bus-ID: 2-6:3
chip-ID: 5986:211b class-ID: 0e02
Display: x11 server: X.Org v: 21.1.7 with: Xwayland v: 22.1.8
compositor: kwin_x11 driver: X: loaded: modesetting,nvidia unloaded: nouveau
alternate: fbdev,intel,nv,vesa dri: iris gpu: i915 display-ID: :0
screens: 1
Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.00x11.22")
s-diag: 582mm (22.93")
Monitor-1: eDP-1 model: AU Optronics 0xaf90 built: 2020 res: 1920x1080
hz: 144 dpi: 142 gamma: 1.2 size: 344x193mm (13.54x7.6") diag: 394mm (15.5")
ratio: 16:9 modes: 1920x1080
API: OpenGL v: 4.6 Mesa 22.3.6 renderer: Mesa Intel Graphics (ADL GT2)
direct-render: Yes
Audio:
Device-1: Intel Alder Lake PCH-P High Definition Audio
vendor: Micro-Star MSI driver: sof-audio-pci-intel-tgl
alternate: snd_hda_intel,snd_sof_pci_intel_tgl bus-ID: 00:1f.3
chip-ID: 8086:51c8 class-ID: 0401
Sound API: ALSA v: k6.2.2-2-cachyos-bore running: yes
Sound Server-1: PulseAudio v: 16.1 running: no
Sound Server-2: PipeWire v: 0.3.66 running: yes
Network:
Device-1: Intel Alder Lake-P PCH CNVi WiFi driver: iwlwifi v: kernel
bus-ID: 00:14.3 chip-ID: 8086:51f0 class-ID: 0280
IF: wlo1 state: up mac: <filter>
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
vendor: Micro-Star MSI driver: r8169 v: kernel pcie: gen: 1 speed: 2.5 GT/s
lanes: 1 port: 3000 bus-ID: 04:00.0 chip-ID: 10ec:8168 class-ID: 0200
IF: enp4s0 state: down mac: <filter>
IF-ID-1: anbox0 state: down mac: <filter>
Bluetooth:
Device-1: Intel AX201 Bluetooth type: USB driver: btusb v: 0.8
bus-ID: 2-10:4 chip-ID: 8087:0026 class-ID: e001
Report: bt-adapter ID: hci0 rfk-id: 0 state: up address: <filter>
Drives:
Local Storage: total: 476.94 GiB used: 49.72 GiB (10.4%)
SMART Message: Unable to run smartctl. Root privileges required.
ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Micron model: 2450 MTFDKBA512TFK
size: 476.94 GiB block-size: physical: 512 B logical: 512 B speed: 63.2 Gb/s
lanes: 4 type: SSD serial: <filter> rev: V5MA010 temp: 33.9 C scheme: GPT
Partition:
ID-1: / raw-size: 87.39 GiB size: 87.39 GiB (100.00%)
used: 49.72 GiB (56.9%) fs: btrfs dev: /dev/nvme0n1p8 maj-min: 259:8
ID-2: /boot/efi raw-size: 512 MiB size: 511 MiB (99.80%)
used: 612 KiB (0.1%) fs: vfat dev: /dev/nvme0n1p6 maj-min: 259:6
ID-3: /home raw-size: 87.39 GiB size: 87.39 GiB (100.00%)
used: 49.72 GiB (56.9%) fs: btrfs dev: /dev/nvme0n1p8 maj-min: 259:8
ID-4: /var/log raw-size: 87.39 GiB size: 87.39 GiB (100.00%)
used: 49.72 GiB (56.9%) fs: btrfs dev: /dev/nvme0n1p8 maj-min: 259:8
ID-5: /var/tmp raw-size: 87.39 GiB size: 87.39 GiB (100.00%)
used: 49.72 GiB (56.9%) fs: btrfs dev: /dev/nvme0n1p8 maj-min: 259:8
Swap:
Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default)
ID-1: swap-1 type: partition size: 15.62 GiB used: 0 KiB (0.0%)
priority: -2 dev: /dev/nvme0n1p7 maj-min: 259:7
ID-2: swap-2 type: zram size: 15.33 GiB used: 512 KiB (0.0%) priority: 100
dev: /dev/zram0
Sensors:
System Temperatures: cpu: 67.0 C mobo: N/A
Fan Speeds (RPM): N/A
Info:
Processes: 440 Uptime: 27m wakeups: 311 Memory: 15.33 GiB
used: 4.88 GiB (31.9%) Init: systemd v: 253 default: graphical
tool: systemctl Compilers: gcc: 12.2.1 Packages: pm: pacman pkgs: 1990
libs: 527 tools: octopi,paru,yay Shell: fish v: 3.6.0 default: Bash
v: 5.1.16 running-in: konsole inxi: 3.3.25
Garuda (2.6.15-1):
System install date:     2023-03-02
Last full system update: 2023-03-04
Is partially upgraded:   No
Relevant software:       snapper NetworkManager mkinitcpio nvidia-dkms
Windows dual boot:       Probably (Run as root to verify)
Failed units:            anbox-container-manager.service systemd-networkd-wait-online.service updatedb.timer

You will have to update /etc/fstab with the new UUID if you move your swap file, there is no way around that. You are going to have to update this file with the new UUID of your other disk anyway though. It shouldn't be difficult to preserve your ability to hibernate.

No problem, post sudo parted -l.

2 Likes
Model: Micron_2450_MTFDKBA512TFK (nvme)
Disk /dev/nvme0n1: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size    File system     Name                          Flags
1      1049kB  316MB  315MB   fat32           EFI system partition          boot, esp
2      316MB   450MB  134MB                   Microsoft reserved partition  msftres
3      450MB   166GB  166GB   ntfs            Basic data partition          msftdata
6      376GB   376GB  537MB   fat32                                         boot, esp
7      376GB   393GB  16,8GB  linux-swap(v1)                                swap
8      393GB   487GB  93,8GB  btrfs
4      487GB   488GB  944MB   ntfs            Basic data partition          hidden, diag
5      488GB   512GB  24,1GB  ntfs            Basic data partition          hidden, diag


Model: Unknown (unknown)
Disk /dev/zram0: 16,5GB
Sector size (logical/physical): 4096B/4096B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system     Flags
1      0,00B  16,5GB  16,5GB  linux-swap(v1)

Nice, you actually have plenty of space to use btrfs replace, so you don't even need to boot to the live system to do this.

:warning: First, back up your data. Whenever you are deleting partitions you should take a backup of any important data in case something goes wrong. If you are thinking about skipping this step I urge you to reconsider. :warning:

When you are ready, turn off the swap partition so you can delete it.

swapoff /dev/nvme0n1p7

Then delete all those partitions you don't need. Using Gparted is fine if that is what you are comfortable with.

You should not delete p1 (your EFI partition) or p8 (your Btrfs partition). Delete the other partitions (2 3 4 5 6 7), including the swap partition, unless you need those NTFS partitions for some reason.

Next, make a new swap partition, and a second Btrfs partition in the free space between the EFI partition and p8. I'm going to assume the swap partition will be p2 and the new Btrfs partition will be p3 because that will allow your Btrfs partition to take up the rest of the disk, but obviously the decision is yours how you want to set it up.

Find the UUID of the (new) swap partition by running sudo blkid. Edit your Grub config file:

sudo micro /etc/default/grub

Find this line:

resume=UUID=4322e3c1-eaa9-4076-9fd4-08600b6e0f66

Change the UUID to match your new one you found when you ran sudo blkid.

Now, move p8 to p3 with Btrfs replace.

sudo btrfs replace start 1 /dev/nvmeon1p3 /

Check the status while it runs if you want by running this command:

btrfs replace status /

When it's done it will just exit without saying anything. It's normally pretty quick. Take a look at lsblk to confirm everything looks correct. Then, you can open up Gparted, delete p8, and extend p3 to the end of the disk.

Next, extend your Btrfs filesystem to fill up the partition:

sudo btrfs filesystem resize max /

Finally, run lsblk -f and put the updated UUIDs in your fstab file.

sudo micro /etc/fstab

Moving the partition with btrfs replace won't change the partition's UUID, but resizing it might. If you don't get your fstab file exactly right, it might prevent your system from booting so double-check and be careful!

That's about it, I recommend runnung a btrfs balance afterward which you can do right from the Btrfs Assistant GUI.


EDIT:

You know what? I typed that whole thing because I took this to mean you are reclaiming the space Windows is using:

Reading through it again, I am realizing that was probably a mistaken impression and you actually just want to use the 210GB between p3 and p6:

Sorry about that, I just got the idea in my head and the whole thing got away from me. :face_with_peeking_eye:

Many of those steps are actually still valid. Obviously don't delete all your partitions if you are keeping Windows, but deleting and re-creating the swap partition is still correct.

Also, since the unallocated space is larger than your Btrfs partition you can still use btrfs replace to move the partition back so you can resize it (you can't resize the partition "to the left"). Just put a new Btrfs partition in the unallocated space and make that the target partition.

One mystery remains:

You have two fat32 partitions that both have boot and esp flags. Do you have two EFI partitions set up on the same disk? Or what is going on with that?

2 Likes

Thank you Bluish!
I managed to merge partitions. Had some issues with grub but no big deal.
Yea 2 FAT32 are because I use only linux and kids use win so I change boot in BIOS and there is no option to switch to garuda for them unless they go inside BIOS again.

Topic can be closed :slight_smile:

I'm glad to hear it worked out. :slightly_smiling_face:

Is this the setup you want? If you wish they can share an EFI partition, then you can boot to either one with Grub (no need to enter the BIOS menu to switch).

If I use grub I have both Garuda and Win. If I use only fat32 for win there is only option for the win there. That is what I wish to have. This way nobody knows I have linux when laptop is rebooted when Im not at home. Protection against my kids lol.

Nice, a secret Linux installation. :shushing_face:

Go ahead and mark the solution and the topic will automatically close in two days.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.