<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://wiki.devilplan.com/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://wiki.devilplan.com/feed.php">
        <title>Luci4 Wiki Blog - linux:btrfs</title>
        <description></description>
        <link>https://wiki.devilplan.com/</link>
        <image rdf:resource="https://wiki.devilplan.com/_media/wiki:logo.png" />
       <dc:date>2026-04-05T12:05:49+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://wiki.devilplan.com/linux:btrfs:compression"/>
                <rdf:li rdf:resource="https://wiki.devilplan.com/linux:btrfs:error-checks"/>
                <rdf:li rdf:resource="https://wiki.devilplan.com/linux:btrfs:hd-migration"/>
                <rdf:li rdf:resource="https://wiki.devilplan.com/linux:btrfs:trim"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://wiki.devilplan.com/_media/wiki:logo.png">
        <title>Luci4 Wiki Blog</title>
        <link>https://wiki.devilplan.com/</link>
        <url>https://wiki.devilplan.com/_media/wiki:logo.png</url>
    </image>
    <item rdf:about="https://wiki.devilplan.com/linux:btrfs:compression">
        <dc:format>text/html</dc:format>
        <dc:date>2025-06-08T13:56:11+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>compression</title>
        <link>https://wiki.devilplan.com/linux:btrfs:compression</link>
        <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;btrfs_compression_-_notes&quot;&gt;BTRFS Compression - Notes&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
It is possible to mount a Btrfs filesystem with different compression settings and change those settings as needed. Here’s how you can do it:
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Mounting with Compression:&lt;/strong&gt;
You can initially mount the Btrfs filesystem with a specified compression method. For example, to mount with maximum compression using &lt;code&gt;zlib&lt;/code&gt;, you can use:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=zlib /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;
&lt;hr /&gt;

&lt;p&gt;
&lt;strong&gt;Unloading Data:&lt;/strong&gt;
After moving some data, you can unmount the drive:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo umount /mnt/mybtrfs&lt;/pre&gt;
&lt;hr /&gt;

&lt;p&gt;
&lt;strong&gt;Remounting with Different Compression:&lt;/strong&gt;
You can then remount the Btrfs filesystem with a different compression option. For example, to use &lt;code&gt;zstd&lt;/code&gt; with maximum compression, you would do:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=zstd:9 /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;BTRFS Compression - Notes&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;btrfs_compression_-_notes&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;10-795&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;important_notes&quot;&gt;Important Notes&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Compression Options:&lt;/strong&gt; Btrfs supports several compression algorithms, such as &lt;code&gt;zlib&lt;/code&gt;, &lt;code&gt;zstd&lt;/code&gt;, and &lt;code&gt;lzo&lt;/code&gt;. Each has different performance and compression characteristics.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Per-File Compression:&lt;/strong&gt; Btrfs allows you to set compression options on a per-file basis, but when mounting, the specified option applies to new files created or copied to the mounted filesystem.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Existing Files:&lt;/strong&gt; Existing files will not be recompressed when you change the mount options. To recompress existing files with a new compression method, you would need to copy them again or use a command to explicitly change their compression.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Important Notes&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;important_notes&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;796-1433&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;example_of_changing_compression_on_existing_files&quot;&gt;Example of Changing Compression on Existing Files&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
To change the compression of existing files, you can use the following command:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs property set /mnt/mybtrfs/yourfile compress zstd:9&lt;/pre&gt;

&lt;p&gt;
Remember that existing files will not automatically change compression until you take explicit action to re-compress them.
&lt;/p&gt;
&lt;hr /&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Example of Changing Compression on Existing Files&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;example_of_changing_compression_on_existing_files&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1434-1771&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit4&quot; id=&quot;supported_compression_types_in_btrfs&quot;&gt;Supported Compression Types in Btrfs&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Supported Compression Types in Btrfs&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;supported_compression_types_in_btrfs&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1772-1811&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;no_compression&quot;&gt;No Compression&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=none /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;/etc/fstab line for mounting at boot:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,compress=none 0 0&lt;/pre&gt;

&lt;p&gt;
No compression is applied.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Fast read/write performance; no CPU overhead.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Disk space.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;No Compression&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;no_compression&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;1812-2114&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;zlib_compression&quot;&gt;Zlib Compression&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=zlib /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;fstab:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,compress=zlib 0 0&lt;/pre&gt;

&lt;p&gt;
Uses the Zlib algorithm, providing moderate compression ratios.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Good balance between compression ratio and speed.
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Higher CPU usage compared to no compression.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Zlib Compression&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;zlib_compression&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;2115-2463&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;lzo_compression&quot;&gt;LZO Compression&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=lzo /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;fstab:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,compress=lzo 0 0&lt;/pre&gt;

&lt;p&gt;
LZO is a fast, lightweight compression algorithm.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Very fast compression and decompression speeds.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Compression ratios are typically lower than Zlib.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;LZO Compression&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;lzo_compression&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:8,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;2464-2797&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;zstd_compression&quot;&gt;Zstd Compression&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=zstd /dev/sdX1 /mnt/mybtrfs
&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;fstab:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,compress=zstd 0 0&lt;/pre&gt;

&lt;p&gt;
Zstd (Zstandard) offers high compression ratios and good speed.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Can achieve better compression ratios than Zlib and LZO while maintaining decent speed.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Slightly higher CPU usage compared to LZO.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Zstd Compression&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;zstd_compression&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:10,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;2798-3177&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;zstd_with_level_options&quot;&gt;Zstd with Level Options&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o compress=zstd:9 /dev/sdX1 /mnt/mybtrfs
&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;fstab:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,compress=zstd:9 0 0&lt;/pre&gt;

&lt;p&gt;
You can specify compression levels (1-15) with Zstd for fine-tuning.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Flexibility in balancing compression ratio vs. speed.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Higher levels (e.g., 9 or above) may increase CPU usage significantly.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Zstd with Level Options&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;zstd_with_level_options&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:12,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;3178-3574&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit10&quot; id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;div class=&quot;table sectionedit11&quot;&gt;&lt;table class=&quot;inline&quot;&gt;
	&lt;tr class=&quot;row0&quot;&gt;
		&lt;td class=&quot;col0&quot;&gt; &lt;strong&gt;Compression Type&lt;/strong&gt; &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; &lt;strong&gt;Pros&lt;/strong&gt;                                    &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; &lt;strong&gt;Cons&lt;/strong&gt;                                   &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row1&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; No Compression    &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; Fast performance, no CPU overhead       &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; More disk space required                 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row2&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Zlib              &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; Good balance of speed and compression    &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; Higher CPU usage than no compression     &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row3&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; LZO               &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; Very fast compression/decompression      &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; Lower compression ratios                 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row4&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Zstd              &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; High compression with decent speed       &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; Slightly higher CPU usage than LZO       &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row5&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Zstd with Levels  &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; Flexible for tuning performance           &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; High levels increase CPU usage           &lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;3588-4243&amp;quot;} --&gt;&lt;hr /&gt;
&lt;dl class=&quot;file&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;https://wiki.devilplan.com/_export/code/linux:btrfs:compression?codeblock=14&quot; title=&quot;Download Snippet&quot; class=&quot;mediafile mf_cpp&quot;&gt;snippet.cpp&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code file cpp&quot;&gt;by&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
▖     ▘▖▖
▌ ▌▌▛▘▌▙▌
▙▖▙▌▙▖▌ ▌
&amp;nbsp;
written&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; a &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; ago. &lt;span class=&quot;me1&quot;&gt;Edited&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; June &lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2025&lt;/span&gt;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Summary&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;summary&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:14,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;3575-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="https://wiki.devilplan.com/linux:btrfs:error-checks">
        <dc:format>text/html</dc:format>
        <dc:date>2025-06-08T14:29:13+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>error-checks</title>
        <link>https://wiki.devilplan.com/linux:btrfs:error-checks</link>
        <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;btrfs_error_checks&quot;&gt;BTRFS Error Checks&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
