Converting the Raspberry Pi image to Btrfs

I attempted this because I wanted to run btrfs’s timeshift as a backup / snapshot solution, and use other tools of btrfs. If you want btrfs timeshift with yunohost on a RPi, you’re probably better off running ubuntu’s image for Raspberry Pi and then installing yunohost on top. [Edit: maybe don’t do this, see wbk’s comment below] (Or check the second to last paragraph for what might be the right way to approach this if you are considering btrfs)

I think the development of a method to run btrfs on YNH could help make installs more resilient and easier for when people like me mess up their installs. An image or even just a script would be really cool.

Anyways, after flashing the raspberry pi image (buster 4.1.7.2) for YNH I followed this guide: Raspbian and btrfs

The one caveat here:

After a kernel update, you will need to run mkinitramfs again. Probably it’s the best to only do manual kernel updates (even as security updates) as otherwise your Raspi will not boot again.

The real solution to that is here:
https://raspberrypi.stackexchange.com/questions/92557/how-can-i-use-an-init-ramdisk-initramfs-on-boot-up-raspberry-pi/92558#92558

You could somewhat protect yourself against this more easily by running the following as a root cronjob:

apt -y update
apt -y upgrade
mkinitramfs -o /boot/initramfs-btrfs.gz

But if you manually or automatically updated and your kernel updated and you didn’t run mkinitramfs or the cronjob for mkinitramfs didn’t run before you rebooted, your Pi might not boot.

Alternate method of auto-updating that could be adapted to include mkinitramfs: github (sorry, I’m limited to 5 links) .com/YunoHost-Apps/unattended_upgrades_ynh/blob/master/README.md#configuration

Anyways, after I had btrfs I tried running timeshift (in btrfs mode):

root@yunohost:~# timeshift --create
Using system disk as snapshot device for creating snapshots in BTRFS mode
/dev/mmcblk0p2 is mounted at: /mnt/timeshift/backup, options: rw,relatime,ssd,space_cache,subvolid=5,subvol=/
E: The system partition has an unsupported subvolume layout. Only ubuntu-type layouts with @ and @home subvolumes are currently supported.

This linked to from the issue here may be the solution to that, but update-grub doesn’t exist so that final command didn’t work and I never ended up able to boot from the “/@” btrfs subvolume snapshot.

Lastly, MySQL wouldn’t run, and gave the following errors:

Journalctl
 journalctl

