BTRFS defrag - got failures - should I restore my data?

I was following the Fedora Magazine instructions on enabling btrfs transparrent compression.

My system was a newly updated F34 Silverblue (from F33 Silverblue). After running the command to compress existing files I got some failures.

$ sudo btrfs filesystem defrag -czstd -rv / /var/home/
...
total 126655 failures

Out of 370G used space the compression got that down to 335G :slight_smile:

On the other hand there that 1.2M failures reported :thinking:

Should I be worried, could files have gotten corrupted?

1 Like

Hi Nikoloas. I am the author of that article. On Silverblue systems this is expected, and nothing to worry about. See:

NOTE: You may receive several warnings that say something like “Cannot compress permission denied.”. This is because some files, on Silverblue systems especially, the user cannot easily modify. This is a tiny subset of files. They will most likely compress on their own, in time, as the system upgrades.

However, if you are distressed, look in the output. Most likely *all the failures are some sort of permission denied error. I hope this helps!

2 Likes

Thanks for the reply.

Unfortunately I didn’t redirect the output of the command to another file, and the terminal didn’t keep the lines output from all the millions of files processed. But since there is a most likely cause and explanation I ll take your word for it.

While googling about it I also decided to run a scrub to see what would happen:

$ sudo btrfs scrub start /
$ sudo btrfs scrub status /
UUID:             ...
Scrub started:    Thu Apr 29 19:11:54 2021
Status:           finished
Duration:         0:11:34
Total to scrub:   333.60GiB
Rate:             492.11MiB/s
Error summary:    no errors found

So I think this is ok.

2 Likes

It’s likely because /usr is read-only on Silverblue. This is a VFS mount option being enforced, but your path passed to the defragment command / does include this /usr.

A possible work around is to mount the top-level of the Btrfs file system and defragment from there, e.g.

lsblk -f

Find the device node+partition for / or /var/home (should be the same thing).

mount /dev/sdXY /mnt

Mount it without any options, since unlike fstab you’re not using subvol= mount option, it’ll mount the top level of the Btrfs file system.

cd /mnt
ls -l

You should see what looks like two ordinary directories, “root” and “home” these are the subvolumes.

btrfs fi defrag -czstd -rv root/

Defrag from here won’t run into the VFS read-only mount, so it should compress whatever can be compressed in this subvolume, or at least not run into any errors.

@chrismurphy Thank you for the reply.

Your suggestion looks a bit complicated to me because of my setup and my limited understanding of these parts of the system. When Installing Silverblue 33 on my laptop I 've merged two SSD’s into one volume (partition? - not sure what the right term is) and used LUKS encryption on that combined volume. To illustrate:

$ lsblk -f
NAME                                          FSTYPE      FSVER LABEL  UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda                                                                                                                        
├─sda1                                        vfat        FAT32        XXXX-XXXX                             590.3M     1% /boot/efi
├─sda2                                        ext4        1.0          xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  752.3M    16% /boot
└─sda3                                        crypto_LUKS 2            xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                
  └─luks-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx btrfs             fedora xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1      1T    24% /sysroot/ostree/deploy/fedora/var/home
sdb                                                                                                                        
└─sdb1                                        crypto_LUKS 2            xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                
  └─luks-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx btrfs             fedora xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1                
zram0                                                                                                                      [SWAP]

I m guessing your instructions can be modified appropriately to work on that setup but if it’s not necessary I m hesitant because there is a risk of me breaking things by doing something wrong :thinking:

P.S. Note that I deliberately named the volumes named fedora with UUID’s xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1 because in my output they do have the same UUID.

It’s not necessary. You can let compression happen going forward and uncompressed things will tend to go away over time.

Instructions are the same even with multiple device Btrfs.

2 Likes