To perform an error check on a Btrfs filesystem, you can use the &lt;code&gt;btrfs check&lt;/code&gt; command, which is designed for checking and repairing Btrfs filesystems. Here’s how to perform an error check:
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;BTRFS Error Checks&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;btrfs_error_checks&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;10-223&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;check_the_btrfs_filesystem_without_making_changes&quot;&gt;1. Check the Btrfs Filesystem without Making Changes:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Before performing any modifications, it&amp;#039;s always good to run the check in a &lt;strong&gt;read-only&lt;/strong&gt; mode to identify any issues.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs check --readonly /dev/sdX&lt;/pre&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;Replace &lt;code&gt;/dev/sdX&lt;/code&gt; with the actual device where your Btrfs filesystem is located (e.g., &lt;code&gt;/dev/sda1&lt;/code&gt;).&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;This command will scan for errors but won’t make any changes.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;1. Check the Btrfs Filesystem without Making Changes:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;check_the_btrfs_filesystem_without_making_changes&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;224-619&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;check_and_repair_the_btrfs_filesystem_if_needed&quot;&gt;2. Check and Repair the Btrfs Filesystem (if needed):&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
If you want to perform repairs, you can use the &lt;code&gt;--repair&lt;/code&gt; option. &lt;strong&gt;Be cautious with this option&lt;/strong&gt;, as it can result in data loss.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs check --repair /dev/sdX&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2. Check and Repair the Btrfs Filesystem (if needed):&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;check_and_repair_the_btrfs_filesystem_if_needed&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;620-855&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;checking_a_mounted_btrfs_filesystem&quot;&gt;3. Checking a Mounted Btrfs Filesystem:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
You can also check for errors in a mounted Btrfs filesystem by using the &lt;code&gt;btrfs scrub&lt;/code&gt; command. This scrubs the filesystem for data inconsistencies:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs scrub start /mountpoint&lt;/pre&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;Replace &lt;code&gt;/mountpoint&lt;/code&gt; with the actual mount point of the Btrfs filesystem (e.g., &lt;code&gt;/mnt&lt;/code&gt;).&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;This process runs in the background, checking the data and metadata blocks.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;To monitor the progress of a scrub operation, run:&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs scrub status /mountpoint&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;3. Checking a Mounted Btrfs Filesystem:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;checking_a_mounted_btrfs_filesystem&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;856-1363&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;log_scrub_results&quot;&gt;4. Log Scrub Results:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
After a scrub completes, you can view detailed information about any errors found or fixed using the &lt;code&gt;status&lt;/code&gt; command mentioned earlier.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;4. Log Scrub Results:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;log_scrub_results&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;1364-1528&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit6&quot; id=&quot;repairing_specific_issues&quot;&gt;5. Repairing Specific Issues:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
If you&amp;#039;re dealing with specific issues like a corrupt superblock or other particular problems, there are more advanced options, but these should be used with caution and preferably after backing up data. 
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;5. Repairing Specific Issues:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;repairing_specific_issues&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;1529-1770&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit7&quot; id=&quot;what_does_btrfs_scrub_do&quot;&gt;What Does `btrfs scrub` Do?&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The &lt;code&gt;btrfs scrub&lt;/code&gt; command in Btrfs is used to &lt;strong&gt;verify data integrity&lt;/strong&gt; by checking for any inconsistencies between data and metadata on disk. Here&amp;#039;s a more detailed breakdown of what it does:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Data Integrity Check&lt;/strong&gt;: The scrub operation systematically reads all data and metadata blocks of the Btrfs filesystem, verifying that the content matches the checksums that were stored when the data was written. This ensures that the data hasn&amp;#039;t been corrupted since it was last written.
&lt;br/&gt;
- &lt;strong&gt;Error Detection&lt;/strong&gt;: If the scrub finds any blocks that don’t match their checksum (i.e., corrupted data), it logs these errors. If redundancy (like a RAID setup) is used, it can attempt to fix the issue by reading the same data from another redundant copy (e.g., from a mirrored disk in RAID 1 or RAID 10) and automatically repairing the corrupted data.
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Involves All Devices&lt;/strong&gt;: On multi-device setups, like Btrfs RAID configurations, the scrub runs across all devices, checking for issues in any of the mirrored or striped copies of the data.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;What Does `btrfs scrub` Do?&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;what_does_btrfs_scrub_do&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;1771-2844&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit8&quot; id=&quot;key_points&quot;&gt;Key Points:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
1. &lt;strong&gt;Non-intrusive&lt;/strong&gt;: The scrub operation is safe to run while the filesystem is mounted and in use, as it doesn’t alter the data itself unless an error is detected and corrected (in RAID setups).
2. &lt;strong&gt;Runs in Background&lt;/strong&gt;: It runs in the background, allowing the system to continue operating normally. You can check its progress using the &lt;code&gt;status&lt;/code&gt; option.
3. &lt;strong&gt;Finds and Fixes Silent Corruption&lt;/strong&gt;: Btrfs has built-in checksumming for both metadata and data. A scrub operation ensures that any silent data corruption (e.g., bit rot) is detected and, if possible, corrected.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Key Points:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;key_points&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;2845-3437&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;how_scrub_works_in_raid&quot;&gt;How Scrub Works in RAID:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
- &lt;strong&gt;RAID 1&lt;/strong&gt; (mirroring): If a block’s checksum doesn’t match the stored checksum, Btrfs will compare it with the mirrored block from the other device. If the other copy is correct, it will be used to repair the corrupted block.
&lt;/p&gt;

