{"id":334,"date":"2015-09-19T15:27:32","date_gmt":"2015-09-19T19:27:32","guid":{"rendered":"http:\/\/www.mufljuz.com\/?p=334"},"modified":"2017-10-24T13:05:50","modified_gmt":"2017-10-24T17:05:50","slug":"btrfs-raid6","status":"publish","type":"post","link":"https:\/\/www.mufljuz.com\/?p=334","title":{"rendered":"Btrfs raid6"},"content":{"rendered":"<p>See <a href=\"https:\/\/wiki.archlinux.org\/index.php\/Btrfs\">archlinux<\/a> for more&#8230;<br \/>\nCreate btrfs filesystem using raid6 for data and and raid 10 for metadata<br \/>\n<code><br \/>\nmkfs.btrfs -d raid6 -m raid10 -L alexandria_btrfs \/dev\/vd[bcdefghijk]<br \/>\n<\/code><\/p>\n<p>Mount newly created partition with<br \/>\n<code><br \/>\nmount \/dev\/sdb \/mnt\/md0<br \/>\n<\/code><\/p>\n<p>Check file system usage with:<br \/>\n<code><br \/>\nbtrfs filesystem df \/mnt\/md0<br \/>\n<\/code><\/p>\n<h2>Removing devices<\/h2>\n<p>Remove a drive from the file system. This should rebalance the data across the other devices. <code>btrfs device delete<\/code> is used to remove devices online. It redistributes the any extents in use on the device being removed to the other devices in the filesystem.<br \/>\n<code><br \/>\n# mount fs first<br \/>\nbtrfs device delete \/dev\/vdX \/mnt\/md0<br \/>\n<\/code><\/p>\n<h2>Adding devices<\/h2>\n<p><code>btrfs device add<\/code> is used to add new devices to a mounted filesystem.<br \/>\n<code>btrfs filesystem<\/code> balance can balance (restripe) the allocated extents across all of the existing devices. For example, with an existing filesystem mounted at \/mnt\/md0, you can add the device \/dev\/vdX to it with:<br \/>\n<code><br \/>\nbtrfs device add \/dev\/vdX \/mnt\/md0<br \/>\n<\/code><br \/>\nThis should commence a resync.<\/p>\n<p>At this point we have a filesystem with two devices, but all of the metadata and data are still stored on the original device(s). The filesystem must be balanced to spread the files across all of the devices.<br \/>\n<code><br \/>\nbtrfs filesystem balance \/mnt\/md0<br \/>\n<\/code><\/p>\n<h2>List of all the btrfs filesystems<\/h2>\n<p><code>btrfs filesystem show<\/code> gives you a list of all the btrfs filesystems on the systems and which devices they include.<br \/>\n<code><br \/>\nbtrfs filesystem show<br \/>\n<\/code><\/p>\n<pre>\r\nLabel: 'alexandria_btrfs'  uuid: abdef71f-d813-4128-bc39-de3df7e6c673\r\n        Total devices 10 FS bytes used 217.73GiB\r\n        devid    1 size 1.82TiB used 29.42GiB path \/dev\/sdb\r\n        devid    2 size 1.82TiB used 29.40GiB path \/dev\/sdc\r\n        devid    3 size 1.82TiB used 29.40GiB path \/dev\/sdd\r\n        devid    4 size 1.82TiB used 29.40GiB path \/dev\/sde\r\n        devid    5 size 1.82TiB used 29.40GiB path \/dev\/sdf\r\n        devid    6 size 1.82TiB used 29.40GiB path \/dev\/sdg\r\n        devid    7 size 1.82TiB used 29.40GiB path \/dev\/sdh\r\n        devid    8 size 1.82TiB used 29.40GiB path \/dev\/sdi\r\n        devid    9 size 1.82TiB used 29.40GiB path \/dev\/sdj\r\n        devid   10 size 1.82TiB used 29.40GiB path \/dev\/sdk\r\n\r\nbtrfs-progs v4.0.1\r\n<\/pre>\n<h2>Replacing failed devices<\/h2>\n<p>The example above can be used to remove a failed device if the super block can still be read. But, if a device is missing or the super block has been corrupted, the filesystem will need to be mounted in degraded mode:<br \/>\n<code><br \/>\nbtrfs filesystem show<br \/>\n<\/code><\/p>\n<pre>\r\nLabel: 'alexandria_btrfs'  uuid: abdef71f-d813-4128-bc39-de3df7e6c673\r\n        Total devices 10 FS bytes used 14.50TiB\r\n        devid    1 size 1.82TiB used 1.82TiB path \/dev\/sdb\r\n        devid    2 size 1.82TiB used 1.82TiB path \/dev\/sdc\r\n        devid    3 size 1.82TiB used 1.82TiB path \/dev\/sdd\r\n        devid    4 size 1.82TiB used 1.82TiB path \/dev\/sde\r\n        devid    5 size 1.82TiB used 1.82TiB path \/dev\/sdf\r\n        devid    6 size 1.82TiB used 1.82TiB path \/dev\/sdg\r\n        devid    7 size 1.82TiB used 1.82TiB path \/dev\/sdh\r\n        devid    8 size 1.82TiB used 1.82TiB path \/dev\/sdi\r\n        devid   10 size 1.82TiB used 1.82TiB path \/dev\/sdk\r\n        *** Some devices missing\r\n<\/pre>\n<p><code><br \/>\n# sdd is destroyed or removed, use -o degraded to force the mount<br \/>\n# to ignore missing devices#<br \/>\nmount -o degraded \/dev\/sdX \/mnt\/md0<br \/>\n#<br \/>\nbtrfs device delete missing \/mnt\/md0<br \/>\nbtrfs replace start 9 \/dev\/sdX_new_disk \/mnt\/md0<br \/>\nbtrfs replace status \/mnt\/md0<br \/>\n#<br \/>\n# cancel replacement with<br \/>\n# btrfs replace cancel \/dev\/md0<br \/>\n<\/code><\/p>\n<h2>Conversion<\/h2>\n<p>A non-raid filesystem is converted to raid by adding a device and running a balance filter that will change the chunk allocation profile.<br \/>\nFor example, to convert an existing single device system (\/dev\/sdX1) into a 2 device raid1 (to protect against a single disk failure):<br \/>\n<code><br \/>\nmount \/dev\/sdX1 \/mnt\/md0<br \/>\nbtrfs device add \/dev\/sdY1 \/mnt\/md0<br \/>\nbtrfs balance start -dconvert=raid1 -mconvert=raid1 \/mnt\/md0<br \/>\n<\/code><br \/>\nIf the metadata is not converted from the single-device default, it remains as DUP, which does not guarantee that copies of block are on separate devices. If data is not converted it does not have any redundant copies at all.<\/p>\n<h2>Scrub<\/h2>\n<p>Scrub is an online file system checking tool. Reads all the data and metadata on the file system, and uses checksums and the duplicate copies from RAID storage to identify and repair any corrupt data.<br \/>\n<code><br \/>\nbtrfs scrub start \/<br \/>\nbtrfs scrub status \/<br \/>\n<\/code><br \/>\n(from <a href=\"https:\/\/wiki.archlinux.org\/index.php\/Btrfs#Scrub\">archlinux<\/a>)<br \/>\nWarning: The running scrub process will prevent the system from suspending, see this thread for details.<br \/>\nIf running the scrub as a systemd service, use Type=forking. Alternatively, you can pass the -B flag to btrfs scrub start to run it in the foreground and use the default Type value.<\/p>\n<h2>Balance<\/h2>\n<p>Balance passes all data in the filesystem through the allocator again. It is primarily intended to rebalance the data in the filesystem across the devices when a device is added or removed. A balance will regenerate missing copies for the redundant RAID levels, if a device has failed. As of linux kernel 3.3, a balance operation can be made selective about which parts of the filesystem are rewritten.<br \/>\n<code><br \/>\nbtrfs balance start \/<br \/>\nbtrfs balance status \/<br \/>\n<\/code><\/p>\n<h2>Defragment<\/h2>\n<p>Btrfs supports transparent compression, meaning every file on the partition is automatically compressed. This not only reduces the size of files, but also improves performance, in particular if using the lzo algorithm, in some specific use cases (e.g. single thread with heavy file IO), while obviously harming performance on other cases (e.g. multithreaded and\/or cpu intensive tasks with large file IO).<\/p>\n<p>Compression is enabled using the compress=zlib or compress=lzo mount options. Only files created or modified after the mount option is added will be compressed. However, it can be applied quite easily to existing files (e.g. after a conversion from ext3\/4) using the btrfs filesystem defragment -calg command, where alg is either zlib or lzo. In order to re-compress the whole file system with lzo, run the following command:<br \/>\n<code><br \/>\nbtrfs filesystem defragment -r -v -clzo \/<br \/>\n<\/code><\/p>\n<p>Tip: Compression can also be enabled per-file without using the compress mount option; simply apply chattr +c to the file. When applied to directories, it will cause new files to be automatically compressed as they come.<br \/>\nWhen installing Arch to an empty Btrfs partition, set the compress option after preparing the storage drive. Simply switch to another terminal (Ctrl+Alt+number), and run the following command:<br \/>\n<code><br \/>\nmount -o remount,compress=lzo \/mnt\/target<br \/>\n<\/code><br \/>\nAfter the installation is finished, add compress=lzo to the mount options of the root file system in fstab.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>See archlinux for more&#8230; Create btrfs filesystem using raid6 for data and and raid 10 for metadata mkfs.btrfs -d raid6 -m raid10 -L alexandria_btrfs \/dev\/vd[bcdefghijk] Mount newly created partition with mount \/dev\/sdb \/mnt\/md0 Check file system usage with: btrfs filesystem df \/mnt\/md0 Removing devices Remove a drive from the file system. This should rebalance the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/334"}],"collection":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334"}],"version-history":[{"count":8,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/334\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/334\/revisions\/371"}],"wp:attachment":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}