Freeing space by deleting btrfs snapshots

As a btrfs newbie, I didn’t realize that automatically generated snapshots could accumulate and overrun the root partition. It’s easy enough to fix however.

When I installed openSUSE 42.1 I noticed that btrfs was the then-new default filesystem choice. Great, I thought, and accepted it without giving it further thought or study.

It wasn’t until my root partition became unexpectedly full that I belatedly did my homework. Btrfs periodically saves snapshots of the filesystem. How often they are taken and for how long they are saved can be configured, and in my case the default values weren’t ideal.

We will fix this in two parts: delete unneeded snapshots, then tweak the configuration so this hopefully does not happen again.

As root, view your snapshots:

# snapper list
Type   | #   | Pre # | Date                            | User | Cleanup | Description           | Userdata
single | 0   |       |                                 | root |         | current               |
single | 1   |       | Sun 20 Mar 2016 08:47:05 PM CST | root |         | first root filesystem |
pre    | 146 |       | Tue 12 Apr 2016 05:57:14 AM CST | root | number  | zypp(packagekitd)     | important=yes
post   | 147 | 146   | Tue 12 Apr 2016 06:02:26 AM CST | root | number  |                       | important=yes
pre    | 159 |       | Wed 20 Apr 2016 03:31:15 PM CST | root | number  | zypp(zypper)          | important=no

The number of each snapshot is shown in the # column. You cannot delete snapshots numbers 0 or 1, and you will probably want to keep the most recent snapshot and the most recent important one. So in this example, we can delete snapshot 146:

# snapper delete 146

Now check your free space with df -h. Space usage should have decreased. Be open however to the possibility that your space problems lie elsewhere.

Now let’s tweak the configuration. As root, open the snapper configuration file /etc/snapper/configs/root. Edit away; the settings I change are:

TIMELINE_LIMIT_DAILY="2"   # Keep daily snapshots for 2 days (default 10)
TIMELINE_LIMIT_MONTHLY="0" # Don't keep monthly snapshots (default was 10)
TIMELINE_LIMIT_YEARLY="0"  # Don't keep yearly snapshots (default was 10)

And we’re done.

The above is a condensed version of the excellent post The joys of btrfs and OpenSuSE – or “no space left on device”; see it for additional information. Also see System Recovery and Snapshot Management with Snapper.

The above refers to btrfs as implemented on openSUSE 42.1 and was last updated on 7 October 2016.


About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s