&lt;p&gt;
- &lt;strong&gt;RAID 5/6&lt;/strong&gt; (striping with parity): If a block is corrupted, the parity blocks are used to reconstruct the correct data and repair the error.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;How Scrub Works in RAID:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;how_scrub_works_in_raid&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;3438-3848&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit10&quot; id=&quot;commands_for_scrubbing&quot;&gt;Commands for Scrubbing&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Start Scrub&lt;/strong&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs scrub start /mountpoint&lt;/pre&gt;

&lt;p&gt;
This begins the scrub operation on the specified Btrfs filesystem.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Check Scrub Status&lt;/strong&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs scrub status /mountpoint&lt;/pre&gt;

&lt;p&gt;
This shows the current progress of the scrub and any errors that have been found or repaired.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Cancel Scrub&lt;/strong&gt; (if needed):
&lt;code&gt;
sudo btrfs scrub cancel /mountpoint
&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
This cancels the ongoing scrub operation.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Commands for Scrubbing&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;commands_for_scrubbing&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;3849-4295&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit11&quot; id=&quot;output_example_of_scrub_status&quot;&gt;Output Example of Scrub Status:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
After completing a scrub, you can see the results with:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs scrub status /mountpoint&lt;/pre&gt;

&lt;p&gt;
Example output:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
scrub status for btrfs filesystem /mnt/volume
scrub started at Sun Sep 29 11:27:53 2024 and finished after 02:11:08
total bytes scrubbed: 500.00GiB with 0 errors&lt;/pre&gt;

&lt;p&gt;
In this case, no errors were detected during the scrub of a 500 GiB filesystem.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Output Example of Scrub Status:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;output_example_of_scrub_status&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;4296-4702&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit12&quot; id=&quot;when_to_run_btrfs_scrub&quot;&gt;When to Run `btrfs scrub`?&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
- &lt;strong&gt;Periodically&lt;/strong&gt;: Regular scrubs are recommended to ensure data integrity. Many users run it monthly or quarterly.
- &lt;strong&gt;Before Backups&lt;/strong&gt;: It&amp;#039;s a good practice to scrub the filesystem before taking backups to ensure that no corrupted data gets backed up.
- &lt;strong&gt;After Power Failures or Hardware Issues&lt;/strong&gt;: If there’s a concern about potential disk corruption (e.g., after a power failure), running a scrub can help detect any issues.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;When to Run `btrfs scrub`?&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;when_to_run_btrfs_scrub&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:8,&amp;quot;secid&amp;quot;:12,&amp;quot;range&amp;quot;:&amp;quot;4703-5166&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit13&quot; id=&quot;when_scrub_doesn_t_repair&quot;&gt;When Scrub Doesn’t Repair:&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
- If you&amp;#039;re not using RAID or some form of data redundancy, scrub can detect corruption but will not be able to repair it, as there’s no redundant data to fall back on.
&lt;/p&gt;

