Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkashRajvanshi/7c07011df89fc64a70fdb105b553b680 to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/7c07011df89fc64a70fdb105b553b680 to your computer and use it in GitHub Desktop.

1.0 Introduction to btrfs

  • Btrfs: “ZFS lite” for Linux
  • Oracle’s Btrfs filesystem project (“B-tree file system,” officially pronounced “butter FS” or “better FS,” though it’s hard not to think “butter face”) aimed to repeat many of ZFS’s advances on the Linux platform during the long interregnum when ZFS seemed like it might be lost to Linux because of licensing issues.
  • BtrFS VS ZFS

btrfs1.png

btrfs2.png

btrfs3.png


2.0 Install Arch with Btrfs


  • 2.1 Create a bootable pendrive with arch latest iso

  • 2.2 Boot the ISO with UEFI ( UEFI support (BIOS system install is also possible with some modification of these instructions, but this has not yet been detailed here)

  • 2.3 Install System

# Verify the EFI
$ ls /sys/firmware/efi/efivars ( if this exits : your system is booted on UEFI )

# Check Internet
$ ping archlinux.org

# Update Time 
$ timedatectl set-ntp true

# Partition the drive
# Ex : SSD : 120 GB
$ cfdisk /dev/sda
#  Partitions ( GPT ) 
  # /dev/sda1 : efi partition : 1GB MAX
  # /dev/sda2 : 111GB
  # /dev/sda3 : 8 GB ( swap )
  
# Format the Patitions 
  # mkfs.fat -F32 /dev/sda1
  # mkfs.btrfs -L "Arch Linux" /dev/sda2
  # mkswap /dev/sda3
  # swapon /dev/sda3
  
# Mount the root btrfs volume 
$ mount /dev/sda2 /mnt

# 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

# Mount them.
$ umount /mnt
$ mount -o noatime,compress=lzo,space_cache,subvol=@root /dev/sda2 /mnt
$ mkdir /mnt/{boot,var,home,.snapshots}
$ 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

# Mount /boot
$ mount /dev/sda1 /mnt/boot

# Install the Base System
$ pacstrap /mnt base linux linux-firmware

# Generate fstab and check Fstab
$ genfstab -U /mnt >> /mnt/etc/fstab
$ cat /mnt/etc/fstab ( check for every partition : Very Important ) 

# chroot to enviornment
$ arch-chroot /mnt /bin/bash
---
# Install Some Utilities
$ pacman -S vim btrfs-progs

# Set Time Zone 
$ ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

# Hw Clock
$ hwclock --systohc

# Locale 
# Edit /etc/locale.gen and uncomment en_US.UTF-8 UTF-8 and other needed locales. Generate the locales by running:
$ locale-gen
# Create the locale.conf(5) file, and set the LANG variable accordingly:  /etc/locale.conf
$ echo LANG=en_US.UTF-8 > /etc/locale.conf
$ export LANG=en_US.UTF-8

# Create HostName 
$ /etc/hostname
# myhostname

# Edit mkinitcpio.conf
$ vim /etc/mkinitcpio.conf
 * Remove fsck and add btrfs to HOOKS
$ mkinitcpio -p linux

# Root passwd
$ passwd 

# Do other things you usually when setting up a system like arch ( eg: setup you users etc etc )

# Install and Conifure Bootloader
$ pacman -S grub efibootmgr
# For AMD processors, install the amd-ucode package.
# For Intel processors, install the intel-ucode package. 

$ pacman -S intel-ucode 
$ grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB

# generate config file 
$ grub-mkconfig -o /boot/grub/grub.cfg

# Exit Chroot Enviornment
$ exit 
----

Note : Manually unmount all the partitions with umount -R /mnt: this allows noticing any "busy" partitions, and finding the cause with fuser

  • $ reboot

3.0 Work with Btrfs

# Check Your OS Supports Btrfs 
$ grep btrfs /proc/filesystems

## Setup RAID with Btrfs
$ mkfs.btrfs -L raid -d raid1 /dev/sdb /dev/sdc
$ mount LABEL=raid /mnt/raid

## Change RAID Level with adding another disk
$ btrfs device add /dev/sdd /mnt/raid
# Check Device is Added or not
$ btrfs filesystem usgage /mnt/raid
$ btrfs balance start -dconvert=raid5 /mnt/raid

## List Subvolumes
$ btrfs subvolume list -p path
$ btrfs subvolume list -t /

## Snapshots and quotas are filesystem-level entities in Btrfs, so it’s helpful to be able to define portions of the file tree as distinct entities. Btrfs calls these “subvolumes.”

# Create Subvolume
$ btrfs subvolume create /path/to/subvolume

# we can mount a subvolume independently of its parent with the subvol mount option.
$ mount LABEL=raid -o subvol=/sub /path_to_mounted

# Delete Subvolume 
$ btrfs subvolume delete /path/to/subvolume

# Show btrfs filesystems 
$ btrfs filesystem show

## Filesystem Usage
$ btrfs filesystem usage /

## Snapshot
# -r : Read Only Snapshots
$ btrfs subvolume snapshot -r / /.snapshots/@root-`date +%F--%R` 
# Create a folder : @root-{{Current-date}}--{{Time}}
# This Folder is a full snapshot of Root Fs ( contains every file )

# Export Snapshot
$ btrfs send \@root-x--x | btrfs receive /home/user/backup
# Then you can tar this snapshot and export to B2 or S3 ( whatever your backup utility is )

# Restore From Snapshot
$ mount /dev/sda2 /mnt
$ btrfs subvolume delete /mnt/@root
$ brtfs subvolume snapshot /mnt/@snapshots/@root-x--x /mnt/@root
$ reboot

4.0 Other Resources



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment