CITATION: https://btrfs.wiki.kernel.org/index.php/Btrfs-image

Text in red is my information/notes.

Btrfs-image

Makes a compressed image of a btrfs partition (zeroed data).

More info by me: This will only backup image the METADATA (and possibly SYSTEM as well) but not DATA chunks. Thus the data will appear as zeroed out data if you take the btrfs image and restore it to a file with -r and mount the restored btrfs image – so you will see your folder and file structure (As that is kept in the metadata) but all of your files will have nothing in them (as data is zeroed out). [if you mount it from the same system where the data is, then the data will be accessible as the extents will point to the drives]. This file is useful for devs to look at.

Usage – image

btrfs-image [-r] [-c num] [-t num] source destination

Description of parameters

  • “-r”: Restore a previously made image (this makes a file which is a alike to dding a filesystem)
  • “-c”: Level of compression from 0=none over 1=lowest zlib to 9=highest zlib
  • “-t”: Number of threads used 1 to 32 (defaults to number of cpus)
  • source: when used without -r it is the device that has the btrfs filesystem on it. when used with the -r, source is the btrfs-image (which was the output or destination parameter of a previous btrfs-image command)
  • destination: its the output file. When used without -r this names the final btrfs-image file. When used with the -r this names the btrfs dd

Everything below is my addition

Usage – example making btrfs-image

btrfs-image -c 9 /dev/sda5 /root/sda5.bim
file /root/sda5.bim
# OUTPUT:
# /root/md127: data (this is btrfs own format - even if we used -c 1 it would still say data - its only when we decompress it that it gets the file command  to recognize it)
# SIZE OF FILE: 2.4 G (compressed very well, and quick as it only looks at metadata)

Usage – example restore btrfs-image

btrfs-image -r /root/sda5.bim /root/sda5.iso
# OUTPUT:
# /root/sda5.iso:  BTRFS Filesystem (label "5e28100e:sda5", sectorsize 4096, nodesize 4096, leafsize 4096)
# SIZE OF FILE: 115 Gig
losetup /root/sda5.iso /dev/loop1
mount /dev/loop1 /mnt
  • If mounted on the same system, the data might be accessible from /mnt as it points to the extents from a disk. Now if you mount it from another location it will be zeroed out data.
  • Side note: the 115 gig size of the restored btrfs-image makes sense because the “btrfs fi df /vol” output of the /dev/sda5 volume showed to me the following output:
  • brtfs fi df /vol
    # OUTPUT:
    # Data, single: total=1.22TiB, used=1.19TiB
    # System, DUP: total=8.00MiB, used=160.00KiB
    # System, single: total=4.00MiB, used=0.00
    # Metadata, DUP: total=56.00GiB, used=18.85GiB
    # Metadata, single: total=8.00MiB, used=0.00
    
    # NOTE: Look at the Metadata entry, 56 GiB allocated, but since its DUP we multiple by 2 which turns into: 56 GiB * 2 = 112 GiB allocated for metadata. Add a couple gigs of overhead and you get 115 GiB. Which is the exact size of the reconstructed/restored btrfs-image file

Leave a Reply

Your email address will not be published. Required fields are marked *