-- Logs begin at Sun 2021-12-19 06:56:00 GMT, end at Sun 2021-12-19 08:50:01 GMT. --
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31-MariaDB-0+deb10u1) starting as process 6929 ...
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Using Linux native AIO
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Uses event mutexes
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Number of pools: 1
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Using generic crc32 instructions
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Completed initialization of buffer pool
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [ERROR] InnoDB: Space ID in fsp header is 37903, but in the page header it is 0.
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: A bad Space ID was found in datafile: ./ibdata1, Space ID:4294967295, Flags: 1024
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [ERROR] InnoDB: Corrupted page [page id: space=4294967295, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
Dec 19 08:24:29 mysqld[6929]: 2021-12-19  8:24:29 0 [Note] InnoDB: Starting shutdown...
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [ERROR] Plugin 'InnoDB' init function returned error.
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [Note] Plugin 'FEEDBACK' is disabled.
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [ERROR] Unknown/unsupported storage engine: innodb
Dec 19 08:24:30 mysqld[6929]: 2021-12-19  8:24:30 0 [ERROR] Aborting
Dec 19 08:24:31 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 08:24:31 systemd[1]: mariadb.service: Failed with result 'exit-code'.
Dec 19 08:24:31 systemd[1]: Failed to start MariaDB 10.3.31 database server.
Dec 19 08:24:31 systemd[1]: Starting MariaDB 10.3.31 database server...
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Warning] option 'table_open_cache': unsigned value 4 adjusted to 10
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31-MariaDB-0+deb10u1) starting as process 6996 ...
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Using Linux native AIO
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Uses event mutexes
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Number of pools: 1
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Using generic crc32 instructions
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: Completed initialization of buffer pool
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [ERROR] InnoDB: Space ID in fsp header is 37903, but in the page header it is 0.
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [Note] InnoDB: A bad Space ID was found in datafile: ./ibdata1, Space ID:4294967295, Flags: 1024
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [ERROR] InnoDB: Corrupted page [page id: space=4294967295, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
Dec 19 08:24:31 mysqld[6996]: 2021-12-19  8:24:31 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
Dec 19 08:24:32 mysqld[6996]: 2021-12-19  8:24:32 0 [Note] InnoDB: Starting shutdown...
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [ERROR] Plugin 'InnoDB' init function returned error.
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [Note] Plugin 'FEEDBACK' is disabled.
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [ERROR] Unknown/unsupported storage engine: innodb
Dec 19 08:24:33 mysqld[6996]: 2021-12-19  8:24:33 0 [ERROR] Aborting
Dec 19 08:24:33 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 08:24:33 systemd[1]: mariadb.service: Failed with result 'exit-code'.
Dec 19 08:24:33 systemd[1]: Failed to start MariaDB 10.3.31 database server.
/var/log/mysql/error.log
2021-12-19  6:50:58 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
2021-12-19  6:50:58 0 [Note] InnoDB: Starting shutdown...
2021-12-19  6:50:59 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-12-19  6:50:59 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-12-19  6:50:59 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-12-19  6:50:59 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2021-12-19  6:50:59 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2021-12-19  6:50:59 0 [ERROR] Aborting

2021-12-19  6:55:14 0 [Note] InnoDB: Using Linux native AIO
2021-12-19  6:55:14 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-12-19  6:55:14 0 [Note] InnoDB: Uses event mutexes
2021-12-19  6:55:14 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-12-19  6:55:14 0 [Note] InnoDB: Number of pools: 1
2021-12-19  6:55:14 0 [Note] InnoDB: Using generic crc32 instructions
2021-12-19  6:55:15 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-12-19  6:55:15 0 [Note] InnoDB: Completed initialization of buffer pool
2021-12-19  6:55:15 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-12-19  6:55:15 0 [Note] InnoDB: Header page consists of zero bytes in datafile: ./ibdata1, Space ID:0, Flags: 0
2021-12-19  6:55:15 0 [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
2021-12-19  6:55:15 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
2021-12-19  6:55:15 0 [Note] InnoDB: Starting shutdown...
2021-12-19  6:55:16 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-12-19  6:55:16 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-12-19  6:55:16 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-12-19  6:55:16 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2021-12-19  6:55:16 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2021-12-19  6:55:16 0 [ERROR] Aborting

2021-12-19  6:56:16 0 [Note] InnoDB: Using Linux native AIO
2021-12-19  6:56:16 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-12-19  6:56:16 0 [Note] InnoDB: Uses event mutexes
2021-12-19  6:56:16 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-12-19  6:56:16 0 [Note] InnoDB: Number of pools: 1
2021-12-19  6:56:16 0 [Note] InnoDB: Using generic crc32 instructions
2021-12-19  6:56:16 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-12-19  6:56:16 0 [Note] InnoDB: Completed initialization of buffer pool
2021-12-19  6:56:16 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-12-19  6:56:16 0 [ERROR] InnoDB: Space ID in fsp header is 37903, but in the page header it is 0.
2021-12-19  6:56:16 0 [Note] InnoDB: A bad Space ID was found in datafile: ./ibdata1, Space ID:4294967295, Flags: 1024
2021-12-19  6:56:16 0 [ERROR] InnoDB: Corrupted page [page id: space=4294967295, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
2021-12-19  6:56:16 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
2021-12-19  6:56:17 0 [Note] InnoDB: Starting shutdown...
2021-12-19  6:56:18 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-12-19  6:56:18 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-12-19  6:56:18 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-12-19  6:56:18 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2021-12-19  6:56:18 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2021-12-19  6:56:18 0 [ERROR] Aborting

I don’t know what to do about that, I decided that was too many issues for me and I was concerned my mkinitramfs might not update so I got spooked away from the install I did. 12b says that this might be the right way to run btrfs and timeshift, because there would exist a redundant ext4 filesystem in case of issues. I’m not sure if MySQL would still break.

Thanks to user 12b and tituspijean in the matrix support room.

1 Like

Thanks for the write-up! I have hesitated about using BTRFS numerous times, but never dared to take the plunge.

That is not so solid advice. With Ubuntu based on Debian, most things will work, but with different repositories, different system tools and different package versions, there’s the risk of ending up with some quite hard to track errors and misconfigurations. If you (the reader of the post in general, not @Ocwa per se) do use Ubuntu as a base for Yunohost, do be sure to mention it when posting a problem on the forum!

Thanks for summarizing your btrfs adventures here @Ocwa
I’ve also been tempted to try btrfs on a small yunohost server for some times. Well… that or zfs actually.
Maybe I’ll give it a try on the raspberry pi I have some day.

And I second @wbk regarding yunohost on Ubuntu. That is not a good idea.
You can have a look to what yunohost core dev think of it here :

and here :

1 Like

So, I did try the last BTRFS howto I gave to @Ocwa (this one : Raspbian Btrfs root filesystem guide (2017-06) - HackMD) with a fresh install of YUNoHost on a Raspberry Pi 4.
I did not follow all the exact steps of the how-to. Mainly :

  • I skipped some steps that I found useless in the context of YUNoHost.
  • I changed the root subvolume name to be just @ instead of @root
  • I identified the partitions by UUID instead of by label in fstab

It was a bit tedious but I ended-up with a working YUNoHost running on BTRFS, without anything broken so far.

I still have to check what happens with the initramfs upon a kernel update. I think there is a way to automate things compared to the manual procedure described in the howto. But I have not addressed that yet

I’m not going to try using timeshift though. I have no experience with it. But is seems to be targeted at desktop not servers. I need to find some other solution to make btrfs snapshots incremental transfer based backups of the raspberry pi to my OpenMediaVault NAS. Probably something that is listed on that page : Incremental Backup - btrfs Wiki

1 Like

I’m referencing this here : convert from ext4 (standard) to btrfs with @ and @home layout (for timeshift) Raspberry-pi : convert to 64 bit installation? (manual way : reinstall, convert to btrfs) - #12 by Lapineige
Might be useful :slight_smile:

1 Like