Installing linux on btrfs

mikroskeem / Arch Linux btrfs install.md

NOTE: Last update to this gist was on Jun 2, 2018. Most of the things here are out of date (e.g consider using zstd for transparent compression instead of lzo), so do your own research as well. Take care!

  • Plenty of storage — snapshots will take (sort of) a lot of space
  • Latest Arch Linux install iso because those have newer kernels and more bugfixes in btrfs.
  • Have previous experience with installing Arch (like you can install arch with a blind fold).
  • Read everything through

Pick a partition scheme fitting your needs, GPT for UEFI and MBR for BIOS based systems.

We really need two of them, one for /boot and the other one will be a btrfs partition with subvolumes. Or whatever you desire, e.g swap partition. You know what to do

  1. /dev/sda1 — this will be /boot with vfat filesystem because UEFI or syslinux for legacy BIOS boot mkfs.fat -F32 /dev/sda1
  2. /dev/sda2 — btrfs with bunch of subvolumes mkfs.btrfs /dev/sda2

We will create few of them to support easy snapshoting with Snapper

1. Mount the root btrfs volume

2. Create subvolume for root, home, var and one for snapshots

btrfs subvolume create /mnt/@root btrfs subvolume create /mnt/@var btrfs subvolume create /mnt/@home btrfs subvolume create /mnt/@snapshots 
umount /mnt mount -o noatime,compress=lzo,space_cache,subvol=@root /dev/sda2 /mnt mkdir /mnt/ mount -o noatime,compress=lzo,space_cache,subvol=@var /dev/sda2 /mnt/var mount -o noatime,compress=lzo,space_cache,subvol=@home /dev/sda2 /mnt/home mount -o noatime,compress=lzo,space_cache,subvol=@snapshots /dev/sda2 /mnt/.snapshots 

pacstrap and other normal things you do when installing arch

I personally install using systemd-nspawn , e.g systemd-nspawn —directory=/mnt —boot . However, fstab and bootloader must be installed using arch-chroot .

Make sure that fstab is okay after you finish. Do not forget to use subvol=@foo and get rid of subvolid= flags

You can create snapshots like so
btrfs subvolume snapshot -r / «/.snapshots/@root-$(date +%F-%R)»

And to restore from snapshot you just delete the currently used @root and replace it with a earlier snapshot

mount /dev/sda2 /mnt btrfs subvolume delete /mnt/@root brtfs subvolume snapshot /mnt/@snapshots/@root-2015-08-10-20:19 /mnt/@root 

you will probably want to use Snapper or something like that to manage your snapshots.

  1. syslinux sould be capable of booting a btrfs volume but afaik it is just talk, I havent found anyone in the internet who has a working syslinux btrfs boot without seperate /boot parition. Only GRUB is capable of booting from bare btrfs file system.
  2. /boot is not snapshottable with this setup, someone somewhere sugested to create a systemd service to copy files from btrfs /boot to your seperate FAT32 ESP partition when files change in /boot folder. I havent tried that yet.

btrfs-specific notes (by @mikroskeem)

  • ssd mount option is considered harmful on non-rotational devices, unless you have newer kernel than 4.14 or have backported this commit
  • discard option isn’t really good either, as it seems to cause performance drops on certain SSDs. Manual trimming is more flexible.
Читайте также:  Лаборатория 50 репозитории astra linux

Thanks, it was good for me as a practical guide, as a newcomer to btrfs, but not arch.
I found i had to use mkfs.btrfs -f /dev/sda2 , in order to overwrite an existing fs because I had partitioned with cgisk, using 8300 linux filesytem — as according to the advice I had found.

A point for other followers: I had to use mkfs.btrfs -f -L ‘arch’ /dev/sda2 in order to configure my efi bootloader (i.e. sytemd bootctl) to load using label rather than UUID. A GPT partition label alone doesn’t work with the bootloader to a btrfs subvolume

In answer to Randon Note (2): pacman-boot-backup-hook available in aur will do that for you. Also in aur, systemd-boot-pacman-hook will upgrade for systemd bootloader for you, and also, check ou hooks snap-pac and snap-pac-grub to make snapper snapshots after any pacman installation (and work with yay too).

Источник

Anim Mouse

Avatar

A person who loves to harness the power of computers.

Table of contents

