<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Autarchy of the Private Cave &#187; btrfs</title> <atom:link href="https://bogdan.org.ua/tags/btrfs/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Wed, 28 Dec 2022 16:09:04 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>How to: enable metadata duplication on an existing btrfs filesystem</title><link>https://bogdan.org.ua/2016/12/30/how-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html</link> <comments>https://bogdan.org.ua/2016/12/30/how-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html#comments</comments> <pubDate>Fri, 30 Dec 2016 19:43:51 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[btrfs]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=2474</guid> <description><![CDATA[Just one command: sudo btrfs balance start -v -mconvert=dup /toplevel/ where /toplevel/ is your mountpoint of the btrfs root, -v is there for verbosity (not too verbose, don&#8217;t worry), and -mconvert=dup literally says act on metadata only, convert data profile to DUP. This will duplicate both metadata and btrfs system data. Verify with: sudo btrfs [&#8230;]]]></description> <content:encoded><![CDATA[<p>Just one command: <code>sudo btrfs balance start -v -mconvert=dup  /toplevel/</code><br
/> where <code>/toplevel/</code> is your <a
href="http://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html">mountpoint of the btrfs root</a>, <code>-v</code> is there for verbosity (not too verbose, don&#8217;t worry), and <code>-mconvert=dup</code> literally says <em>act on metadata only, convert data profile to DUP</em>.</p><p>This will duplicate both metadata and btrfs system data.<br
/> Verify with: <code>sudo btrfs fi df /toplevel</code>:</p><blockquote><p>Data, single: total=10.00GiB, used=3.88GiB<br
/> System, DUP: total=64.00MiB, used=4.00KiB<br
/> Metadata, DUP: total=512.00MiB, used=286.18MiB<br
/> GlobalReserve, single: total=96.00MiB, used=0.00B</p></blockquote><p>Explanation: on SSDs, mkfs.btrfs creates metadata in <em>single</em> mode (because of widely spread SSD deduplication algorithms negating duplicate entries). However, second copy of metadata increases recovery chances, especially so if your SSD does not deduplicate writes. Hence the desire to add metadata/systemdata duplication after the filesystem is created.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&amp;linkname=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&amp;linkname=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&amp;linkname=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&amp;linkname=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&amp;linkname=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2016%2F12%2F30%2Fhow-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html&#038;title=How%20to%3A%20enable%20metadata%20duplication%20on%20an%20existing%20btrfs%20filesystem" data-a2a-url="https://bogdan.org.ua/2016/12/30/how-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html" data-a2a-title="How to: enable metadata duplication on an existing btrfs filesystem"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2016/12/30/how-to-add-enable-metadata-duplication-existing-btrfs-filesystem.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to: easily add swap partition to a live system on btrfs</title><link>https://bogdan.org.ua/2016/04/14/how-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html</link> <comments>https://bogdan.org.ua/2016/04/14/how-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html#comments</comments> <pubDate>Thu, 14 Apr 2016 13:09:23 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[btrfs]]></category> <category><![CDATA[filesystem]]></category> <category><![CDATA[partition]]></category> <category><![CDATA[resize]]></category> <category><![CDATA[swap]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=2397</guid> <description><![CDATA[Recently I had a need to add a swap file to my Debian installation. However, I am now using btrfs, and &#8211; as with any other COW filesystem &#8211; it is not possible to simply create a swap file and use it. There are workarounds (creating a file with a COW attribute removed, and then [&#8230;]]]></description> <content:encoded><![CDATA[<p>Recently I had a need to <a
href="http://bogdan.org.ua/2010/07/16/linux-how-to-label-swap-partition-without-losing-swap-uuid.html">add a swap file</a> to my Debian installation.<br
/> However, I am now using btrfs, and &#8211; as with any other <abbr
title="Copy On Write">COW</abbr> filesystem &#8211; it is not possible to simply create a swap file and use it.<br
/> There are workarounds (creating a file with a COW attribute removed, and then loop-mounting it), but I just did not like them.</p><p>So I have decided to add a swap partition.<br
/> It worked amazingly (and very easily), there was even no need to reboot &#8211; at all.<br
/> I still did restart, just to make sure the system is bootable &#8211; and all was perfectly fine.</p><p>My initial setup is very simple: a single /dev/sda1 partition on the /dev/sda disk, fully used by btrfs.<br
/> Different important paths/mountpoints are btrfs subvolumes, using <a
href="http://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html">flat hierarchy</a>.<br
/> For this example, let us assume that /dev/sda (and /dev/sda1) is 25GB large, and that I want to add a 2GB swap /dev/sda2 after /dev/sda1.</p><p>Brief explanation before we start:</p><ol><li>shrink btrfs <em>filesystem</em> by more than 2GB;</li><li>shrink btrfs <em>partition</em> by 2GB;</li><li>create new 2GB partition for the swap;</li><li>resize btrfs <em>filesystem</em> to full size of its new-size <em>partition</em>;</li><li>initialize swap and turn it on.</li></ol><p>Here are the very easy steps! Just make sure you do not make mistakes anywhere <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /><br
/> <span
id="more-2397"></span></p><ol><li>If your btrfs volume with ID 5 (top level) is a separate mountpoint: mount it now, e.g. <code>sudo mount /toplevel</code>.</li><li>Take note of your current partition label and UUID: <code>sudo blkid</code>.</li><li>Resize btrfs filesystem <strong>down</strong> (shrink) with a <strong>good</strong> margin; for example, if I want to add a 2 GB swap, then I can <code>sudo btrfs fi resize -3g /toplevel</code> &#8211; here, I&#8217;m shrinking btrfs <em>filesystem</em> by about a gigabyte more than necessary. The process is very quick if you have free space, so you can even use a larger margin &#8211; say, <code>sudo btrfs fi resize -5g /toplevel</code>.</li><li><code>sudo parted</code>, then <code>print</code> to make sure what is the number of your btrfs <em>partition</em>, then <code>resizepart 1</code> (where <strong>1</strong> is the partition number), and answer a few questions: <code>yes</code>, <code>new_size_here</code> (in our example: 23.0GB), <code>yes</code>. You can also create a swap partition from parted, then quit parted with <code>q</code> and Enter.</li><li><code>sudo partprobe</code> to let the OS know that partitions have changed.</li><li>I have used <strong>cfdisk</strong> to create a 2GB swap partition: it has a very simple ncurses UI, and is very intuitive. After creating swap partition, do run <code>sudo partprobe</code> again.</li><li>Resize btrfs <em>filesystem</em> back up to take all of the <em>partition</em>: <code>sudo btrfs fi resize max /toplevel</code>.</li><li>Simply to be sure, run a scrub: <code>sudo btrfs scrub start -B -r /toplevel</code>.</li><li>Initialize swap; you can specify uuid and/or label which you may already have in your fstab: <code>mkswap --label=swap --uuid=your1234-your-uuid-1234-youruuid1234 /dev/sda2</code>.</li><li><code>sudo blkid</code> to make sure your /dev/sda1 UUID stayed the same (or to get swap uuid/label if you haven&#8217;t specified any).</li><li>Optionally, add the swap line to your /etc/fstab. Then turn on swap with <code>swapon -a</code>.</li></ol><p>That&#8217;s it! Amazing, isn&#8217;t it? On-the-fly filesystem and partition resizing!</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&amp;linkname=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&amp;linkname=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&amp;linkname=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&amp;linkname=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&amp;linkname=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2016%2F04%2F14%2Fhow-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html&#038;title=How%20to%3A%20easily%20add%20swap%20partition%20to%20a%20live%20system%20on%20btrfs" data-a2a-url="https://bogdan.org.ua/2016/04/14/how-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html" data-a2a-title="How to: easily add swap partition to a live system on btrfs"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2016/04/14/how-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ZFS is the FS for Containers in Ubuntu 16.04 and how it compares to btrfs</title><link>https://bogdan.org.ua/2016/02/20/zfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html</link> <comments>https://bogdan.org.ua/2016/02/20/zfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html#comments</comments> <pubDate>Sat, 20 Feb 2016 18:45:00 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[btrfs]]></category> <category><![CDATA[comparison]]></category> <category><![CDATA[ext4]]></category> <category><![CDATA[FreeNAS]]></category> <category><![CDATA[vs]]></category> <category><![CDATA[XFS]]></category> <category><![CDATA[ZFS]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=2354</guid> <description><![CDATA[Recently in hacker news the following was posted: ZFS is the FS for Containers in Ubuntu 16.04. I must admit the 16.04 demo does look very pleasant to work with. However, bringing in ZFS into Linux reminded me of a fairly recent comparison of ZFS and btrfs that I had to do when building my [&#8230;]]]></description> <content:encoded><![CDATA[<p>Recently in hacker news the following was posted: <a
href="https://news.ycombinator.com/item?id=11125063">ZFS is the FS for Containers in Ubuntu 16.04</a>.</p><p>I must admit the 16.04 demo does look very pleasant to work with.</p><p>However, bringing in ZFS into Linux reminded me of a fairly recent comparison of ZFS and btrfs that I had to do when building my home NAS.<br
/> At that time, few months ago, I&#8217;ve arrived (among others) at the following conclusions:</p><ul><li>ZFS on FreeBSD is reliable, though a memory hog;</li><li>on Debian, OpenVault seems to be a good NAS web-management interface;</li><li>on FreeBSD, FreeNAS is good (there is also Nas4Free fork of an older version, but I haven&#8217;t looked into it deep enough);</li><li>running ZFS on linux (even as a kernel module) is the least efficient solution, at least partially because kernel&#8217;s file caching and ZFS&#8217;s ARC cache are two separate entities;</li><li>although btrfs offers features very similar to ZFS, as of few months ago OpenVault did not offer btrfs volumes support from the web-interface.</li></ul><p>In the end, I&#8217;ve decided to go with FreeNAS, and it seems to work well so far.</p><p>But had anything changed in the <em>btrfs vs ZFS on Linux</em> field?<br
/> <span
id="more-2354"></span><br
/> Luckily, in the comments section of the <a
href="http://blog.dustinkirkland.com/2016/02/zfs-is-fs-for-containers-in-ubuntu-1604.html">original post</a> Brian Mullan linked to a recent Bachelor degree project titled <a
href="https://www.diva-portal.org/smash/get/diva2:822493/FULLTEXT01.pdf">A performance comparison of ZFS and btrfs on Linux</a> (<a
href="http://bogdan.org.ua/wp-content/uploads/2016/02/A_performance_comparison_of_ZFS_and_btrfs_on_Linux.pdf">local copy</a>). Here&#8217;s an excerpt from the abstract:</p><blockquote><p> The main conclusions that can be drawn from the analysis of the gathered data is that<br
/> Btrfs has improved greatly in recent years and is today showing great throughput whereas<br
/> ZFS on Linux is performing considerably worse than Btrfs.</p></blockquote><p>The document is definitely worth looking at &#8211; actual results start on page 22, and there are figures for easy comprehension <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /><br
/> XFS and ext4 are also added to the comparison, so if you are thinking about changing your FS &#8211; the document may help you, too.<br
/> The only area where ZFS excelled was database-like load; btrfs and XFS were the leaders in the majority of other tests.<br
/> (In fact, somewhat lower btrfs performance for database-like loads seems to be a well-known thing, and can be <em>cured</em> with the <code>nodatacow</code> mount option &#8211; see e.g. this <a
href="http://blog.pgaddict.com/posts/friends-dont-let-friends-use-btrfs-for-oltp" class="broken_link" rel="nofollow">nice rant about PostgreSQL on btrfs</a>.)</p><p>I do believe that ZFS is still more stable than btrfs, but I&#8217;m also still not convinced that <em>ZFS and Linux</em> are a good combination.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&amp;linkname=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&amp;linkname=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&amp;linkname=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&amp;linkname=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&amp;linkname=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F20%2Fzfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html&#038;title=ZFS%20is%20the%20FS%20for%20Containers%20in%20Ubuntu%2016.04%20and%20how%20it%20compares%20to%20btrfs" data-a2a-url="https://bogdan.org.ua/2016/02/20/zfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html" data-a2a-title="ZFS is the FS for Containers in Ubuntu 16.04 and how it compares to btrfs"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2016/02/20/zfs-is-the-fs-for-containers-in-ubuntu-16-04-and-how-it-compares-to-btrfs.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to: convert your VPS root filesystem to btrfs (using rescue boot)</title><link>https://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html</link> <comments>https://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html#comments</comments> <pubDate>Mon, 15 Feb 2016 17:04:25 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[btrfs]]></category> <category><![CDATA[convert]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[filesystem]]></category> <category><![CDATA[VPS]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=2349</guid> <description><![CDATA[I&#8217;m moving from (a kind of&#8230;) a dedicated server to a VPS, to decrease my frightful anticipation of hardware failures. Honestly though, that server had been freezing up and restarting spontaneously for several months now, causing sometimes really long down-times&#8230; That server is now about 6-7 years old, built with off-the-shelf components, some of which [&#8230;]]]></description> <content:encoded><![CDATA[<p>I&#8217;m moving from (a kind of&#8230;) a dedicated server to a VPS, to decrease my frightful anticipation of hardware failures.<br
/> <em>Honestly though, that server had been freezing up and restarting spontaneously for several months now, causing sometimes really long down-times&#8230;</em><br
/> That server is now about 6-7 years old, built with off-the-shelf components, some of which (the HDD <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> ) had weird noises from the very start.<br
/> Definitely time to move!</p><p>I&#8217;ve purchased a fairly cheap VPS with an easy, one-click upgrade option for after I&#8217;m done configuring it.<br
/> It comes with a wide selection of OSes to pre-install; I&#8217;ve chosen <strong>Debian Jessie</strong>, version 8.3 as of this writing.</p><p>I wanted to use <strong>btrfs</strong> from the beginning, so could have installed Debian myself, but&#8230; VPS provider does some initial configuration (like their Debian mirror and some other things), so I&#8217;ve felt that converting to btrfs <em>after the fact</em> would be easier. Now that I&#8217;ve done this &#8211; I guess it was fairly easy, although preparation did take some time.</p><p>Below, I&#8217;m providing step-by-step instructions on how to convert your root filesystem from (most likely) <strong>ext4 to btrfs</strong>.<br
/> <span
id="more-2349"></span><br
/> I&#8217;ll be using my provider&#8217;s <em>rescue boot</em> mode: this is a live Debian system which is network-booted on my own VPS, and thus has access to the SSD/HDD of my VPS. Hopefully, your provider has a similar feature.</p><p>Preparing for this conversion, I had mostly used two sources:</p><ul><li>an older <a
href="https://www.howtoforge.com/how-to-convert-an-ext3-ext4-root-file-system-to-btrfs-on-ubuntu-12.10-p2">howtoforge conversion tutorial</a>, and</li><li><a
href="https://btrfs.wiki.kernel.org/index.php/SysadminGuide">Sysadmin Guide</a></li></ul><p>Before we begin with actual conversion, here is a</p><h3>List of hints and useful practices/commands for a future btrfs user</h3><ul><li>Changing the default subvolume with <code>btrfs subvolume set-default</code> will make the top level of the filesystem inaccessible, except by use of the <code>subvol=/</code> or <code>subvolid=5</code> mount options.</li><li>If top level is no longer your default subvolume, it is useful to have an <strong>fstab</strong> entry for the top level (note the <strong>noauto</strong> option!):<br
/> <code>LABEL=toplevel   /root/btrfs-top-lvl   btrfs  subvol=/,defaults,noauto,noatime   0  0</code></li><li><a
href="http://marc.merlins.org/perso/btrfs/post_2014-03-19_Btrfs-Tips_-Btrfs-Scrub-and-Btrfs-Filesystem-Repair.html">scurbbing and repairing btrfs</a>; most of the hints below originate from Marc&#8217;s <a
href="http://events.linuxfoundation.org/sites/events/files/slides/Btrfs_1.pdf">2014 btrfs presentation</a></li><li>scrub script: <a
href="http://marc.merlins.org/linux/scripts/btrfs-scrub">http://marc.merlins.org/linux/scripts/btrfs-scrub</a></li><li><code>mount -o compress=lzo</code> is fast and best for SSDs; <code>mount -o compress=zlib</code> compresses better but is slower</li><li>you can turn off COW (copy-on-write) for specific files and directories with <code>chattr Â­-C /path</code> (new files will inherit this)</li><li>for a highly fragmented VM, <code>btrfs filesystem defragment vbox.vdi</code> could take hours; <code>cp -reflink=never vbox.vdi vbox.vdi.new; rm vbox.vdi</code> is much faster</li><li><code>cp -reflink=always</code> copies within and between subvolumes without duplicating data</li><li>run scrub nightly or weekly on all btrfs filesystems</li><li><strong>noatime</strong> is the best fstab mount option for btrfs <em>IF USING SNAPSHOTS</em>, because <strong>relatime</strong> still causes at least 1 write every 24h</li><li>if you have <strong>errors=remount-ro</strong> in your <strong>fstab</strong> for extX-filesystem, you should remove it after converting to <strong>btrfs</strong> as it does not understand the option.</li></ul><h3>We are almost ready to start! Just one last thing: partitioning!</h3><p>On my previous server, I did have a certain partition scheme, with separate <strong>/boot</strong>, <strong>/home</strong>, <strong>/var</strong>, <strong>/usr</strong>, and everything else under <strong>/</strong> partition.<br
/> It worked very well for me, never ran into problems (although this is more like a Debian&#8217;s feature, not that of my partition scheme <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> ).<br
/> However&#8230; With the current VPS, it started initially with just everything under <strong>/</strong>, in a single partition.<br
/> I could have re-partitioned everything from the rescue system while converting to <strong>btrfs</strong>, but what for? What would be the benefits?</p><p>Let&#8217;s have a look and evaluate</p><h3>Advantages/disadvantages of keeping specific partitions separate.</h3><ul><li><strong>/boot</strong> comes the first. Normally I format it with ext2, and set aside just 100-200 megabytes for this small partition.<br
/> This improves boot-reliability of the system. With <strong>btrfs</strong>, it was also the case that grub could not use <strong>/boot</strong> on a btrfs volume.<br
/> However,</p><blockquote><p> Newer GRUBs can handle a /boot partition which is btrfs, so you need not have a separate /boot partition formatted as ext3/4.</p></blockquote><p>So this time I&#8217;m going without a separate /boot.<br
/> I will not even create a separate subvolume for it: for snapshotting purposes, <strong>/boot</strong> fits perfectly under the <strong>/</strong> snapshots.</li><li>Next comes <strong>/home</strong>.<br
/> The reason to separate it is to safeguard user data when upgrading/reinstalling the OS.<br
/> This, however, can be achieved with <strong>btrfs subvolumes</strong> &#8211; no need for partitions!<br
/> I&#8217;m going with a &#8220;subvolume for home&#8221; here, then.</li><li>Next comes <strong>/var</strong>, or more precisely <strong>/var/log</strong>.<br
/> One of the reasons to keep <strong>/var/log</strong> separate is to prevent filesystem overfill if logs suddenly start growing too fast.<br
/> This, however, can be achieved with <strong>subvolume quotas</strong>. No need for a partition!</li><li>There is also <strong>/var/lib/<databasename></strong> (and also <strong>/var/lib/lxc/&#8230;</strong>), which hold fairly big data files, often with random write access patterns.<br
/> There are two reasons to make them subvolumes:</p><ol><li>for data-only snapshots</li><li>to enable <code>nocow</code>/<code>nodatacow</code> at mount time, to avoid high fragmentation with random writes</li></ol><p>However, this can be done later, when these databases/LXC get installed &#8211; in just a few commands, without rebooting.</li><li>Finally, <strong>/</strong> itself should be a separate subvolume &#8211; mostly for snapshot and reinstall/upgrade reasons.</li></ul><p>Ok, now we are <strong>really</strong> going to</p><h3>Convert the filesystem</h3><ol><li>Enable rescue system, write down access credentials. You may need to restart your VPS to boot into rescue system, but check with your VPS provider first.</li><li>Connect to and log in to the rescue system.</li><li>Install <strong>btrfs-tools</strong> in the rescue system, if not there yet. We&#8217;ll need <strong>btrfs-convert</strong>, which should be included in <strong>btrfs-tools</strong>.</li><li>I&#8217;m assuming that your SSD/HDD is device <strong>/dev/sda</strong>, and that the only (root) partition there is <strong>/dev/sda1</strong>; adjust the next steps if your setup is different. <em>Only proceed with commands if you understand what they are doing!</em></li><li>It never hurts to <code>fsck /dev/sda1</code> before doing filesystem conversion <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> You should see something like <em>/dev/sda1: clean, 27282/1564672 files, 351853/6249472 blocks</em>.</li><li><code>btrfs-convert -l toplevel /dev/sda1</code>; note that I&#8217;m adding a &#8220;toplevel&#8221; <em>LABEL</em> to the top level of btrfs, for easier mounting it later. The output should look like this:<br
/><blockquote><p> creating btrfs metadata.<br
/> creating ext2fs image file.<br
/> cleaning up system chunk.<br
/> conversion complete.</p></blockquote><p> At this point the system is already btrfs! <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></li><li>If you forgot to set btrfs label, or decide to do it later: list the filesystems with <code>btrfs filesystem show</code>, or just look for the label with <code>btrfs filesystem label /dev/sda1</code> (which will produce an empty line if there is no label), then simply <code>btrfs filesystem label /dev/sda1 toplevel</code>; it will produce no output on success.</li><li>Let&#8217;s change into the new system, and start configuring it:<br
/> <code>mount /dev/sda1 /mnt<br
/> for fs in proc sys dev dev/pts; do mount --bind /$fs /mnt/$fs; done<br
/> chroot /mnt</code></li><li><code>ls</code> now should show your root filesystem files and directories, plus the <strong>ext2_saved</strong> &#8220;directory&#8221; (which is a subvolume, actually):<br
/><blockquote><p> bin   dev  ext2_saved  initrd.img         installimage.debug  lib64       media  opt   root  sbin  sys  usr  vmlinuz<br
/> boot  etc  home        installimage.conf  lib                 lost+found  mnt    proc  run   srv   tmp  var</p></blockquote></li><li>Run <code>blkid /dev/sda1</code> to find out the UUID of the new btrfs top-level volume. You can also see it with <code>btrfs filesystem show</code>:<br
/><blockquote><p> /dev/sda1: LABEL=&#8221;toplevel&#8221; UUID=&#8221;3124c827-c3bd-4a62-843f-1d5a552f1858&#8243; UUID_SUB=&#8221;ffad5668-2ac7-4ea4-83ad-e6ccba7ccf96&#8243; TYPE=&#8221;btrfs&#8221; PARTUUID=&#8221;750b31a7-01&#8243;</p></blockquote></li><li>Edit <strong>/etc/fstab</strong> (with e.g. <code>nano /etc/fstab</code>):<ul><li>change <strong>UUID</strong> of <strong>/</strong> to the new one</li><li>change the filesystem type from ext3/ext4 to <strong>btrfs</strong></li><li>change the options to <strong>subvol=root,defaults,noatime,compress=lzo,ssd,discard</strong> (yes, <strong>subvol=root</strong> does not exist yet&#8230; also, <strong>ssd,discard</strong> are for SSDs only, and instead of adding <strong>discard</strong> here it might be better to setup an <strong>fstrim</strong> cronjob. Finally, <strong>noatime</strong> can be left out if you are not going to make snapshots.)</li><li>change the last number in the line from 1 to 0 (the fsck passes &#8211; btrfs does not want boot-time filesystem checking)</li></ul></li><li>Some guides mention editing /etc/grub.d/00_header in a specific way, running <em>grub-mkconfig | grep &#8221; ro &#8220;</em> to see if it adds the proper <em>rootflags=subvol=root</em>, then even run <em>update-grub</em> and <em>grub-install /dev/sda</em> here&#8230; But all of this seems redundant or plain unnecessary. First of all, the <em>root</em> subvolume simply does not exist yet, so <em>grub-mkconfig</em> will <strong>not</strong> produce correct <em>rootflags</em>. Secondly, we are not yet done with setting up subvolumes, and we are not going to reboot right now, so running <em>update-grub</em>/<em>grub-install</em> is a bit premature at this stage <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></li><li>Now we are going to create some subvolumes. As I want to name the <strong>root</strong> subvolume simply <em>root</em>, I should first move the root user&#8217;s home files somewhere else (otherwise <code>btrfs snapshot</code> complains &#8220;ERROR: incorrect snapshot name &#8216;/&#8217;&#8221;):<br
/> <code>mv /root /root_orig<br
/> btrfs subvolume snapshot / /root</code></li><li>The same <em>problem</em> with <strong>/home</strong>, need to move it as well: <code>mv /home /home_orig</code></li><li>I can NOT snapshot <strong>/home</strong> like I did with <strong>/</strong>, because it is just a directory, not a volume like <strong>/</strong>, so:<br
/> <code>btrfs subvolume create /home</code><br
/> Note: my <strong>/home</strong> (/home_orig) is still empty, as this is a brand-new installation with only the root user, so double-check steps below, as I haven&#8217;t really run them.<br
/> <code>rsync --progress -aHAX /home_orig/* /home<br
/> ls -la /home/<br
/> ls -la /home_orig/<br
/> rm -fr /home_orig/*<br
/> ls -la /root/home/<br
/> rm -fr /root/home/*</code> # be sure to leave the empty /root/home/ in place: it will be the mount point.</li><li><code>nano /etc/fstab</code> to add the <strong>/home</strong> mount line, using <strong>the same UUID as earlier for the / partition</strong>, but a different <strong>subvol</strong> option:<br
/> <strong>UUID=3124c827-c3bd-4a62-843f-1d5a552f1858 /home               btrfs   subvol=home,defaults 0       0</strong><br
/> Feel free to add more mount options, similar to those for root subvolume. While we are editing /etc/fstab, it also makes sense to add a <strong>non-automount /toplevel</strong> entry (<strong>UUID=3124c827-c3bd-4a62-843f-1d5a552f1858 /toplevel               btrfs   subvol=/,defaults,noauto 0       0</strong>) and create mountpoint for it: <code>mkdir /root/toplevel</code></li><li>Follow the same procedure to create the <strong>/var/log</strong> subvolume. I&#8217;m using <em>flat subvolumes</em> layout here:<br
/> <code>btrfs subvolume create /log<br
/> rsync --progress -aHAX /var/log/* /log<br
/> ls -la /log/<br
/> ls -la /var/log/<br
/> rm -fr /var/log/*<br
/> ls -la /root/var/log/<br
/> rm -fr /root/var/log/*<br
/> </code></li><li>Add <strong>/var/log</strong> entry to <strong>fstab</strong>:<br
/> <strong>UUID=&#8221;3124c827-c3bd-4a62-843f-1d5a552f1858&#8243; /var/log   btrfs   subvol=log,defaults,ssd,discard,compress=lzo,noatime   0   0</strong></li><li>/var/lib/<name> &#8211; databases, LXC, nodatacow/nocow &#8211; can be created later, not doing it here and now.</li><li><code>cp /etc/fstab /root/etc/fstab</code></li><li><code>exit</code> # chroot</li><li> <code>for fs in proc sys dev/pts dev; do umount /mnt/$fs; done<br
/> umount /mnt</code></li><li>Let&#8217;s enter the new root subvolume!<br
/> <code>mount -o subvol=root /dev/sda1 /mnt<br
/> for fs in proc sys dev dev/pts; do mount --bind /$fs /mnt/$fs; done<br
/> chroot /mnt</code></li><li>Oh, we forgot to move back root_orig into /root! That&#8217;s easy: <code>mv root_orig root</code>. If you want your root&#8217;s aliases/profile to load, then just <code>exit</code> and <code>chroot /mnt</code> again (I had to do that for the nice pre-configured prompt colours <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /> )</li><li><code>btrfs subvolume list /</code> to see our new and shiny subvolumes:<br
/><blockquote><p> ID 256 gen 8 top level 5 path ext2_saved<br
/> ID 260 gen 49 top level 5 path root<br
/> ID 261 gen 35 top level 5 path home<br
/> ID 262 gen 42 top level 5 path log</p></blockquote></li><li>Let&#8217;s make <strong>root</strong> the default subvolume! If suddenly <em>rootflags</em> get lost during grub configuration, then the system should still be able to boot. Subvol ID comes from the output of the command above (260 in my case):<br
/> <code>btrfs subvolume set-default 260 /</code> # no output<br
/> <code>btrfs subvolume get-default /</code> # to verify</p><blockquote><p>ID 260 gen 49 top level 5 path root</p></blockquote></li><li>Now let&#8217;s check grub-mkconfig output: <code>grub-mkconfig | grep " ro "</code>. Now that the subvolume exists, it does show all the desired <em>rootflags=subvol=root</em>.</li><li>Let&#8217;s make sure our system will be bootable:<br
/> <code>update-grub<br
/> grub-install /dev/sda</code></li><li>Leave the chroot:<br
/> <code>exit<br
/> for fs in proc sys dev/pts dev; do umount /mnt/$fs; done<br
/> umount /mnt</code></li><li>Now let&#8217;s mount top-level again, for cleanup. If you remember, we had all the <strong>/</strong> files there &#8211; which are now in the <strong>root</strong> subvolume:<br
/> <code>mount -o subvol=/ /dev/sda1 /mnt</code></li><li>Navigate to /mnt (<code>cd /mnt</code>, yes <img
src="https://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> ) and delete from here everything that is <strong>NOT</strong> a subvolume.<br
/> The command which supposedly does this is <code>find /mnt -xdev -delete</code> (<strong>-xdev</strong> is supposed to not descend into mounts of other filesystems), but I haven&#8217;t used it &#8211; was a bit tired and did not want to screw up the so-far-successful conversion, so I just did <code>rm -rf bin boot dev etc initrd.img lib lib64 lost+found media mnt opt proc run sbin srv sys tmp usr vmlinuz var root_orig</code> &#8211; basically, deleted everything except for ext2_saved, home, root, and log &#8211; which are all subvolumes.</li><li>Confirm that only subvolumes are left now:<br
/> <code>ls -la</code>:</p><blockquote><p> drwxr-xr-x 1 root root  10 Feb 13 21:30 ext2_saved<br
/> drwxr-xr-x 1 root root   0 Feb 13 22:04 home<br
/> drwxr-xr-x 1 root root 510 Feb 13 22:13 log<br
/> drwxr-xr-x 1 root root 318 Feb 13 22:18 root</p></blockquote><p><code>btrfs subvolume list /mnt</code>:</p><blockquote><p> ID 256 gen 8 top level 5 path ext2_saved<br
/> ID 260 gen 52 top level 5 path root<br
/> ID 261 gen 35 top level 5 path home<br
/> ID 262 gen 42 top level 5 path log</p></blockquote><p><code>btrfs subvolume get-default /mnt</code>:</p><blockquote><p>ID 260 gen 52 top level 5 path root</p></blockquote></li><li>We can leave now: <code>cd / &#038;&#038; umount /mnt</code></li><li>Reboot into the new system. If this fails: can boot rescue again, chroot and check what went wrong&#8230;</li><li>In my case, conversion seemed to have succeeded, BUT: a) for some reason <strong>/toplevel</strong> was mounted at boot and full of root-like files which should not have been there anymore; b) I could not delete <strong>ext2_saved</strong>, at all, neither from <strong>/</strong> nor from <strong>/toplevel</strong>. The problem was with the <strong>toplevel</strong> mount line in <strong>/etc/fstab</strong> (initially, I forgot to specify the filesystem type). After fixing this and rebooting once more, everything was perfect: <strong>/toplevel</strong> not mounted, and when mounted it only had subvolumes in it. And of course the system booted without any problems. Now I could delete the previous filesystem snapshot: <code>mount /toplevel; btrfs subvolume delete /toplevel/ext2_saved; umount /toplevel</code>. Note that there was also another, different <strong>ext2_saved</strong> in the <strong>root</strong> subvolume: it is NOT a subvolume, which was not carried over when we created the <strong>/</strong> snapshot &#8211; only the empty directory was left in place. (Yes, snapshots do not descend into subvolumes.)</li></ol><p>The last 2 commands to issue (after <code>mount /toplevel</code>) are <code>btrfs filesystem defragment -r /toplevel</code> and <code>btrfs balance start /toplevel</code>.<br
/> I&#8217;m not including them in the instructions above: they are not strictly required, and if your filesystem had some heavy use before conversion, you may want to run these 2 commands more intelligently, in phases (metadata first, then big files, then smaller, etc). Another reason is that it may produce significant system load. On my fresh system both finished very quickly.</p><p>&#8230;And we are done!</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&amp;linkname=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&amp;linkname=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&amp;linkname=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&amp;linkname=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&amp;linkname=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2016%2F02%2F15%2Fhow-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html&#038;title=How%20to%3A%20convert%20your%20VPS%20root%20filesystem%20to%20btrfs%20%28using%20rescue%20boot%29" data-a2a-url="https://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html" data-a2a-title="How to: convert your VPS root filesystem to btrfs (using rescue boot)"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2016/02/15/how-to-convert-your-vps-root-filesystem-to-btrfs-using-rescue-boot.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>