&lt;p&gt;
In short, &lt;code&gt;btrfs scrub&lt;/code&gt; is a powerful tool for verifying and maintaining the integrity of data on a Btrfs filesystem, especially in scenarios where data redundancy (like RAID) is involved.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;When Scrub Doesn\u2019t Repair:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;when_scrub_doesn_t_repair&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:8,&amp;quot;secid&amp;quot;:13,&amp;quot;range&amp;quot;:&amp;quot;5167-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="https://wiki.devilplan.com/linux:btrfs:hd-migration">
        <dc:format>text/html</dc:format>
        <dc:date>2025-06-08T14:28:26+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>hd-migration</title>
        <link>https://wiki.devilplan.com/linux:btrfs:hd-migration</link>
        <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;complete_guide_for_migrating_to_a_new_btrfs_formatted_hard_drive&quot;&gt;Complete Guide for Migrating to a New BTRFS Formatted Hard Drive&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Using a USB enclosure to transfer data from your old hard drive to a new one is a common and practical approach, especially when you don’t have extra slots in your machine. 
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;considerations&quot;&gt;Considerations:&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Safety:&lt;/strong&gt; You can ensure that the new drive is fully prepared and tested before replacing the old one.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Data Verification:&lt;/strong&gt; Transferring data over USB allows you to verify the transfer before making any changes to your system.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Transfer Speed:&lt;/strong&gt; Depending on the USB version (e.g., USB 2.0 vs. USB 3.0), transfer speeds may vary. USB 3.0 is significantly faster and is recommended if your drives support it.
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Power Supply:&lt;/strong&gt; Ensure that the USB enclosure provides enough power for your hard drive, especially if it’s a larger 3.5-inch drive.
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;strong&gt;Data Integrity:&lt;/strong&gt; Always verify the data after transfer, as mentioned earlier, using &lt;code&gt;diff&lt;/code&gt; or similar tools to ensure nothing was lost or corrupted.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Complete Guide for Migrating to a New BTRFS Formatted Hard Drive&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;complete_guide_for_migrating_to_a_new_btrfs_formatted_hard_drive&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;10-998&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;format_and_initialize&quot;&gt;Format and initialize&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Identify the Drive:&lt;/strong&gt; list block devices to find your new hard drive:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
lsblk&lt;/pre&gt;

&lt;p&gt;
Look for the new device (e.g., &lt;code&gt;/dev/sdb&lt;/code&gt;).
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Format and initialize&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;format_and_initialize&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;999-1162&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;option_1_partition_the_ssd_using_parted&quot;&gt;(Option 1) Partition the SSD using `parted`&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Start &lt;code&gt;parted&lt;/code&gt; with your SSD:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
# Replace `/dev/sdX` with the correct device identifier.
sudo parted /dev/sdX&lt;/pre&gt;

&lt;p&gt;
Create a new partition table:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
mklabel gpt&lt;/pre&gt;

&lt;p&gt;
Create a new partition:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
mkpart primary btrfs 0% 100%&lt;/pre&gt;

&lt;p&gt;
This command creates a primary partition that occupies the entire drive.
&lt;/p&gt;

&lt;p&gt;
Exit &lt;code&gt;parted&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
quit&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;(Option 1) Partition the SSD using `parted`&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;option_1_partition_the_ssd_using_parted&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1163-1554&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;option_2_partition_the_ssd_using_fdisk&quot;&gt;(Option 2) Partition the SSD using `fdisk`&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Open &lt;code&gt;fdisk&lt;/code&gt; to Create a New Partition:&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Start &lt;code&gt;fdisk&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
# Replace sdX with your drive identifier (e.g., /dev/sdb).
sudo fdisk /dev/sdX&lt;/pre&gt;

&lt;/div&gt;

&lt;h4 id=&quot;create_a_new_partition&quot;&gt;Create a New Partition:&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Type &lt;code&gt;g&lt;/code&gt;&lt;/strong&gt; to create a new GPT partition table (if you want GPT; skip if you prefer MBR).
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Type &lt;code&gt;n&lt;/code&gt;&lt;/strong&gt; to create a new partition.
&lt;/p&gt;

&lt;p&gt;
Choose the partition number (default is fine).
&lt;/p&gt;

&lt;p&gt;
For the first sector, press Enter to accept the default.
&lt;/p&gt;

&lt;p&gt;
For the last sector, press Enter to use the entire disk (or specify a size).
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Type &lt;code&gt;w&lt;/code&gt;&lt;/strong&gt; to write changes and exit &lt;code&gt;fdisk&lt;/code&gt;.
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;(Option 2) Partition the SSD using `fdisk`&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;option_2_partition_the_ssd_using_fdisk&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1555-2153&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;format_the_new_partition_as_btrfs&quot;&gt;Format the New Partition as Btrfs:&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Format the partition you just created (e.g., &lt;code&gt;/dev/sdX1&lt;/code&gt;):
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mkfs.btrfs /dev/sdX1&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Mount the Partition:&lt;/strong&gt; create a mount point and mount it:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mkdir /mnt/mybtrfs
sudo mount /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Verify the Filesystem:&lt;/strong&gt; check the newly created Btrfs filesystem:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo btrfs filesystem show&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Check if the partition is mounted:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
df -h&lt;/pre&gt;

