Difference between revisions of "Installing Arch Linux on ZFS"

From ArchWiki
Jump to: navigation, search
(Personal note fit in talk page.)
(Added more sections, cleaned up the layout, added more formatting.)
Line 1: Line 1:
[[Category:Getting and installing Arch]]
 
 
{{Note|This is a work in progress. Some parts could have gaps, or require you to do things on your own.}}
 
{{Note|This is a work in progress. Some parts could have gaps, or require you to do things on your own.}}
  
This tutorial will show you how to install Arch Linux (Your / partition) on ZFS.
+
This tutorial will show you how to install your root partition (/) of Arch Linux on ZFS.
  
 
== Installing Arch Linux on a regular filesystem ==
 
== Installing Arch Linux on a regular filesystem ==
1. Install Arch Linux to wherever you want as normal<br/>
+
1. Install Arch Linux to wherever you want with the default partition settings, select base-devel when selecting the packages to install, select '''[[syslinux]]''' as the bootloader, and boot into your new install. <br/>
2. Compile a custom kernel (with everything needed to boot built into the kernel and with ZLIB_DEFLATE support)
+
2. Install some applications that we will be using:
{{Note|The reason for this is because Arch's kernel is very modular and I didn't write my initramfs creator to support autodetection of every single piece of hardware and modules}}
+
  # pacman -S git pbzip2
3. Compile the zfs/spl rc9 from the aur with kylef's PKGBUILD. https://aur.archlinux.org/packages.php?ID=41045 Modify the PKGBUILD so that the ./configure has --with-linux=/usr/src/linux --with-linux-obj=/usr/src/linux<br/>
+
4. Install the spl/zfs packages<br/>
+
5. Install git and cpio
+
  pacman -S git cpio
+
6. Clone my zfs initramfs creator and make a new initramfs
+
git clone git://github.com/fearedbliss/Bliss-Initramfs-Creator.git
+
+
cd Bliss-Initramfs-Creator
+
+
git checkout archlinux
+
+
./createInit
+
^^ # Follow the instructions and copy the ZFS file to your /boot afterwards
+
+
cp ZFS-kernel-version.img /boot/initramfs-zfs.img
+
  
=== Back up Arch Linux via stage5 ===
+
3. Installing the SPL/ZFS module<br/>
cd /
+
tar --exclude proc --exclude tmp --exclude var/cache/pacman/pkg --exclude sys -cvvpf stage5-arch.tar .
+
  
# Compress the stage5 if you want to with pbzip2 (dont use bzip2.. it will take a much longer time, use pbzip2 if you have a multicore system)
+
=== Using compiled binaries ===
pbzip2 stage5-arch.tar
+
  
# Save this file somewhere because we will be moving it to our new installation afterwards (stage5-arch.tar.bz2)
+
For compiled binaries just:
 +
# git clone git://github.com/fearedbliss/Arch-ZFS-Binaries.git
 +
# cd Arch-ZFS-Binaries
 +
# pacman -U *.tar.xz
  
(Note, you will need to remake the proc, tmp, and sys directories after you extract it onto the ZFS system)
+
and that's it, you can now skip to "Configuring the environment" https://wiki.archlinux.org/index.php?title=Installing_Arch_on_ZFS&action=submit#Configuring_the_environment. I've also made branches for different Arch kernels as it rolls. You can see the different binaries for kernels by typing:
 +
# git branch
  
# edit your fstab to remove old mountpoints
+
To switch to a specific kernel, just do a:
# add zfs to rc.d
+
# git branch v[kernel-version].
vim /etc/rc.conf (and add zfs to your daemons)
+
 
 +
Example:
 +
# git branch v3.4.3-1-ARCH
 +
 
 +
=== Compiling it from source via AUR ===
 +
Install required packages
 +
# pacman -S yajl
 +
 
 +
Make a temp dir in your home folder (You will probably want to keep the resulting binaries)
 +
# mkdir ~/tmp
 +
# cd ~/tmp
 +
 
 +
Download cower
 +
# git clone git://github.com/falconindy/cower.git
 +
# cd cower
 +
 
 +
Compile and install cower
 +
# make cower
 +
# make install
 +
 
 +
Download ZFS/SPL
 +
# cd ~/tmp && cower -d zfs spl
 +
 
 +
Install SPL
 +
# cd spl && makepkg -s
 +
# pacman -U *.tar.xz
 +
 
 +
Install ZFS
 +
# cd ../zfs && makepkg -s
 +
# pacman -U *.tar.xz
 +
 
 +
=== Configuring the environment ===
 +
1. Add the '''zfs''' hook to your '''HOOKS''' array in '''/etc/mkinitcpio.conf''' before '''filesystems''' and after '''sata''', and make a new initramfs with '''mkinitcpio'''.
 +