Featured image of post How to Install Linux Mint on Btrfs

How to Install Linux Mint on Btrfs

Install Linux Mint on B-tree file system

Do you want to use Timeshift on Linux Mint just like System Restore in Windows? The B-tree file system or Btrfs is a file system on Linux that behaves like the NTFS on Windows . Btrfs is actually better than NTFS because it uses Copy-on-write while NTFS is just a Journaling Filesystem.
The ext4 file system is a pure file system, do it’s one job, no extra stuff like NTFS or Btrfs.
When you use Timeshift on ext4, it uses rsync to make copies of the files, above the file system, that is why it is slow.
When you use System Restore on NTFS, the copies of the files are made as an atomic transaction to the file system, that is why it is fast.
Timeshift on Btrfs behaves like System Restore in Windows.

Install Linux Mint on Btrfs

  1. Open Linux Mint installer and follow everything up to Installation Type.
  2. At installation type, click Something else.

Something else

New partition tableNew partition table 2

Free space

UEFI

Create partition EFI

Free space UEFI

Create partition Btrfs on UEFI

Install now UEFI

GRUB always wait 30 seconds on boot

A patch has been merged fixing grub timeout menu to 30 seconds for UEFI systems with /boot on Btrfs.

  1. Open Terminal.
  2. Type sudo xed /etc/default/grub .
  3. Add GRUB_RECORDFAIL_TIMEOUT=0 on the file. (If you are not sure that you can access UEFI settings, use 1 instead.)
  4. Type sudo update-grub to update GRUB settings.

BIOS

Create partition Btrfs on BIOS

Install now BIOS

After installation, set-up Timeshift using the Btrfs option.

Screenshots taken on Linux Mint 20.2 using VirtualBox 6.1.26

Licensed under CC BY-NC-SA 4.0

Last updated on April 03, 2022 11:50:00 PM +0800

Источник

Installing linux on btrfs

Have you ever wished you could travel back in time after deleting that all important customer report or installing a broken driver just before heading into the board meeting?

Well, you better read on, because now you can!

All it takes is to install Kali Linux version 2022.1 or newer with btrfs as file system and to enable snapshotting after installation.

You can even boot into any of your saved snapshots via the boot menu and easily rollback to a previous system state:

boot menu

