Enable bcache or LVM on existing block devices
Repo Geramy/blocks-cpp, read from GitHub 22 h ago. Geramy has not joined Take My Repo.
Geramy/blocks-cpp is a public repo on GitHub by Geramy. Enable bcache or LVM on existing block devices. It declares the MIT license on GitHub. It is written mainly in C++, has 0 stars and last changed on 2025-03-19. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
This program was converted from the original one in python into C++ Original https://github.com/g2p/blocks/tree/master Then to-lvm was tested, the python one had all kinds of versioning problems so I said im done with this i'll just convert it to C++ So here we are!
If someone wants to continue my work they may fork and send PRs.
I ended up having to chroot like it said and everything else but you need to be careful to mount the boot partition if using EFI to /boot/efi and not anything else and then as long as the UUID of the partition is the same as the old one you wont need to worry about NVRAM when you update FSTAB make sure to use the /dev/mapper/ vg path instead.
Conversion tools for block devices.
Convert between raw partitions, logical volumes, and bcache devices
without moving data. blocks shuffles blocks and sprouts superblocks.
Here’s the revised step-by-step procedure for converting your Pop!_OS root filesystem to LVM using our C++ blocks binary, formatted in Markdown (.md). This assumes you’re using the Pop!_OS Live ISO and the binary at ~/Documents/Development/lvmify_full/cmake-build-debug/blocks, avoiding the Python3 version entirely. Converting Pop!_OS Root Filesystem to LVM with C++ Blocks Binary This guide details how to convert your Pop!_OS root filesystem to LVM using our custom C++ blocks binary, executed from a Pop!_OS Live ISO. It includes preparing the live environment, running the conversion, and updating the systemd-boot bootloader to boot from the LVM logical volume. Prerequisites Pop!_OS Live ISO: Download from System76’s website and create a bootable USB (e.g., with dd or Etcher). Backup: Ensure your data is backed up. This is an in-place conversion; errors could lead to data loss. Target Device: Identify your root filesystem’s block device (e.g., /dev/nvme0n1p2 or /dev/sda1). Replace this with your actual root partition in the steps below. C++ blocks Binary: Located at ~/Documents/Development/lvmify_full/cmake-build-debug/blocks on your development machine. Step-by-Step Procedure
sudo mkdir /mnt/root
sudo mount /dev/nvme0n1p2 /mnt/root # Replace /dev/nvme0n1p2 with your root device
ls /mnt/root # Verify contents (e.g., /bin, /etc, /home)
If encrypted (e.g., LUKS):
bash
sudo cryptsetup luksOpen /dev/nvme0n1p2 root_crypt
sudo mount /dev/mapper/root_crypt /mnt/root
Mount Additional Filesystems: For a full chroot later:
bash
sudo mount --bind /dev /mnt/root/dev
sudo mount --bind /proc /mnt/root/proc
sudo mount --bind /sys /mnt/root/sys
sudo mount --bind /run /mnt/root/run
If you have a separate /boot partition (e.g., /dev/nvme0n1p1):
bash
sudo mkdir /mnt/root/boot
sudo mount /dev/nvme0n1p1 /mnt/root/boot
sudo cp /media/user/usb/blocks /tmp/blocks
sudo chmod +x /tmp/blocks
sudo umount /mnt/root/dev /mnt/root/proc /mnt/root/sys /mnt/root/run /mnt/root/boot /mnt/root
Run the Conversion: Use our C++ blocks binary.
bash
sudo /tmp/blocks to-lvm /dev/nvme0n1p2 # Replace with your root device
Expected output:
Checking the filesystem before resizing it
Executing: e2fsck -f -y -- /dev/nvme0n1p2
Will shrink the filesystem (ext4) by 7340032 bytes
Executing: resize2fs -- /dev/nvme0n1p2 253952
Installing LVM metadata... Writing 4194304 bytes of metadata to physical device at offset 0 ok Activating volume group vg.nvme0n1p2... ok LVM conversion successful! Volume group name: vg.nvme0n1p2 Logical volume name: nvme0n1p2 Filesystem uuid: fc07dd43-5d65-4806-97ff-7745ce118cf0
sudo mount /dev/vg.nvme0n1p2/nvme0n1p2 /mnt/root # Use the LV path from the output
sudo mount --bind /dev /mnt/root/dev
sudo mount --bind /proc /mnt/root/proc
sudo mount --bind /sys /mnt/root/sys
sudo mount --bind /run /mnt/root/run
sudo mount /dev/nvme0n1p1 /mnt/root/boot # If separate boot partition
sudo chroot /mnt/root
Install LVM2 in the Chroot:
apt update
apt install -y lvm2
Update /etc/fstab:
Edit /etc/fstab to use the LVM logical volume:
nano /etc/fstab
# Replace the root entry (e.g., /dev/nvme0n1p2) with:
/dev/vg.nvme0n1p2/nvme0n1p2 / ext4 defaults 0 1
Save and exit (Ctrl+O, Enter, Ctrl+X). Update Initramfs: Ensure the initramfs includes LVM support:
echo "lvm" >> /etc/initramfs-tools/modules
update-initramfs -u -k all
Update systemd-boot: Pop!_OS uses kernelstub to manage systemd-boot entries. Update the root parameter: bash
kernelstub -r /dev/vg.nvme0n1p2/nvme0n1p2
Verify the loader entry:
cat /boot/loader/entries/Pop_OS-current.conf
Ensure options includes root=/dev/vg.nvme0n1p2/nvme0n1p2 (or UUID if preferred):
blkid /dev/vg.nvme0n1p2/nvme0n1p2 # Get UUID
# Edit if needed
nano /boot/loader/entries/Pop_OS-current.conf
# Example:
# options root=UUID=<uuid> rw quiet loglevel=3 ...
Exit Chroot:
exit
sudo umount /mnt/root/dev /mnt/root/proc /mnt/root/sys /mnt/root/run /mnt/root/boot /mnt/root
sudo reboot
Check Boot: If successful, Pop!_OS should boot normally from /dev/vg.nvme0n1p2/nvme0n1p2. Verify:
df -h / # Should show /dev/vg.nvme0n1p2/nvme0n1p2 mounted on /
lsblk # Should show LVM structure
Troubleshooting Boot Issues Boot Failure: If the system doesn’t boot, use the Pop!_OS Live ISO again, chroot back in, and check:
cat /boot/loader/entries/Pop_OS-current.conf # Verify root= parameter
update-initramfs -u -k all
kernelstub -r /dev/vg.nvme0n1p2/nvme0n1p2
Initramfs Missing LVM: Ensure lvm is in /etc/initramfs-tools/modules and regenerate if not:
echo "lvm" >> /etc/initramfs-tools/modules
update-initramfs -u -k all
Why This Works Custom C++ Binary: Our blocks binary performs the in-place conversion, shrinking the filesystem and setting up LVM without Python dependencies. LVM Recognition: Installing lvm2 and updating the initramfs ensures the kernel can mount the LVM root. systemd-boot Update: kernelstub adjusts the bootloader to point to the new LVM logical volume, aligning with Pop!_OS conventions. Post-Conversion Expand LVM: Add more disks if desired:
sudo vgextend vg.nvme0n1p2 /dev/sdb1
sudo lvextend -l +100%FREE /dev/vg.nvme0n1p2/nvme0n1p2
sudo resize2fs /dev/vg.nvme0n1p2/nvme0n1p2
For testing with a loop device (e.g., /dev/loop26p1), adapt the paths, but use your physical root partition for the real system. Follow these steps with your actual root device, and let me know how it goes or if you encounter any issues! Your data integrity verification is a great foundation, and this should ensure a smooth transition to booting from LVM.
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=<VG> 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<extra-copies>.
blocks to-bcache converts a block device (partition, logical volume,
LUKS device) to use bcache. If --join=<cset-uuid> 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:
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.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 (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.
You can install python3-blocks from a PPA and skip the rest of the installation section.
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
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):
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:
pip-3.3 install --user -r <(wget -O- https://raw.github.com/g2p/blocks/master/requirements.txt)
cp -lt ~/bin ~/.local/bin/blocks
Install LVM.
Edit your /etc/fstab to refer to filesystems by UUID, and regenerate
your initramfs so that it picks up the new tools.
With grub2, you don't need to switch to a separate boot
partition, but make sure grub2 installs lvm.mod inside your /boot.
Make sure your backups are up to date, boot to live media (Ubuntu raring liveusb is a good choice), install blocks, and convert.
Install bcache-tools and a recent kernel (3.10 or newer). If your distribution uses Dracut (Fedora), you need Dracut 0.31 or newer.
Edit your /etc/fstab to refer to filesystems by UUID, and regenerate
your initramfs so that it picks up the new tools.
On Debian and Ubuntu, this is done with update-initramfs -u -k all.
With Dracut (Fedora), this is done with dracut -f.
Arch Linux users should enable the bcache hook in mkinitcpio.conf
and rerun mkinitcpio.
If you don't see your distribution in this list, you are welcome to
port this hook
to your distribution's preferred tools and contribute a patch to bcache-tools.
Having working bcache support in your initramfs is important, as your system
will be unbootable without.
Edit your grub.cfg to refer to filesystems by UUID on the kernel
command-line (this is often the case, except when you are already using
LVM, in which case update-grub tends to write a logical path). Make
sure you have a separate /boot partition.
If you don't have a cache device yet, create it on an empty SSD (or on a properly aligned partition or LV on top of it; LVM's 4MiB alignment is sufficient, as is the 1MiB alignment of modern partitioning tools).
sudo make-bcache -C /dev/<cache-device>
This will give you a cache-set uuid.
If you already have a cache device
ls /sys/fs/bcache
And copy the cache-set uuid.
Finally, if you have a maintboot-compatible distribution, run:
sudo blocks to-bcache --maintboot /dev/<root-device> --join <cset-uuid>
Geramy/blocks-cpp is a public repo on GitHub by Geramy. Enable bcache or LVM on existing block devices.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2025-03-19. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run blocks-cpp. What is known comes from GitHub. It declares the MIT license on GitHub. Its last change was on 2025-03-19. It has 0 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.