&lt;p&gt;
You should see your Btrfs partition listed.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Add to &lt;code&gt;/etc/fstab&lt;/code&gt; for Automatic Mounting:&lt;/strong&gt; to mount the partition automatically at boot, edit the &lt;code&gt;/etc/fstab&lt;/code&gt; file:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo vim /etc/fstab&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults 0 0&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Format the New Partition as Btrfs:&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;format_the_new_partition_as_btrfs&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;2154-2829&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;files_migration&quot;&gt;Files Migration&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
To replace your old hard drive with the new one and copy all data—including hidden files and preserving permissions—you can use the &lt;code&gt;rsync&lt;/code&gt; command. Here’s how to do it step by step:
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Files Migration&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;files_migration&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:12,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;2830-3039&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit7&quot; id=&quot;steps_to_replace_old_hard_drive_with_new_one&quot;&gt;Steps to Replace Old Hard Drive with New One&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Mount Both Hard Drives:&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;Ensure both the old and new hard drives are mounted. You might have something like this:&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;Old drive (e.g., &lt;code&gt;/dev/sda1&lt;/code&gt; mounted at &lt;code&gt;/mnt/old_drive&lt;/code&gt;)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;New drive (e.g., &lt;code&gt;/dev/sdb1&lt;/code&gt; mounted at &lt;code&gt;/mnt/mybtrfs&lt;/code&gt;)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
If not already mounted, create mount points and mount them:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mkdir /mnt/old_drive
sudo mount /dev/sda1 /mnt/old_drive&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Copy Data Using &lt;code&gt;rsync&lt;/code&gt;:&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Use the following &lt;code&gt;rsync&lt;/code&gt; command to copy all data from the old drive to the new drive while preserving permissions and copying hidden files:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo rsync -aAv /mnt/old_drive/ /mnt/mybtrfs/&lt;/pre&gt;

&lt;p&gt;
Breakdown of options:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;code&gt;-a&lt;/code&gt;: Archive mode; preserves permissions, timestamps, and symlinks.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;code&gt;-A&lt;/code&gt;: Preserves ACLs (Access Control Lists).&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;code&gt;-v&lt;/code&gt;: Verbose; shows the progress of the transfer.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;Optional &lt;code&gt;-X&lt;/code&gt; option, will not allow compression!&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;&lt;code&gt;-X&lt;/code&gt;: Preserves extended attributes.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;strong&gt;Verify the Copy:&lt;/strong&gt; after the copying process completes, you can verify that the data has been copied correctly:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo diff -r /mnt/old_drive/ /mnt/mybtrfs/&lt;/pre&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;This will show any differences between the two directories.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;strong&gt;Unmount Both Drives:&lt;/strong&gt; once the data is copied and verified, unmount both drives:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo umount /mnt/old_drive
sudo umount /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Replace the Old Drive:&lt;/strong&gt; physically replace the old hard drive with the new one in your system.
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Steps to Replace Old Hard Drive with New One&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;steps_to_replace_old_hard_drive_with_new_one&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:12,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;3040-4455&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;data_integrity&quot;&gt;Data Integrity&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
While &lt;code&gt;rsync&lt;/code&gt; has features that help ensure data integrity, it’s a good idea to perform additional verification after the transfer to ensure everything has copied correctly. Using checksums or file comparison tools will help confirm that your data is intact and uncorrupted. 
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;rsync&lt;/code&gt; itself does not guarantee data integrity, but it provides several mechanisms to help ensure that data is transferred correctly and is uncorrupted. 
&lt;/p&gt;

&lt;p&gt;
Here’s how you can use &lt;code&gt;rsync&lt;/code&gt; effectively and what you can do to enhance data integrity:
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Data Integrity&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;data_integrity&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:16,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;4456-5003&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;features_of_rsync&quot;&gt;Features of `rsync`&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;strong&gt;File Comparison:&lt;/strong&gt; by default, &lt;code&gt;rsync&lt;/code&gt; checks file sizes and timestamps to determine if files need to be copied. This helps prevent unnecessary copies.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Checksum Verification:&lt;/strong&gt; you can use the &lt;code&gt;--checksum&lt;/code&gt; option, which forces &lt;code&gt;rsync&lt;/code&gt; to compare files using checksums instead of relying solely on size and timestamp. This is more resource-intensive but increases the likelihood of identifying changes or corruption:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo rsync -aAv --checksum /mnt/old_drive/ /mnt/mybtrfs/&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Verbose Output:&lt;/strong&gt; the &lt;code&gt;-v&lt;/code&gt; option gives you a detailed output of the transfer, allowing you to monitor the process.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Features of `rsync`&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;features_of_rsync&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:16,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;5004-5635&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit10&quot; id=&quot;post-transfer_verification&quot;&gt;Post-Transfer Verification&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
To ensure that data is uncorrupted after the transfer, consider using additional verification methods:
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;&lt;code&gt;diff&lt;/code&gt; Command:&lt;/strong&gt; After using &lt;code&gt;rsync&lt;/code&gt;, you can compare the source and destination directories using:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo diff -r /mnt/old_drive/ /mnt/mybtrfs/&lt;/pre&gt;