Content

  • Content
  • Overview
    • Installation Overview
    • Partitioning Scheme
    • Kali Linux Installation Procedure
    • Modify configurations
    • Create additional configurations
    • Create a snapshot
    • List snapshots
    • Delete snapshots
    • Rollback
    • Diff
    • Browse snapshots
    • Boot into a last known good snapshot
    • Rollback

    Overview

    btrfs is a modern Copy on Write (CoW) filesystem for Linux aimed at implementing advanced features such as pooling, snapshots, checksums, and integrated multi-device spanning. In particular, the snapshot support is what makes btrfs attractive for Kali installations on bare metal. Virtualization solutions such as VMware and VirtualBox provide their own snapshotting functionality and using btrfs in those environments is not really required.

    The snapshotting strategy of this walk-through centres around a tool called “snapper” from our friends over at SUSE. Snapper transparently hooks into the apt workflow and automatically creates snapshots before and after any apt operation. This neat little feature allows to easily rollback a system after a botched upgrade.

    To top things off, we added grub-btrfs by Antynea to automatically add a list of snapshots to the grub boot menu.

    Snapper-gui by Ricardo Vieira is another great tool we use to make our lifes easier.

    Installation Overview

    Installing Kali Linux with snapshotting functionality is very similar to a standard installation except that we install it with btrfs as file system.

    After the installation, we will install some tools and create a default configuration for snapper.

    Partitioning Scheme

    When selecting “btrfs” as file system, the installer will automatically create the following subvolume layout:

    [email protected] | Log files /srv | @srv | Site-specific data served by this system /tmp | @tmp | Temporary files /usr/local | @[email protected] | Tertiary hierarchy for local data 

    Kali Linux BTRFS Installation Steps

    Kali Linux Installation Procedure
    1. To start your installation, boot with your chosen installation medium. You should be greeted with the Kali Boot screen. Choose Graphical Install.
    2. The installation steps are identical to a default Kali installation except changing “ext4” to “btrfs” as file system:

    At the “Partition Disk” screen, choose “Guided — use entire disk”:

    Double-click on the / partition:

    Select “Done setting up the partition” and continue:

    Select “Finish partitioning and write changes to disk” and continue with the installation.

    1. We need to tweak the desktop managers to work in read only snapshots. Pick your DE from the following:
      in our example, replace it with yours $ sudo mount /mnt $ sudo btrfs subvolume create /mnt/@[email protected]@gdm3 $ sudo btrfs subvolume create /mnt/@[email protected]@AccountsService $ sudo mv /var/lib/gdm3/* /var/lib/gdm3/.*/mnt/@[email protected]@gdm3 $ sudo mv /var/lib/AccountsService/* /var/lib/AccountsService/.* /mnt/@[email protected]@AccountsService/ $ sudo vi /etc/fstab # Add the following (substitute the with yours) # /var/lib/gdm3 was on /dev/sda1 during installation UUID= /var/lib/gdm3 btrfs defaults,[email protected]@[email protected] 0 0 # /var/lib/AccountsService was on /dev/sda1 during installation UUID= /var/lib/AccountsService btrfs defaults,[email protected]@[email protected] 0 0 # Reboot for the changes to take effect $ sudo reboot 

    1. The first reboot will create the first automatic snapshot. Reboot again to find the new boot menu entry for this snapshot:

    Congratulations, you have just installed a Kali system with automatic snapshotting functionality! Next, we will cover some basic usage examples.

    Usage

    Modify configurations

    Out of the box Kali creates snapshots of the root directory to allow system rollbacks. Snapshots are automatically created during apt operations, at specified time intervals, and on every boot. The configuration can be changed via the “snapper-gui” tool. Just click on the little icon in the top left hand corner and select “Properties”:

    Create additional configurations

    To create snapshots of your home directory, you can create a new configuration using snapper-gui.

    Click on “New” -> “Create Configuration”

    Create a snapshot

    To manually create a snapshot using snapper-gui, select the appropriate configuration tab (home in this case) and click “New” -> “Create Snapshot”

    List snapshots

    Snapshots are listed in the snapper-gui:

    Alternatively, snapshots on all configurations can be viewed using the snapper command line tool:

    Delete snapshots

    The easiest way to delete a snapshot is by using the snapper command line tool:

    Now is probably the right time to flick through the snapper command line options via:

    Rollback

    To roll back to a previous snapshot we have to remember two things:

    • The root / of the file system has been installed in a subvolume /@» and not the root of the btrfs partition /
    • A snapshot is treated like just another subvolume except that they are read-only
    • You can easily boot into your read-only snapshots to find the one you want to roll-back to.

    Thus all we have to do is mount the btrfs partition and replace the current root subvolume @ with the last snapshot. To be safe we’ll backup the current root ( @ ) subvolume.

    Diff

    Snapper is chock-a-block with powerful features like diffs between snapshots:

    Browse snapshots

    You can even browse the content of snapshots:

    Full recovery from an unbootable system

    Boot into a last known good snapshot

    Let’s assume that the last upgrade broke our machine. Every run of “apt install” creates to snapshots, one “pre” snapshot is created before the installation and one “post” snapshot is created after the installation.

    To undo the last “apt upgrade”, we would boot into the last “pre” snapshot and check if everything is working again:

    Now you can login to the snapshot.

    Please note that the snapshot is read only and you might receive an error message from an applet or two after logging in. Just ignore that.

    Have a look around ensure that this is what you would like to roll-back to.

    Rollback

    Remember that “/” itself is the subvolume “@”. To rollback to a snapshot, all we have to do is replace “@” with the snapshot we want.

    1. First we have to mount the physical partition that holds all our subvolumes. Let’s find it first

    and then mount it (/dev/sda2 in this example:

    sudo mount /dev/sda2 -o subvol=/ /mnt

    If we list the content of that partition we can see all the subvolumes, including the one containing our snapshots:

    1. Now we can create a read-write snapshot of the current read-only snapshot (in this example we booted into the read-only snapshot “6” according to the query above):

    sudo btrfs subvolume snapshot /mnt/@.snapshots/6/snapshot /mnt/@

    And that’s all there is to it, now we can reboot as if nothing ever happened to our beautiful machine:

    References

    Updated on: 2023-Mar-06
    Author: re4son

    Источник

Оцените статью
Adblock
detector