<?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; swap</title> <atom:link href="https://bogdan.org.ua/tags/swap/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: 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>Linux: how to label swap partition w/o losing swap UUID</title><link>https://bogdan.org.ua/2010/07/16/linux-how-to-label-swap-partition-without-losing-swap-uuid.html</link> <comments>https://bogdan.org.ua/2010/07/16/linux-how-to-label-swap-partition-without-losing-swap-uuid.html#comments</comments> <pubDate>Fri, 16 Jul 2010 12:41:13 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[partition]]></category> <category><![CDATA[swap]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=1082</guid> <description><![CDATA[In short: sudo mkswap -L new_swap_label -U old_swap_UUID /dev/sd_swap_device. If you don&#8217;t care about the UUID: just sudo mkswap -L new_swap_label /dev/sd_swap_device. Step-by-step: Identify current swap UUID: grep swap /etc/fstab ; you should see a line starting with UUID=b4e6e&#8230; &#8211; note that UUID; let us assume our UUID is b4e6e5d8-8854-4a3e-8edb-f423ded31e2a Identify swap partition device. If [&#8230;]]]></description> <content:encoded><![CDATA[<p>In short: <strong>sudo mkswap -L new_swap_label -U old_swap_UUID /dev/sd_swap_device</strong>.<br
/> If you don&#8217;t care about the UUID: just <strong>sudo mkswap -L new_swap_label /dev/sd_swap_device</strong>.</p><p>Step-by-step:<br
/> <span
id="more-1082"></span></p><ol><li>Identify current swap UUID: <strong>grep swap /etc/fstab</strong> ; you should see a line starting with <strong>UUID=</strong>b4e6e&#8230; &#8211; note that UUID; let us assume our UUID is <em>b4e6e5d8-8854-4a3e-8edb-f423ded31e2a</em></li><li>Identify swap partition device. If you are using Debian or Ubuntu, device might have been shown to you when running command #1 as a comment of the form<br
/><blockquote># /dev/sdX4       none            swap    sw              0       0</p></blockquote><p> Just to be sure, run <strong>cat /proc/swaps</strong> (or <strong>sudo swapon -s</strong>), to be shown something like this:</p><p><code>Filename                                Type            Size    Used    Priority<br
/> /dev/sdX4                               partition       2104504 0       -1<br
/> </code><br
/> You can also use partition managers to identify swap device, e.g. <strong>sudo fdisk -l</strong>. Let us assume our partition device is <em>sdX4</em>.</li><li>If that swap partition is in use, you need to disable it first: <strong>sudo swapoff /dev/sdX4</strong></li><li>Now that you have both the UUID and the device, run<br
/> <strong>sudo mkswap -L new_swap_label -U b4e6e5d8-8854-4a3e-8edb-f423ded31e2a /dev/sdX4</strong><br
/> Do not forget replacing sample values above (label, UUID and device) with your actual values.</li><li>Enable swap: <strong>sudo swapon /dev/sdX4</strong></li></ol><p>Now, if you wish so, you may proceed to edit /etc/fstab and replace UUID=&#8230;. with LABEL=your_new_swap_label, leaving all other spaces and values in that line untouched.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&amp;linkname=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" 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%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&amp;linkname=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" 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%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&amp;linkname=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" 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%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&amp;linkname=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" 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%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&amp;linkname=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" 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%2F2010%2F07%2F16%2Flinux-how-to-label-swap-partition-without-losing-swap-uuid.html&#038;title=Linux%3A%20how%20to%20label%20swap%20partition%20w%2Fo%20losing%20swap%20UUID" data-a2a-url="https://bogdan.org.ua/2010/07/16/linux-how-to-label-swap-partition-without-losing-swap-uuid.html" data-a2a-title="Linux: how to label swap partition w/o losing swap UUID"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2010/07/16/linux-how-to-label-swap-partition-without-losing-swap-uuid.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>