# vim /etc/mkinitcpio.conf
 +
HOOKS="...sata zfs filesytems ..."
 +
 
 +
# mkinitcpio -p linux
 +
 
 +
2. Edit your fstab to only mount things not managed by ZFS (/boot, swap, cdrom?)
 +
# vim /etc/fstab
 +
 
 +
3. Add '''zfs''' to your '''DAEMONS''' array in '''/etc/rc.conf''':
 +
# vim /etc/rc.conf
 +
DAEMONS="syslog-ng zfs network ..."
 +
 
 +
and that's it for the setup portion.
 +
 
 +
=== Backing up Arch Linux ===
 +
Make a temporary directory to bind '''/''' to only backup the / without any other mountpoints:
 +
# mkdir /tmp/zfs
 +
# mount -o bind / /tmp/zfs
 +
# mount -o bind /boot /tmp/zfs/boot
 +
# cd /tmp/zfs
 +
# tar --exclude arch-zfs.tar --exclude var/cache/pacman/pkg -cvpf arch-zfs.tar .
 +
 
 +
Compress the tarball with '''[[pbzip2]]''' (dont use [[bzip2]].. it will take a much longer time since it's single-threaded, use pbzip2 if you have a multithreaded system)
 +
# pbzip2 arch-zfs.tar
 +
 
 +
Save this file somewhere because we will be moving it to our new installation afterwards ('''arch-zfs.tar.bz2''')
  
 
== New install with ZFS as the filesystem ==
 
== New install with ZFS as the filesystem ==
  
In order to partition the system, I was using system rescue cd v2.5.1. The reason I'm using 2.5.1 is because it's the last version that had the
+
In order to partition the system, I was using '''System Rescue CD v2.5.1'''. The reason I'm using 2.5.1 is because it's the last version that had the
 
native ZFS on Linux modules. Any version before or later does not have them. Since the link for 2.5.1 was removed from the author's website, I recommend you
 
native ZFS on Linux modules. Any version before or later does not have them. Since the link for 2.5.1 was removed from the author's website, I recommend you
 
to use the Gentoo Live DVD 2012. http://torrents.gentoo.org/ , download the `livedvd-amd64-multilib-2012.1`.
 
to use the Gentoo Live DVD 2012. http://torrents.gentoo.org/ , download the `livedvd-amd64-multilib-2012.1`.
Line 49: Line 92:
 
=== Partitioning ===
 
=== Partitioning ===
 
Our system will be using GPT as the base and extlinux as the bootloader.
 
Our system will be using GPT as the base and extlinux as the bootloader.
 +
 +
Let's create a directory to hold out zfs pool
 +
# mkdir /mnt/pool
  
 
The layout will look like this:
 
The layout will look like this:
  /dev/sda1 Linux FS 250M
+
  /dev/sda1 8300 Linux FS 250M # This will be our /boot partition
  /dev/sda2 bf01 Rest of Disk
+
  /dev/sda2 8200 Linux Swap <YOUR_RAM * 1.5> # or w/e calculations you use
 +
/dev/sda3 bf01 Rest of Disk # This will be the ZFS pool
  
# Create ZFS Pool and Mountpoints
+
{{Warning|You cannot put the swap inside the ZFS pool yet because it will have problems. This will probably be fixed in a future upstream version.}}
zpool create -o ashift=12 -o cachefile= -O normalization=formD -R /mnt/custom rpool /dev/sda2
+
zfs create -o mountpoint=none rpool/ROOT
+
zfs create -o mountpoint=/ rpool/ROOT/arch
+
zfs create -o mountpoint=/home rpool/HOME
+
zfs create -o mountpoint=/root rpool/HOME/root
+
  
# Mount /boot partition in the zfs /
+
# Format the '''/boot''' partition as ext4 (or ext2-3)
  mkdir /mnt/custom/boot
+
  # mkfs.ext4 /dev/sda1
mount /dev/sda1 /mnt/custom/boot
+
  
# Extract Arch Stage5 (Preloaded with ZFS modules and your own kernel)
+
# Make the swap and turn it on
 +
# mkswap /dev/sda2
 +
# swapon
  
# Change into the directory
+
Load up the spl/zfs modules (if needed)
  cd /mnt/custom
+
# modprobe spl zfs
 +
 
 +
Create ZFS Pool and Mountpoints
 +
# zpool create -o ashift=12 -o cachefile= -O normalization=formD -R /mnt/pool rpool /dev/sda3
 +
# zfs create -o mountpoint=none rpool/ROOT
 +
# zfs create -o mountpoint=/ rpool/ROOT/arch
 +
# zfs create -o mountpoint=/home rpool/HOME
 +
# zfs create -o mountpoint=/root rpool/HOME/root
 +
 
 +
Mount your '''/boot''' partition
 +
# mkdir /mnt/pool/boot
 +
# mount /dev/sda1 /mnt/pool/boot
 +
 
 +
Move the '''arch-zfs.tar.bz2''' file to your system. You can use scp if it's over the network, or a flash drive if you are within walking distance.
 +
  # scp /arch-zfs.tar.bz2 root@<ip_of_new_computer>:/mnt/pool
 +
 
 +
Extract the Arch backup (Preloaded with ZFS modules and configured for ZFS)
 +
# cd /mnt/pool
 +
# tar -xjpvf arch-zfs.tar.bz2 .
  
 
=== Install Extlinux bootloader ===
 
=== Install Extlinux bootloader ===
# Bind proc in the chroot env before chroot so that extlinux can find the correct device
+
Bind a few mountpoints in the chroot env before chroot so that '''[[extlinux]]''' can find the correct device
  mount --bind /proc ./proc
+
  # mount --bind /proc ./proc
  env HOME=/root TERM=$TERM chroot . /bin/bash --login
+
  # mount --bind /dev ./dev
  mkdir /boot/extlinux
+
# mount --bind /sys ./sys
  extlinux --install /boot/extlinux
+
# env -i HOME=/root TERM=$TERM chroot . /bin/bash --login
 +
 
 +
  # The below commands are executed within the chroot environment
 +
 +
# mkdir /boot/extlinux
 +
  # extlinux --install /boot/extlinux
  
# Set correct boot flags in the GPT legacy bios and then flash mbrgpt
+
Set correct boot flags in the [[GPT]] legacy bios and then flash gptmbr
  sgdisk /dev/sda --attributes=1:set:2
+
  # sgdisk /dev/sda --attributes=1:set:2
  sgdisk /dev/sda --atributes=1:show
+
  # sgdisk /dev/sda --atributes=1:show
  dd count=1 bs=440 conv=notrunc if=/usr/lib/syslinux/gptmbr.bin of=/dev/sda
+
  # dd count=1 bs=440 conv=notrunc if=/usr/lib/syslinux/gptmbr.bin of=/dev/sda
  
# Make an extlinux.conf
+
Make an '''extlinux.conf'''
  cd /boot/extlinux
+
  # cd /boot/extlinux
  vim extlinux.conf
+
  # vim extlinux.conf
  
Inside extlinux.conf put the following
+
Inside '''extlinux.conf''' put the following
  
 
  PROMPT 0
 
  PROMPT 0
Line 96: Line 162:
 
   
 
   
 
  LABLE Arch
 
  LABLE Arch
     MENU LABEL Arch [ZFS]
+
     MENU LABEL Arch Linux
     LINUX /kernel-thatyoucompiled
+
     LINUX /vmlinuz-linux
     INITRD /initramfs-zfs.img
+
     INITRD /initramfs-linux.img
 +
    APPEND zfs=rpool/ROOT/arch zfs_force=1
  
 
and save it.
 
and save it.
  
 
That's it, restart your computer and you should be inside Arch on ZFS :)!
 
That's it, restart your computer and you should be inside Arch on ZFS :)!

Revision as of 22:22, 23 June 2012

Note: This is a work in progress. Some parts could have gaps, or require you to do things on your own.

This tutorial will show you how to install your root partition (/) of Arch Linux on ZFS.

Installing Arch Linux on a regular filesystem

1. Install Arch Linux to wherever you want with the default partition settings, select base-devel when selecting the packages to install, select syslinux as the bootloader, and boot into your new install.
2. Install some applications that we will be using:

# pacman -S git pbzip2

3. Installing the SPL/ZFS module

Using compiled binaries

For compiled binaries just:

# git clone git://github.com/fearedbliss/Arch-ZFS-Binaries.git
# cd Arch-ZFS-Binaries
# pacman -U *.tar.xz

and that's it, you can now skip to "Configuring the environment" https://wiki.archlinux.org/index.php?title=Installing_Arch_on_ZFS&action=submit#Configuring_the_environment. I've also made branches for different Arch kernels as it rolls. You can see the different binaries for kernels by typing:

# git branch

To switch to a specific kernel, just do a:

# git branch v[kernel-version].

Example:

# git branch v3.4.3-1-ARCH

Compiling it from source via AUR

Install required packages

# pacman -S yajl

Make a temp dir in your home folder (You will probably want to keep the resulting binaries)

# mkdir ~/tmp
# cd ~/tmp

Download cower

# git clone git://github.com/falconindy/cower.git
# cd cower

Compile and install cower

# make cower
# make install

Download ZFS/SPL

# cd ~/tmp && cower -d zfs spl

Install SPL

# cd spl && makepkg -s
# pacman -U *.tar.xz

Install ZFS

# cd ../zfs && makepkg -s
# pacman -U *.tar.xz

Configuring the environment

1. Add the zfs hook to your HOOKS array in /etc/mkinitcpio.conf before filesystems and after sata, and make a new initramfs with mkinitcpio.

# vim /etc/mkinitcpio.conf
HOOKS="...sata zfs filesytems ..."
 
# mkinitcpio -p linux

2. Edit your fstab to only mount things not managed by ZFS (/boot, swap, cdrom?)

# vim /etc/fstab

3. Add zfs to your DAEMONS array in /etc/rc.conf:

# vim /etc/rc.conf
DAEMONS="syslog-ng zfs network ..."

and that's it for the setup portion.

Backing up Arch Linux

Make a temporary directory to bind / to only backup the / without any other mountpoints:

# mkdir /tmp/zfs
# mount -o bind / /tmp/zfs
# mount -o bind /boot /tmp/zfs/boot
# cd /tmp/zfs
# tar --exclude arch-zfs.tar --exclude var/cache/pacman/pkg -cvpf arch-zfs.tar .

Compress the tarball with pbzip2 (dont use bzip2.. it will take a much longer time since it's single-threaded, use pbzip2 if you have a multithreaded system)

# pbzip2 arch-zfs.tar

Save this file somewhere because we will be moving it to our new installation afterwards (arch-zfs.tar.bz2)

New install with ZFS as the filesystem

In order to partition the system, I was using System Rescue CD v2.5.1. The reason I'm using 2.5.1 is because it's the last version that had the native ZFS on Linux modules. Any version before or later does not have them. Since the link for 2.5.1 was removed from the author's website, I recommend you to use the Gentoo Live DVD 2012. http://torrents.gentoo.org/ , download the `livedvd-amd64-multilib-2012.1`.

Note: If anyone knows of another live cd that like sysresccd that has the ZFS on Linux modules, definitely feel free to add it here

Partitioning

Our system will be using GPT as the base and extlinux as the bootloader.

Let's create a directory to hold out zfs pool

# mkdir /mnt/pool

The layout will look like this:

/dev/sda1 8300 Linux FS 250M # This will be our /boot partition
/dev/sda2 8200 Linux Swap <YOUR_RAM * 1.5> # or w/e calculations you use
/dev/sda3 bf01 Rest of Disk # This will be the ZFS pool
Warning: You cannot put the swap inside the ZFS pool yet because it will have problems. This will probably be fixed in a future upstream version.
  1. Format the /boot partition as ext4 (or ext2-3)
# mkfs.ext4 /dev/sda1
  1. Make the swap and turn it on
# mkswap /dev/sda2
# swapon

Load up the spl/zfs modules (if needed)

# modprobe spl zfs

Create ZFS Pool and Mountpoints

# zpool create -o ashift=12 -o cachefile= -O normalization=formD -R /mnt/pool rpool /dev/sda3
# zfs create -o mountpoint=none rpool/ROOT
# zfs create -o mountpoint=/ rpool/ROOT/arch
# zfs create -o mountpoint=/home rpool/HOME
# zfs create -o mountpoint=/root rpool/HOME/root

Mount your /boot partition

# mkdir /mnt/pool/boot
# mount /dev/sda1 /mnt/pool/boot

Move the arch-zfs.tar.bz2 file to your system. You can use scp if it's over the network, or a flash drive if you are within walking distance.

# scp /arch-zfs.tar.bz2 root@<ip_of_new_computer>:/mnt/pool

Extract the Arch backup (Preloaded with ZFS modules and configured for ZFS)

# cd /mnt/pool
# tar -xjpvf arch-zfs.tar.bz2 .

Install Extlinux bootloader

Bind a few mountpoints in the chroot env before chroot so that extlinux can find the correct device

# mount --bind /proc ./proc
# mount --bind /dev ./dev
# mount --bind /sys ./sys
# env -i HOME=/root TERM=$TERM chroot . /bin/bash --login
 
# The below commands are executed within the chroot environment

# mkdir /boot/extlinux
# extlinux --install /boot/extlinux

Set correct boot flags in the GPT legacy bios and then flash gptmbr

# sgdisk /dev/sda --attributes=1:set:2
# sgdisk /dev/sda --atributes=1:show
# dd count=1 bs=440 conv=notrunc if=/usr/lib/syslinux/gptmbr.bin of=/dev/sda

Make an extlinux.conf

# cd /boot/extlinux
# vim extlinux.conf

Inside extlinux.conf put the following

PROMPT 0
TIMEOUT 50
UI menu.c32

MENU TITLE Boot Menu
DEFAULT arch

LABLE Arch
    MENU LABEL Arch Linux
    LINUX /vmlinuz-linux
    INITRD /initramfs-linux.img
    APPEND zfs=rpool/ROOT/arch zfs_force=1

and save it.

That's it, restart your computer and you should be inside Arch on ZFS :)!