Btrfs: Difference between revisions

Onny (talk | contribs)
Restructure page
Onny (talk | contribs)
Tutorial on how to convert system partition to Btrfs
Line 289: Line 289:
</syntaxhighlight >
</syntaxhighlight >


=== Convert Ext3/Ext4 system partition to Btrfs ===
<div style="border: 1px solid #D33; background: #FFEBEB; padding: 30px; border-radius: 5px; margin: 10px 0px; display: flex; align-items: center;">
    <div style="color: #D33; font-size: 40px; margin-right: 15px; background: #FFEBEB; display: flex; line-height: 0;  align-items: center;">⚠</div>
    <div style="color: #D33; font-size: 15px; font-style: normal; font-weight: 400; line-height: normal; text-align: left;">Note that migrating your existing root filesystem can cause data loss or make your system unbootable. Make sure to backup the partition or your files. Proceed only if you know what you're doing!</div>
</div>
To convert the existing filesystem (Ext3/4) to Btrfs, boot into a NixOS live system and run following command<syntaxhighlight lang="sh">
fsck -f /dev/sdXY
btrfs-convert /dev/sdXY
</syntaxhighlight>Replace the device path with the target partition. Converting larger filesystems can take a long time.
Next, mount the converted filesystem and chroot into it<syntaxhighlight lang="sh">
mount /dev/sdXY /mnt
nixos-enter --root /mnt
</syntaxhighlight>Replace the partition UUID with the new one, which can be obtained using the command <code>blkid</code>, in <code>/etc/nixos/hardware-configuration.nix</code> and also change the filesystem to <code>btrfs</code>.<syntaxhighlight lang="nix">
  fileSystems."/" =
    { device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
      fsType = "btrfs";
    };
</syntaxhighlight>Apply the changes<syntaxhighlight lang="sh">
nixos-rebuild boot
</syntaxhighlight>In case Grub bootloader is used and it doesn't get reinstalled correctly, you can run following command inside chroot<syntaxhighlight lang="sh">
grub-install /dev/sdX
</syntaxhighlight>
[[Category: Configuration]]
[[Category: Configuration]]
[[Category:Filesystem]]
[[Category:Filesystem]]