&lt;p&gt;
This will report any differences between the two directories.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Checksums:&lt;/strong&gt; you can generate checksums (e.g., using &lt;code&gt;md5sum&lt;/code&gt; or &lt;code&gt;sha256sum&lt;/code&gt;) for all files in both locations and compare them:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
cd /mnt/old_drive &amp;amp;&amp;amp; find . -type f -exec sha256sum {} + | sort &amp;gt; /tmp/old_checksums.txt
cd /mnt/mybtrfs &amp;amp;&amp;amp; find . -type f -exec sha256sum {} + | sort &amp;gt; /tmp/new_checksums.txt
diff /tmp/old_checksums.txt /tmp/new_checksums.txt&lt;/pre&gt;

&lt;/div&gt;

&lt;h4 id=&quot;noteseveral_default_settings_have_changed_in_version_515_please_make_sure_this_does_not_affect_your_deployments&quot;&gt;NOTE: several default settings have changed in version 5.15, please make sure this does not affect your deployments:&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;DUP for metadata (-m dup)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;enabled no-holes (-O no-holes)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;enabled free-space-tree (-R free-space-tree)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;hr /&gt;
&lt;dl class=&quot;file&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;https://wiki.devilplan.com/_export/code/linux:btrfs:hd-migration?codeblock=19&quot; title=&quot;Download Snippet&quot; class=&quot;mediafile mf_cpp&quot;&gt;snippet.cpp&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code file cpp&quot;&gt;by&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
▖     ▘▖▖
▌ ▌▌▛▘▌▙▌
▙▖▙▌▙▖▌ ▌
&amp;nbsp;
written&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; a &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; ago. &lt;span class=&quot;me1&quot;&gt;Edited&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; June &lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2025&lt;/span&gt;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Post-Transfer Verification&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;post-transfer_verification&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:17,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;5636-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="https://wiki.devilplan.com/linux:btrfs:trim">
        <dc:format>text/html</dc:format>
        <dc:date>2025-06-08T14:12:04+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>trim</title>
        <link>https://wiki.devilplan.com/linux:btrfs:trim</link>
        <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;guide_to_enable_trim_on_a_btrfs_filesystem&quot;&gt;Guide to enable TRIM on a Btrfs filesystem&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Enable TRIM on your Btrfs filesystem, either through continuous or periodic TRIM operations. 
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Guide to enable TRIM on a Btrfs filesystem&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;guide_to_enable_trim_on_a_btrfs_filesystem&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;10-149&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;check_your_ssd&quot;&gt;Check Your SSD&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Ensure your SSD is recognized and has Btrfs installed. You can check connected drives using:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
lsblk&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Check Your SSD&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;check_your_ssd&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;150-278&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;mount_the_btrfs_filesystem_with_trim_option&quot;&gt;Mount the Btrfs Filesystem with TRIM Option&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
You can enable TRIM either during mounting or set it up for periodic trimming.
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Mount the Btrfs Filesystem with TRIM Option&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;mount_the_btrfs_filesystem_with_trim_option&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;279-413&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;option_aenable_trim_during_mounting&quot;&gt;Option A: Enable TRIM During Mounting&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;strong&gt;Mount with the &lt;code&gt;discard&lt;/code&gt; Option:&lt;/strong&gt;
Replace &lt;code&gt;/dev/sdX1&lt;/code&gt; and &lt;code&gt;/mnt/mybtrfs&lt;/code&gt; with your actual device identifier and mount point.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount -o discard /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Add to &lt;code&gt;/etc/fstab&lt;/code&gt;:&lt;/strong&gt;
To make the change persistent across reboots, add the following line to your &lt;code&gt;/etc/fstab&lt;/code&gt; file:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
/dev/sdX1 /mnt/mybtrfs btrfs defaults,discard 0 0&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Option A: Enable TRIM During Mounting&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;option_aenable_trim_during_mounting&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;414-826&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;option_bschedule_periodic_trim&quot;&gt;Option B: Schedule Periodic TRIM&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
In this guide I will schedule the trim-script with systemd, you could instead run the script periodically using a simple cronjob, with some tradeoffs, explained in this table: 
&lt;/p&gt;
&lt;div class=&quot;table sectionedit6&quot;&gt;&lt;table class=&quot;inline&quot;&gt;
	&lt;tr class=&quot;row0&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Feature                  &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; &lt;code&gt;cron&lt;/code&gt;                &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; &lt;code&gt;systemd&lt;/code&gt; timer                      &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row1&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Ease of setup            &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; ✔️ Easier             &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; ❌ More involved                      &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row2&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Logging                  &lt;/td&gt;&lt;td class=&quot;col1&quot;&gt; ❌ Manual (unless set) &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; ✔️ Via &lt;code&gt;journalctl&lt;/code&gt;                  &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row3&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Missed job handling      &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; ❌ Not handled         &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; ✔️ &lt;code&gt;Persistent=true&lt;/code&gt;                 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row4&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Service dependencies     &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; ❌ None                &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; ✔️ Fully supported                   &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row5&quot;&gt;
		&lt;td class=&quot;col0 leftalign&quot;&gt; Portability              &lt;/td&gt;&lt;td class=&quot;col1 leftalign&quot;&gt; ✔️ Highly portable    &lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt; ❌ Linux only (with &lt;code&gt;systemd&lt;/code&gt;)        &lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;1044-1625&amp;quot;} --&gt;
