Btrfs https://tech.feedyourhead.at/tags/btrfs en BTRFS: Solving issues with copy-on-write https://tech.feedyourhead.at/content/btrfs-problems-with-cow <span class="field field--name-title field--type-string field--label-hidden">BTRFS: Solving issues with copy-on-write</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><img alt="" height="592" src="https://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/Btrfs_logo.png" width="592" /></p> <p>I really like BTRFS, that's <a href="https://tech.feedyourhead.at/tags/btrfs">why I write so much about it</a>. But there are some issues with it. BTRFS is based on the copy-on-write principle but this can create some real troubles with virtualisation or databases. Therefore I will explain in this article how to disable cow.</p> <h2>Problems with copy-on-write</h2> <p>I experienced some strange problems with my VirtualBox-Machines. <a href="https://www.virtualbox.org/ticket/11862">If I start a virtual machine, it just freezes</a>. I didn't find anything in the logfiles and I could only fix the problem by disabling copy-on-write on that machine AND revert to a previous snapshot(lucky me that I had one).</p> <h2>Mounting without copy-on-write</h2> <p>It is possible to disable copy-on-write using the mount-option "nodatacow". This <strong>option has no effect on existing files</strong> and copy-on-write will only be disabled for new files. It's also good to know that this option <strong>disables all compression</strong>. A subvolume could be mounted using the following fstab-line:</p> <pre> <code> LABEL=RAIDBUTTER /vms btrfs subvol=VMS,nodatacow,defaults,auto 0 0 </code></pre> <h2>Disabling cow for specific files</h2> <p>It is also possible to disable copy-on-write for specific files only using chattr. Again this<strong> only works for new and empty files</strong>. So lets create a file and check it's attributes:</p> <pre> <code> touch somefile lsattr somefile ---------------- somefile </code></pre> <p>Now let's disable copy-on-write on this file:</p> <pre> <code> chattr +C somefile </code></pre> <p>To check the attributes of a file we can use lsattr:</p> <pre> <code> lsattr somefile ---------------C somefile </code></pre> <p>It is also possible to disable cow on directories. Then all new files will automatically be created with the no-data-cow-flag enabled. Also on directory it is important to know that <strong>this only works on empty directories</strong>!</p> <p>In the following example I will create a new directory, set the no-data-cow-flag and then create a new file:</p> <pre> <code> mkdir somedir lsattr -d somedir ---------------- somedir chattr +C somedir lsattr -d somedir ---------------C somedir touch somedir/somefile lsattr somedir ---------------C somedir/somefile </code></pre> <h2>But what about existing files?</h2> <p>All changes from above just work on empty files. If we want to convert an existing file, we really have to recreate the file and change the attributes before filling the content of the file. nocow.sh can do this for us:</p> <pre> <code> #!/bin/bash if [ $# != 2 ] then echo "Usage: $0 <file> <tmpfile>" exit 0 fi FILE=$1 TMP=$2 if ! [ -e $FILE ] then echo "$FILE doesn't exist" exit 0 fi if [ -d $FILE ] then echo "directories are not supported yet." exit 0 fi echo "Converting $FILE(via $TMP).." touch $TMP chattr +C $TMP dd if=$FILE of=$TMP bs=1M rm $FILE mv $TMP $FILE exit 0 </tmpfile></file></code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Apr 05 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/btrfs" hreflang="en">Btrfs</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/virtualization" hreflang="en">Virtualization</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=174&amp;2=comment&amp;3=comment" token="fV_YEucw6y-hcyWQtaNg19lOaPg7pdUd4vUf7sOtz9A"></drupal-render-placeholder> </section> Tue, 05 Apr 2016 07:22:09 +0000 Hoti 174 at https://tech.feedyourhead.at Snapper: Awesome Snapshot-Manager https://tech.feedyourhead.at/content/snapper-awesome-snapshot-manager <span class="field field--name-title field--type-string field--label-hidden">Snapper: Awesome Snapshot-Manager</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><a href="http://snapper.io/">Snapper</a> is a snapshot-manager for Linux. It can create, delete and compare snapshots and undo changes done between snapshots. It supports btrfs and <a href="http://tech.feedyourhead.at/content/lvm-thin-provisioning-volumes">LVM with thin-provisioning</a>. Snapper can also automatically create snapshots(with cleanup strategies of old snapshots).</p> <h3>Install</h3> <pre> <code> echo "deb http://download.opensuse.org/repositories/filesystems:/snapper/Debian_8.0/ /" &gt;&gt; /etc/apt/sources.list.d/snapper.list wget http://download.opensuse.org/repositories/filesystems:snapper/Debian_8.0/Release.key apt-key add - &lt; Release.key apt-get update apt-get install snapper </code></pre> <h3>Create a config</h3> <p>Let' assume we have a btrfs-subvolume mounted in /home. Then we can create a config for it using the following command:</p> <pre> <code> snapper -c Home create-config /home </code></pre> <p>Snapper creates a config-file under /etc/snapper/configs/Home:</p> <pre> <code> # subvolume to snapshot SUBVOLUME="/home" # filesystem type FSTYPE="btrfs" # users and groups allowed to work with config ALLOW_USERS="" ALLOW_GROUPS="" # sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots # directory SYNC_ACL="no" # start comparing pre- and post-snapshot in background after creating # post-snapshot BACKGROUND_COMPARISON="yes" # run daily number cleanup NUMBER_CLEANUP="yes" # limit for number cleanup NUMBER_MIN_AGE="1800" NUMBER_LIMIT="50" NUMBER_LIMIT_IMPORTANT="10" # create hourly snapshots TIMELINE_CREATE="yes" # cleanup hourly snapshots after some time TIMELINE_CLEANUP="yes" # limits for timeline cleanup TIMELINE_MIN_AGE="1800" TIMELINE_LIMIT_HOURLY="10" TIMELINE_LIMIT_DAILY="10" TIMELINE_LIMIT_WEEKLY="0" TIMELINE_LIMIT_MONTHLY="10" TIMELINE_LIMIT_YEARLY="10" # cleanup empty pre-post-pairs EMPTY_PRE_POST_CLEANUP="yes" # limits for empty pre-post-pair cleanup EMPTY_PRE_POST_MIN_AGE="1800" </code></pre> <p>As we can see, snapper will automatically create snapshots</p> <p>We can list all configs calling:</p> <pre> <code> root@tardis:/home/dr# snapper list-configs Konfiguration | Subvolumen --------------+----------- root | /mnt/Raid Home | /home </code></pre> <h3>Creating manual snapshots</h3> <pre> <code> snapper -c Home create -d "First cool snapshot" snapper -c Home list Typ | # | Vorher # | Datum | Benutzer | Bereinigen | Beschreibung | Benutzerdaten -------+---+----------+------------------------------+----------+------------+---------------------+-------------- single | 0 | | | root | | current | single | 1 | | Fre 11 Mär 2016 15:17:01 CET | root | timeline | timeline | single | 2 | | Fre 11 Mär 2016 15:22:33 CET | root | | First cool snapshot | </code></pre> <h3>Delete Snapshots</h3> <p>Automatically created Snapshots will also be deleted automatically. If you want to manually delete some snapshots it's easy like creating them:</p> <pre> <code> snapper -c Home delete 2 snapper -c Home list Typ | # | Vorher # | Datum | Benutzer | Bereinigen | Beschreibung | Benutzerdaten -------+---+----------+------------------------------+----------+------------+--------------+-------------- single | 0 | | | root | | current | single | 1 | | Fre 11 Mär 2016 15:17:01 CET | root | timeline | timeline | </code></pre> <h3>Mounting Snapshots</h3> <p>If you want to mount any snapshot you can just call:</p> <pre> <code> snapper -c Home mount 1 ls -l /home/.snapshots/1/snapshot/ insgesamt 4 -rw-r--r-- 1 dr dr 189 Jun 9 2007 tardis.txt drwx------ 1 rose rose 2392 Sep 18 2013 rose drwx------ 1 dr dr 8966 Mär 11 15:15 dr drwx------ 1 dr dr 2916 Jul 10 2009 dr_old snapper -c Home umount 1 </code></pre> <h3>Final Words</h3> <p>Snapper is great. It's very easy to use. If you create a config it will automatically create hourly snapshots and rotate them. I mostly use snapper in combination with BTRFS and LXC-Container. But I also have other configurations using <a href="http://tech.feedyourhead.at/content/lvm-thin-provisioning-volumes">thin provisioned LVM's</a> for example. I think it's a great addition to backups since it's very lightweight.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mar 11 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/btrfs" hreflang="en">Btrfs</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/lvm" hreflang="en">LVM</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/virtualization" hreflang="en">Virtualization</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=169&amp;2=comment&amp;3=comment" token="hj7RSHHwLy1uI777D_SlLZhpES_bJ_hwHeFeU9b7Vwk"></drupal-render-placeholder> </section> Fri, 11 Mar 2016 14:06:28 +0000 Hoti 169 at https://tech.feedyourhead.at BTRFS: monitoring raid errors https://tech.feedyourhead.at/content/BTRFS-monitoring-raid-errors <span class="field field--name-title field--type-string field--label-hidden">BTRFS: monitoring raid errors</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><img alt="" height="592" src="https://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/Btrfs_logo.png" width="592" /></p> <p>Btrfs has it's builtin tool for displaying IO stats on devices:</p> <pre> <code> root@tardis:# btrfs device stats /mnt/Raid/ [/dev/sdb].write_io_errs 0 [/dev/sdb].read_io_errs 0 [/dev/sdb].flush_io_errs 0 [/dev/sdb].corruption_errs 0 [/dev/sdb].generation_errs 0 [/dev/sdc].write_io_errs 0 [/dev/sdc].read_io_errs 0 [/dev/sdc].flush_io_errs 0 [/dev/sdc].corruption_errs 0 [/dev/sdc].generation_errs 0 </code></pre> <p>A simple cronjob could warn us if anything is wrong:</p> <pre> <code> MAILTO=sysadmin@tardis.tdl @hourly /sbin/btrfs device stats /mnt/Raid | grep -vE ' 0$' </code></pre> <p>It's wisely to scrub the filesystem from time to time. Wikipedia says the following about "<a href="https://en.wikipedia.org/wiki/Data_scrubbing">Data scrubbing</a>":</p> <blockquote> <p><b>Data scrubbing</b> is an <a class="mw-redirect" href="https://en.wikipedia.org/wiki/Error_correction" title="Error correction">error correction</a> technique that uses a background task to periodically inspect <a class="mw-redirect" href="https://en.wikipedia.org/wiki/Main_memory" title="Main memory">main memory</a> or <a href="https://en.wikipedia.org/wiki/Computer_data_storage" title="Computer data storage">storage</a> for errors, and then correct detected errors using <a href="https://en.wikipedia.org/wiki/Data_redundancy" title="Data redundancy">redundant data</a> in form of different <a href="https://en.wikipedia.org/wiki/Checksum" title="Checksum">checksums</a> or copies of data. Data scrubbing reduces the likelihood that single correctable errors will accumulate, leading to reduced risks of uncorrectable errors.</p> </blockquote> <p>If we don't scrub, it could happen that BTRFS only reads from the good drive without detecting the faulty drive</p> <pre> <code> @monthly /sbin/btrfs scrub start -Bq /mnt/Raid </code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Feb 16 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/btrfs" hreflang="en">Btrfs</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=162&amp;2=comment&amp;3=comment" token="VOhAbVmTjShBF_ttR2Dro60MnCRVZ4QlgoYvEwuz_CY"></drupal-render-placeholder> </section> Tue, 16 Feb 2016 08:00:12 +0000 Hoti 162 at https://tech.feedyourhead.at Btrfs: Turning a mdadm-array into a btrfs https://tech.feedyourhead.at/content/btrfs-turning-mdadm-array-btrfs <span class="field field--name-title field--type-string field--label-hidden">Btrfs: Turning a mdadm-array into a btrfs</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><img alt="" src="http://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/Btrfs_logo.png" /></p> <p>Btrfs is supposed to be the "better filesystem". It is easy to use and has a nice feature-list. Since I had some troubles with a raid1 using mdadm in the past, I will try to turn my private raid-array in a btrfs. In this article I will not post the mdadm-commands(and lvm2 commands)...</p> <p>First I just remove one disk from my array and format it with btrfs:</p> <pre> <code> mkfs.btrfs /dev/sdc </code></pre> <p>Now I have a single disk in my btrfs. The cool thing about btrfs is, that I can convert my btrfs to any supported raid during runtime. This feature I want to test. So first I will mount mount btrfs but I want to use compression on my filesystem. It's super easy to use compression since it's just a mount-option. I just created an entry in my /etc/fstab:</p> <pre> <code> /dev/sdc /mnt/Raid btrfs compress=zlib,defaults 0 0 </code></pre> <p>Now I can mount my btrfs:</p> <pre> <code> mount /mnt/Raid </code></pre> <p>Now I can easily copy(for example using rsync) my data from the old mdadm-raid to my btrfs. Once this is done, I will just delete my mdadm-array and destroy the raid-meta-data using --zero-superblock(<strong>I made a backup of all my data before!</strong>). After that I have a plain disk(/dev/sdb) and I will add this disk to my btrfs:</p> <pre> <code> btrfs device add /dev/sdb /mnt/Raid/ </code></pre> <p>Finally I was very courious if I can convert the btrfs into a raid1 using the following command:</p> <pre> <code> btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt/Raid </code></pre> <p>This job runs in foreground so I would recommend using screen for it. It might take a long time. If you want to monitor the progress you can just use this command:</p> <pre> <code> watch -n1 btrfs fi df /mnt/Raid </code></pre> <p>The following one-shot-command gives a good overview about your btrfs:</p> <pre> <code> btrfs fi show; btfs fi df /mnt/Raid </code></pre> <p>It really worked like expected. I just converted my single btrfs to a raid1 using 2 disks. But I have one problem: the filesystem is mounted using this fstab-entry:</p> <pre> <code> /dev/sdc /mnt/Raid btrfs compress=zlib,defaults 0 0 </code></pre> <p>What if /dev/sdc gets broken? Then I would have to manually mount /dev/sdb. It does not matter which device I do mount since both get synchronized but if the device doesn't exist, the system would not be able to mount my filesystem. So I created a filesystem-label:</p> <pre> <code> btrfs filesystem label /mnt/Raid/ RAIDBUTTER </code></pre> <p>And I changed my fstab-entry into:</p> <pre> <code> LABEL=RAIDBUTTER /mnt/Raid btrfs compress=zlib,defaults 0 0 </code></pre> <p>It's not the end for me. Until now, I mounted my mdadm-raid and on this partition I had a directory for all my home-directories. This directory I mounted using bind-mount into /home. It was good enough for me, but it just feels like a dirty hack. Btrfs gives me the opportunity to create subvolumes. Those subvolumes I can mount wherever I want and it is just a directory in my normal btrfs. I created my subvolume using this command:</p> <pre> <code> btrfs subvolume create /mnt/Raid/Home </code></pre> <p>At last I can mount it using this fstab-line:</p> <pre> <code> LABEL=RAIDBUTTER /home btrfs subvol=Home,compress=zlib,auto,user 0 0 </code></pre> <p>Great, isn't it? In summary I can say that I really like the btrfs. It is very easy to use and has a nice feature list.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Aug 30 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/filesystem" hreflang="en">Filesystem</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/btrfs" hreflang="en">Btrfs</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/software-raid" hreflang="en">Software-Raid</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=102&amp;2=comment&amp;3=comment" token="F9wTP5enL8AmVIRvOmgO7TVSiZzXEZgCZECe7Mia3jg"></drupal-render-placeholder> </section> Sun, 30 Aug 2015 18:58:12 +0000 Hoti 102 at https://tech.feedyourhead.at