Snapshot rollback method for Linux systems using Btrfs

Source: Internet
Author: User

Btrfs, also known as Butter FS, Better FS, or B-tree FS, is a modern file system that Oracle began designing and developing in 2007, and it was merged into the Linux 2.6.29 kernel in 2009. Btrfs is licensed under the GPL and is not very stable, although many Linux distributions are integrated, but are not used as default file systems. Btrfs is widely integrated because of its support for disk snapshots, support for recursive snapshots, RAID support, child volumes (subvolumes), and enabling online sizing of file system sizes. Although most Linux distributions are currently using EXT4 as the primary file system, they are likely to be replaced by Btrfs at any time in the future.

Btrfs is mainly designed to solve the current Linux file system various "weaknesses" of the COW (copy-on-write) file system, is expected to provide better scalability and reliability, its main development focus is on fault tolerance, repair and ease of management.

Next I'll show you how to use apt-btrfs-snapshot to roll back the Btrfs file system snapshot in Linux to the previous system state. Using Apt-btrfs-snapshot to create and manage file system snapshots is as simple as other apt operations, and we can easily recover the state of the Btrfs file system using it.


In order to create and use Btrfs to restore your Linux file system, of course, you need to use the Btrfs file system, you need not use the Ext file system separate/boot partition, or you can not play.

Install Btrfs Package

After the condition is met, install the Apt-btrfs-snapshot package using the following command:

Apt-get Install Apt-btrfs-snapshot

After the installation is complete, use the following Apt-btrfs-snapshot command to check that the creation of the Btrfs snapshot is supported:

Apt-btrfs-snapshot supported

使用Btrfs对Linux系统进行快照回滚方法-btrfs 回滚

If the prerequisites for the Btrfs file system are met, the supported is output, or the output is:

Sorry, your system lacks support for the snapshot feature

You can check the default layout for Btrfs on Ubuntu by using the following command:

Btrfs Subvolume List

To create a snapshot using the ATP operation

To test the rollback operation, we first perform some apt operations in the current system, such as Apt-get.

Apt-get Update && Apt-get upgrade

使用Btrfs对Linux系统进行快照回滚方法-linux 系统回滚

Press Y to continue with the system upgrade, and you will see that Apt-btrfs-snapshot has automatically created a snapshot of the system state prior to the upgrade.

使用Btrfs对Linux系统进行快照回滚方法-btrfs 快照

You can also use the following command to view the list of snapshots in the current system:

Btrfs Subvolume List/

Apt-btrfs-snapshot List


Restore Btrfs Snapshots

For example, in the system upgrade process encountered problems, we need to restore the system before the upgrade state, you can mount the Btrfs file system to a separate location, such as/mnt under operation.


Viewing the/MNT directory outputs the child volumes:


The @apt-snapshot-2016-05-24_02:18:31 is the root file system snapshot of the previous apt operation. Rename the current child volume to the beginning of @, and then rename the @apt-snapshot-2016-05-24_02:18:31 to reboot the system after the current child volume, which restores the snapshot.

使用Btrfs对Linux系统进行快照回滚方法-linux 操作系统快照

Delete Btrfs Snapshots

When a snapshot is restored, or if you need to free up some disk space, you can use the following command to delete the snapshot:


Btrfs Subvolume delete/mnt/@_latest-root/


To be blunt, a Btrfs snapshot is actually a child volume that is data-shared with other child volumes, sharing data and modifying the snapshot using Btrfs's copy-on-write capabilities, and the original child volumes are not visible. Once the snapshot is created, it is considered an alternate version of the original file system.

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.