&lt;p&gt;
&lt;strong&gt;Unmount the Filesystem (if needed):&lt;/strong&gt;
If you want to remove the &lt;code&gt;discard&lt;/code&gt; option and use periodic TRIM instead:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo umount /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Re-mount without &lt;code&gt;discard&lt;/code&gt;:&lt;/strong&gt;
Mount the filesystem normally:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo mount /dev/sdX1 /mnt/mybtrfs&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Create a TRIM Script:&lt;/strong&gt;
Create a simple script for periodic TRIM. For example, create a file named &lt;code&gt;btrfs-trim.sh&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo vim /usr/local/bin/btrfs-trim.sh&lt;/pre&gt;

&lt;p&gt;
Add the following lines:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
#!/bin/bash
btrfs filesystem df /mnt/hd1
sudo btrfs device stats /mnt/hd1
sudo fstrim /mnt/hd1&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Make the Script Executable:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo chmod +x /usr/local/bin/btrfs-trim.sh&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Schedule the Script with systemd:&lt;/strong&gt;
Create a systemd service and timer to run the script regularly.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Create the Service File:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo vim /etc/systemd/system/btrfs-trim.service&lt;/pre&gt;

&lt;p&gt;
Add the following:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
[Unit]
Description=Run Btrfs TRIM

[Service]
Type=oneshot
ExecStart=/usr/local/bin/btrfs-trim.sh&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Create the Timer File:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo vim /etc/systemd/system/btrfs-trim.timer&lt;/pre&gt;

&lt;p&gt;
Add the following:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
[Unit]
Description=Run Btrfs TRIM weekly

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;Enable and Start the Timer:&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo systemctl enable btrfs-trim.timer
sudo systemctl start btrfs-trim.timer&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Option B: Schedule Periodic TRIM&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;option_bschedule_periodic_trim&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;827-2933&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit7&quot; id=&quot;verify_trim&quot;&gt;Verify TRIM&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
You can check if TRIM is functioning by monitoring your SSD’s performance and usage over time. You can also look at the output of the TRIM command you scheduled to see if it executes without errors.
&lt;/p&gt;
&lt;hr /&gt;
&lt;dl class=&quot;file&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;https://wiki.devilplan.com/_export/code/linux:btrfs:trim?codeblock=13&quot; title=&quot;Download Snippet&quot; class=&quot;mediafile mf_cpp&quot;&gt;snippet.cpp&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code file cpp&quot;&gt;by&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
▖     ▘▖▖
▌ ▌▌▛▘▌▙▌
▙▖▙▌▙▖▌ ▌
&amp;nbsp;
written&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; a &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; ago. &lt;span class=&quot;me1&quot;&gt;Edited&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; June &lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2025&lt;/span&gt;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Verify TRIM&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;verify_trim&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:13,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;2934-&amp;quot;} --&gt;</description>
    </item>
</rdf:RDF>
