Recovering from Btrfs no space left on device
Btrfs is a great filesystem, distribution across disks is very usefull.
I have been using it sinse it became available in Ubuntu, and have had once too many times where the disk got full, and getting out of that is very difficult.
First a recommendation that lets you get of out the situation if it happens to you.
Btrfs have a concept called "Device slack". Thats the space not used at the end of the Partition.
Usually it's whatever can not be allocated into a block, but it can be adjusted so more space is left.
Run: "btrfs device usage DEVID" and identify the device slack for each device that is part of your filesystem. They each have an ID.
Then shrink the allocatable space for Btrfs thus increasing the device slack.
btrfs filesystem resize 1:-10G DEVID
This increases the device slack with 10GB. You probably just need space for minimum two blocks, i chose 10GB to be on the safe side.
When you run out of space the next time you can then decrease the device slack so the filesystem get's usable, then you can followup fixing the issue and cleanup.
Is it too late and a disk has filled up, it is possible to fake a larger disk, as long as you have another place to put the data.
The solution is the ancient MDADM.
MDADM have an option where you can create layouts without having metadata as part of the partition, this allows you to glue two partitions together allowing you to extend the btrfs filesystem onto the next part.
This is obviusly just to get you out of this sutation so you can cleanup and delete files.
First create an empty file with eg 10 GB of space.
dd if=/dev/zero of=/mnt/ext_data bs=1024 count=10M
Now create a loop mount the file, select an unused loopid
losetup /dev/loop12 /mnt/ext_data
then also mount your actual btrfs partion.
losetup /dev/loop11 /dev/sdx5
Now you create a linear raid, first with the real parition, secondly with the file you just allocated on another filesystem. check that the md id is available.
mdadm --build /dev/md10 --level=linear --raid-devices=2 /dev/loop11 /dev/loop12
Then mount the md device
sudo mount -onoatime,clear_cache,skip_balance,device=/dev/md10 /dev/md10 /mnt/fs_mount
Be sure to mount md10, especially if you have a multi partion btrfs filesystem, you might have to manually specify the partitions participating to btrfs as the scan also can identify /dev/sdx5 as part of the filesystem
Now you can use filesystem resize mentioned earlier to increase the btrfs filesystem onto the next disk.
Kommentarer
Send en kommentar