Difference between revisions of "Btrfs/en"

Updating to match new version of source page
(Updating to match new version of source page)
(Updating to match new version of source page)
 
Line 6: Line 6:
Because Btrfs is different, some things seem unfamiliar and strange. If you want to learn the details and the newest stuff, then [https://btrfs.wiki.kernel.org/index.php/Main_Page btrfs.wiki.kernel.org] is the place to go or [https://btrfs.readthedocs.io/en/latest/index.html btrfs.readthedocs.io].
Because Btrfs is different, some things seem unfamiliar and strange. If you want to learn the details and the newest stuff, then [https://btrfs.wiki.kernel.org/index.php/Main_Page btrfs.wiki.kernel.org] is the place to go or [https://btrfs.readthedocs.io/en/latest/index.html btrfs.readthedocs.io].
Development of Btrfs started in 2007. Since that time, Btrfs is a part of the Linux kernel and is under active development. The Btrfs code base and filesystem-layout is '''[https://btrfs.wiki.kernel.org/index.php/Status stable] .''' However, new features are still under development. Its main features and benefits are:
Development of Btrfs started in 2007. Since that time, Btrfs is a part of the Linux kernel and is under active development. The Btrfs code base and filesystem-layout is '''[https://btrfs.wiki.kernel.org/index.php/Status stable] .''' However, new features are still under development. Its main features and benefits are:
*'''Snapshots''' which do not make the full copy of files
*'''Snapshots''' which do not make a full copy of files
*'''Volume Manager''' join partitions, split into subvolumes
*'''Volume Manager''' join partitions, split into subvolumes
*'''RAID''' - support for software-based RAID 0, RAID 1, RAID 10
*'''RAID''' - support for software-based RAID 0, RAID 1, RAID 10
Line 19: Line 19:
Because Btrfs is different, you will find some words that do have a special meaning when used for btrfs. This may be a source of confusion.  
Because Btrfs is different, you will find some words that do have a special meaning when used for btrfs. This may be a source of confusion.  


<div class="mw-collapsible mw-collapsed"><div class="mw-collapsible-toggle" style="float:none;">▶ Btrfs '''volume'''</div><div class="mw-collapsible-content">A '''[[Btrfs#Btrfs_Volume|volume]]''' is a pool of raw storage and consists of one or more '''device'''s. The size of the volume will be the addition of all devices that are part of this volume. In most cases you will only use one volume. You are able to add/remove devices at any time. ''Usually you do '''not''' mount a Btrfs volume.''
<div class="mw-collapsible mw-collapsed"><div class="mw-collapsible-toggle" style="float:none;">▶ Btrfs '''volume'''</div><div class="mw-collapsible-content">A '''[[Btrfs#Btrfs_Volume|volume]]''' is a pool of raw storage and consists of one or more '''device'''s. The size of the volume will be the addition of all devices that are part of this volume. In most cases you will only use '''one''' volume. You are able to add/remove devices at any time. ''Usually you do '''not''' mount a Btrfs volume.''
</div></div>
</div></div>


Line 38: Line 38:


<div class="mw-collapsible mw-collapsed"><div class="mw-collapsible-toggle" style="float:none;">▶ '''snapshot'''</div><div class="mw-collapsible-content">A '''[[Btrfs#snapshot|snapshot]]''' looks nearly the same as a '''[[Btrfs#subvolume|subvolumes]]'''. But don´t get confused. When we talk about snapshots we usually mean a "'''Read-Only (ro) photograph''' of a subvolume". While the subvolume changes with time. A snapshot stays in the state of the subvolume at the time we made it. You can mount snapshots into your linux system, but you only can read the content. And the content will never change while this snapshot exists. When creating '''snapshots''' you have to watch out for the Btrfs-'''layout''' in use.
<div class="mw-collapsible mw-collapsed"><div class="mw-collapsible-toggle" style="float:none;">▶ '''snapshot'''</div><div class="mw-collapsible-content">A '''[[Btrfs#snapshot|snapshot]]''' looks nearly the same as a '''[[Btrfs#subvolume|subvolumes]]'''. But don´t get confused. When we talk about snapshots we usually mean a "'''Read-Only (ro) photograph''' of a subvolume". While the subvolume changes with time. A snapshot stays in the state of the subvolume at the time we made it. You can mount snapshots into your linux system, but you only can read the content. And the content will never change while this snapshot exists. When creating '''snapshots''' you have to watch out for the Btrfs-'''layout''' in use.
It is possible to make a writeable(rw) subvolume out of a ro-snapshot. This is the way '''[[Btrfs#Rollback_to_a_snapshot|roll back]]''' does work.
It is possible to make a writeable(rw) subvolume out of a ro-snapshot. This is the way '''[[Btrfs#Rollback_to_a_snapshot|roll back]]''' does work. It is also possible to send a ro-snapshot to another btrfs volume as '''[[Btrfs#Send_.2B_receive_.3D_backup_.E2.87.92|backup]]'''
</div></div>
</div></div>


Line 92: Line 92:


=== Subvolume '''@''' ===
=== Subvolume '''@''' ===
This is the subvolume where your '''complete manjaro system''' will reside. It is mounted at "/" in your filesystem. You may take snapshots of this subvolume (or backups with send/receive) to secure a running manjaro system. When something bad happens, you are able to rollback to one of the snapshots, or to restore one of the backups of this subvolume '''without loosing your data''' at /home.
This is the subvolume where your '''complete manjaro system''' will reside. It is mounted at "/" in your filesystem. You may take snapshots of this subvolume to secure a running manjaro system. When something bad happens, you are able to rollback to one of the snapshots, (or to restore one of the external backups of a snapshot) '''without changing your data''' at /home.


In order to make a rollback possible, this has to contain all and every data that is needed for your manjaro to work properly! This includes:
{{BoxInfo|In order to make a rollback possible|The snapshot has to contain all and every data that is needed for your manjaro to work properly! This includes:
* '''config''' of your bootloader (/boot/brub/grub.cfg)
* '''config''' of your bootloader (/boot/brub/grub.cfg)
* '''initramdisk''' (/boot/initramfs-5.10-x86_64.img)
* '''initramdisk''' (/boot/initramfs-6.xx-x86_64.img)
* '''kernel''' (/boot/vmlinuz-5.10-x86_64)
* '''kernel''' (/boot/vmlinuz-6.xx-x86_64)
* '''kernel-modules''' (/usr/lib/modules/5.10.59-1-MANJARO/*)
* '''kernel-modules''' (/usr/lib/modules/6.xx.xx-x-MANJARO/*)
* programs (/usr/bin/*)
* programs (/usr/bin/*)
* configs (/etc/*)
* configs (/etc/*)
Line 104: Line 104:
* your root account (/root/*)
* your root account (/root/*)
* rest of system files (/usr/*)
* rest of system files (/usr/*)
}}


=== Subvolume '''@home''' ===
=== Subvolume '''@home''' ===
Line 119: Line 120:
{{RootCmd|command=btrfs subvolume create [/mnt/@tests]}}
{{RootCmd|command=btrfs subvolume create [/mnt/@tests]}}
This will be shown by  
This will be shown by  
{{RootCmd|command=ls -l /mnt}}
{{RootCmd|command=ls -lA /mnt}}
{{RootCmd|command=btrfs subvolume list /mnt}}
{{RootCmd|command=btrfs subvolume list /mnt}}
This subvolume '''tests''' is empty. And it is not mounted by default. So if you want to use it, you have to mount it by ''fstab'' or other means. '''Now lets delete it again.'''
This subvolume '''tests''' is empty. And it is not mounted by default. So if you want to use it, you have to mount it by ''fstab'' or other means. '''Now lets delete it again.'''
Line 145: Line 146:
=== Taking snapshots ===
=== Taking snapshots ===


Taking a snapshot is '''very fast''', and '''nearly priceless'''. After the snapshot is taken, all future writes will go as in CoW usual. But none of the space occupied by files in the snapshot will be reusable. As you write more and more new files, the filesystem will grow because it can not reuse the files in the snapshot. A new snapshot will freeze additionally all created or modified files since the last snapshot and so on. '''If you don´t release'''(delete) any snapshot '''you will''' eventually '''run out of space''' soon(disk full)
Taking a snapshot is '''very fast''', and '''nearly priceless'''. After the snapshot is taken, all future writes will go as in CoW usual. But none of the space occupied by files in the snapshot will be reusable. As you write more and more new files, the filesystem will grow because it can not reuse the files in the snapshot. A new snapshot will freeze additionally all created or modified files since the last snapshot and so on. '''If you don´t release'''(delete) any snapshot '''you will''' eventually '''run [[Btrfs#Out_of_space|out of space]]''' soon.


=== Releasing snapshots ===
=== Releasing snapshots ===
Line 151: Line 152:
Deleting a snapshot does not delete any files that are actually in use by other snapshots or the subvolume they where taken from. To free some space, Btrfs has to test for every file in the snapshot, whether it is in use, or it is not. If it is not, the space of this file/version will become free.(This is greatly simplified) Therefore it is '''costly to remove snapshots'''. And Btrfs will do this work in the background. You may notice this, because when you delete a snapshot there will be '''no immediate gain in free space'''. After a while you will notice that some space has become free.
Deleting a snapshot does not delete any files that are actually in use by other snapshots or the subvolume they where taken from. To free some space, Btrfs has to test for every file in the snapshot, whether it is in use, or it is not. If it is not, the space of this file/version will become free.(This is greatly simplified) Therefore it is '''costly to remove snapshots'''. And Btrfs will do this work in the background. You may notice this, because when you delete a snapshot there will be '''no immediate gain in free space'''. After a while you will notice that some space has become free.


Don´t forget to remove snapshots, or you will get in '''"out of space" -trouble soon'''. Btrfs needs some free space to manage its work. If your volume is more then 80% full you have to think(fast) what to do.
It's best to delete snapshots using the tool that created them.
* ++++ '''Add''' some partition/device to the volume
* If you used Snapper to create them, delete them using Snapper.
* If you used Timeshift to create them, delete them using Timeshift.
* If you created them manually, delete them manually.
 
Don´t forget to remove snapshots, or you will get in '''[[Btrfs#Out_of_space|out of space]]-trouble soon'''. Btrfs needs some free space to manage its work. If your volume is more then 85% full you have to think(fast) what to do.
* ++++ '''[[Btrfs#Extend_a_volume|Add]]''' some partition/device to the volume
* +++ '''Remove''' some snapshots you don't need
* +++ '''Remove''' some snapshots you don't need
* ++ [[Btrfs#Compression_.E2.87.92|Compress]] your volume  
* ++ [[Btrfs#Compression_.E2.87.92|Compress]] your volume  
* + '''Delete''' some files (this does only help if they are not part of any snapshot)
* + '''Delete''' some files (This does only help if they are not part of '''any''' snapshot)


=== Rollback to a snapshot ===
=== Rollback to a snapshot ===


If you need to roll back into a snapshot you have to replace the actual subvolume by the chosen snapshot.
If you need to roll back into a snapshot you have to '''replace''' the actual subvolume by the chosen snapshot.
# '''Make a snapshot(ro)''' of the actual subvolume (for later reference)
# '''Make a snapshot(ro)''' of the actual subvolume (for later reference)
# '''Delete the subvolume''' out of its actual place
# '''Delete the subvolume''' out of its actual place
Line 168: Line 174:


Please also have a look at [https://github.com/jrabinow/snapper-rollback snapper-rollback@github] and at [https://wiki.archlinux.org/title/Snapper#Suggested_filesystem_layout snapshot-layout@wiki.archlinux] for the suggested flat layout and the reasoning. ([https://forum.manjaro.org/t/how-to-manual-rollback-with-btrfs/80230 Rollback example ])
Please also have a look at [https://github.com/jrabinow/snapper-rollback snapper-rollback@github] and at [https://wiki.archlinux.org/title/Snapper#Suggested_filesystem_layout snapshot-layout@wiki.archlinux] for the suggested flat layout and the reasoning. ([https://forum.manjaro.org/t/how-to-manual-rollback-with-btrfs/80230 Rollback example ])
{{BoxWarning|Don't forget to remove snapshots before you run out of space|Every time you take a snapshot you only use the "rest of the volume" for storing everything you change from this time on. At some point in time you have to release the snapshot. Don´t use your space up. Btrfs needs '''space to breath.''' Don't use more then '''90%''' or you will get into trouble."}}
{{BoxWarning|Don't forget to remove snapshots before you run out of space|Every time you take a snapshot you only use the "rest of the volume" for storing everything you change from this time on. At some point in time you have to release the snapshot. Don´t use your space up. Btrfs needs '''space to breath.''' Don't use more then '''90%''' or you will get deep into trouble."}}
{{BoxDanger|NO Snapshots together with quotas|There are reports about massive problems when using '''quotas''' together with snapshots (snapper, timeshift). Please have a look at: [https://btrfs.wiki.kernel.org/index.php/Quota_support#Known_issues Known_issues@btrfs.kernel.org]}}
{{BoxDanger|NO Snapshots together with quotas|There are reports about massive problems when using '''quotas''' together with snapshots (snapper, timeshift). Please have a look at: [https://btrfs.wiki.kernel.org/index.php/Quota_support#Known_issues Known_issues@btrfs.kernel.org]}}


Line 194: Line 200:
== [https://btrfs.readthedocs.io/en/latest/mkfs.btrfs.html#raid1 RAID 1] (mirrored), [https://btrfs.readthedocs.io/en/latest/mkfs.btrfs.html#raid1c3 1C3], [https://btrfs.readthedocs.io/en/stable/mkfs.btrfs.html#man-mkfs-profiles 1C4] ==
== [https://btrfs.readthedocs.io/en/latest/mkfs.btrfs.html#raid1 RAID 1] (mirrored), [https://btrfs.readthedocs.io/en/latest/mkfs.btrfs.html#raid1c3 1C3], [https://btrfs.readthedocs.io/en/stable/mkfs.btrfs.html#man-mkfs-profiles 1C4] ==


When using Raid 1 btrfs mirrors data and metadata. This way it is possible to repair data when one copy gets damaged. This could happen when one device fails, when power was lost while writing, ... '''After enabling RAID1''' all new data and metadata is automatically mirrored. To mirror your existing data and metadata, '''you have to balance your complete volume'''.
When using RAID 1 btrfs mirrors '''data and metadata'''. This way it is possible to repair data when one copy gets damaged. This could happen when one device fails, when power was lost while writing, ... '''After enabling RAID1''' all new data and metadata is automatically mirrored. To mirror your existing data and metadata, '''you have to balance your complete volume'''.  


=== Automatic repair ===
=== Automatic repair ===
In order to preserve the integrity of the volume, Btrfs does separate CRC-checksums of metadata blocks and of data blocks. Every time a data block is read, the checksum is verified. When the checksum shows that the data is not good, Btrfs tries to get a good copy from the mirrored block. Then the bad block is written again with the good data from the mirrored block. This happens in background. The filesystem has been repaired, and this is logged into syslog. This can be forced by using btrfs scrub.
In order to preserve the integrity of the volume, Btrfs does separate CRC-checksums of metadata blocks and of data blocks. Every time a data block is read, the checksum is verified. When the checksum shows that the data is not good, Btrfs tries to get a good copy from the mirrored block. Then the bad block is written again with the good data from the mirrored block. This happens in background. The filesystem has been repaired, and this is logged into syslog. This repair can be forced by using btrfs scrub.


=== [https://btrfs.readthedocs.io/en/stable/mkfs.btrfs.html#man-mkfs-profiles RAID 10] (automatic) ===
=== [https://btrfs.readthedocs.io/en/stable/mkfs.btrfs.html#man-mkfs-profiles RAID 10] (automatic) ===
When using enough devices(4...) with RAID 1, Btrfs will distribute all data, so that it not only is mirrored but also striped.
When using enough devices(4...) with RAID 1, Btrfs will distribute all data, so that it not only is mirrored but also striped.
{{BoxInfo|Bulletproof your system|If you have enough storage space and it is spread across 2 devices, it is really advisable to use btrfs RAID1/10. This will cover a whole range of risks that would be impossible to manage without RAID. At the same time, RAID in BTRFS is as straightforward as it gets.
}}


== RAID 5 ==
== RAID 5 ==
Line 284: Line 292:
=== Get out of jail ===
=== Get out of jail ===
This said, there is an '''easy way out''': Give btrfs more space ;-)
This said, there is an '''easy way out''': Give btrfs more space ;-)
* '''add a partition''' (for example a extern USB-Stick with 8GB) to the btrfs-volume with{{RootCmd|command=btrfs device add /dev/[sdz4] /}}
* '''add a (unformatted) partition''' (for example a fast extern USB-Stick with 8GB) to the btrfs-volume with{{RootCmd|command=btrfs device add /dev/[sdz4] /}}
* From now on this usb-partition belongs to your volume! Do not boot without it. '''Do not reboot''' at all in this stage! This stick has to stay until btrfs device remove has completed.
{{BoxDanger|Do NOT remove this USB-Stick|From now on this partition belongs to your volume! '''Do not boot without it'''. If possible do not reboot at all in this stage! This USB-stick has to stay until '''btrfs device remove''' has '''completed'''.}}
* look for old snapshots you don´t need, remove them '''now'''
* look for old snapshots you don´t need, remove them '''now'''
* '''or delete some files''' you do not need  
* '''or delete some files''' you do not need  
Line 292: Line 300:
Do not get confused if btrfs does not immediately display the vacant space. After the next step (balance) it will become visible.
Do not get confused if btrfs does not immediately display the vacant space. After the next step (balance) it will become visible.


* '''balance''' your volume with a filter(50%) This '''will''' take some time !
* '''balance''' your volume with a filter(50%) This '''will''' take some time !{{RootCmd|command=btrfs balance start -dusage=50 /}}
{{RootCmd|command=btrfs balance start -dusage=50 /}}
{{BoxSuccess|Tip: Want to watch the volume clean up ?|{{UserCmd|command=pamac install procps-ng}}}}
{{BoxSuccess|Tip: Want to watch the volume clean up ?|
{{BoxSuccess||After that inside a terminal: {{RootCmd|command=watch -n 60 btrfs filesystem usage -h / }}}}  
{{UserCmd|command=pamac install procps-ng}}}}
* If neccesary '''balance''' your volume with a filter(90%) This '''will''' take some more time !{{RootCmd|command=btrfs balance start -dusage=95 /}}
{{BoxSuccess|After that inside a terminal:|
{{RootCmd|command=watch -n 60 btrfs filesystem usage -h / }}}}  
* '''balance''' your volume with a filter(95%) This '''will''' take some more time !
{{RootCmd|command=btrfs balance start -dusage=95 /}}


* '''remove the added partition''' from the volume with {{RootCmd|command=btrfs device remove /dev/[sdz4] /}}
* '''remove the added partition''' from the volume with {{RootCmd|command=btrfs device remove /dev/[sdz4] /}}
* This '''will''' take some time ! '''Do not reboot until this step is complete'''.
* This '''will''' take some time ! '''Do not reboot until this step is complete'''.
* Now you may remove the USB-Stick.
* After "btrfs remove" has finished successfully, you can remove the USB stick.


=== Stay out of jail ===
=== Stay out of jail ===
8,673

edits