Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

blocks

> 编程语言
Open source

Enable bcache or LVM on existing block devices

397 stars0 likes1 views
WebsiteGitHub

About

Enable bcache or LVM on existing block devices

blocks

Conversion tools for block devices.

Convert between raw partitions, logical volumes, and bcache devices without moving data. blocks shuffles blocks and sprouts superblocks.

LVM conversion

blocks to-lvm (alias: lvmify) takes a block device (partition or whole disk) containing a filesystem, shrinks the filesystem by a small amount, and converts it to LVM in place.

The block device is converted to a physical volume and the filesystem is converted to a logical volume. If --join= is used the volumes join an existing volume group.

An LVM conversion can be followed by other changes to the volume, growing it to multiple disks with vgextend and lvextend, or converting it to various RAID levels with lvconvert --type=raidN -m.

bcache conversion

blocks to-bcache converts a block device (partition, logical volume, LUKS device) to use bcache. If --join= is used the device joins an existing cache set. Otherwise you will need to create and attach the cache device manually.

blocks will pick one of several conversion strategies:

  • one for partitions, which requires a shrinkable filesystem or free space immediately before the partition to convert. Converting a logical partition to bcache is not supported: if blocks complains about overlapping metadata in the middle of the disk, please use gdisk to convert your MBR disk to GPT and reinstall your bootloader before proceeding with the bcache conversion.
  • one for LUKS volumes
  • one for LVM logical volumes

When the first two strategies are unavailable, you can still convert to bcache by converting to LVM first, then converting the new LV to bcache.

You will need to install bcache-tools, which is available here:

  • (sudo add-apt-repository ppa:g2p/storage; for ubuntu 13.10 and newer)

Conversion makes no demands on the kernel, but to use bcache, you need Linux 3.10 or newer. My own branch currently adds resizing support on top of Kent Overstreet's upstream branch.

maintboot mode

Maintboot mode (blocks to-bcache --maintboot) is an easier way to convert in-use devices that doesn't require a LiveCD. maintboot will run the conversion from an in-memory boot environment. This is currently tested on Ubuntu; ports to other distributions are welcome.

Ubuntu PPA (13.10 and newer)

You can install python3-blocks from a PPA and skip the rest of the installation section.

bash
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:g2p/storage
sudo apt-get update
sudo apt-get install python3-blocks bcache-tools

Requirements

Python 3.3, pip and Git are required before installing.

You will also need libparted (2.3 or newer, library and headers) and libaugeas (library only, 1.0 or newer).

On Debian/Ubuntu (Ubuntu 13.04 or newer is recommended):

bash
sudo aptitude install python3.3 python3-pip git libparted-dev libaugeas0 \
    pkg-config libpython3.3-dev gcc
sudo aptitude install cryptsetup lvm2 liblzo2-dev \
    nilfs-tools reiserfsprogs xfsprogs e2fsprogs btrfs-tools  # optional
type pip-3.3 || alias pip-3.3='python3.3 -m pip.runner'

Command-line tools for LVM2, LUKS, bcache (see above), filesystem resizing (see below for btrfs) are needed if those formats are involved. Kernel support isn't required however, so you can do bcache conversions from a live-cd/live-usb for example.

For btrfs resizing, you need a package that provides btrfs-show-super, or you can install from source:

Installation

pip-3.3 install --user -r 

This will give you a cache-set uuid.

  1. If you already have a cache device

     ls /sys/fs/bcache
    

    And copy the cache-set uuid.

  2. Finally, if you have a maintboot-compatible distribution, run:

    bash
     sudo blocks to-bcache --maintboot /dev/ --join 
    

    If you are using encryption, use the encrypted device as the root device so that cache contents are also encrypted.

  3. Otherwise, make sure your backups are up to date, boot to live media (Ubuntu raring liveusb is a good choice), install blocks, and convert.

bcache on a fresh install

When using a distribution installer that doesn't support bcache at the partitioning stage, make sure the installer creates a separate /boot partition. Install everything on the HDD, using whatever layout you prefer (but I suggest LVM if you want multiple partitions).

Once the installer is done, you can follow the steps at converting your root filesystem to bcache.

Subcommand help

blocks --help
blocks  --help

If blocks isn't in the shell's command path, replace with:

bash
sudo python3.3 -m blocks

Build status

Issues· 29 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言