Creating System Rescue CD ZFS Modules
This HOWTO will show you how to create your own zfs srm or download the prebuilt zfs srm module from my website.
Compiling a compatible kernel
The first thing you need to do is decide for which version of System Rescue CD you will be building for. Each System Rescue CD version has a different set of kernels. Specifically each version has a Stable kernel and an Alternate Kernel. The stable kernels get minor version increments every release (Sometimes major ones but usually doesn't happen too quickly), the Alternate kernels tend to move up much faster. For example System Rescue CD had the following stable/alternate kernels:
Download kernel and patches
Once you decide which version you want to use, you can go to http://kernel.sysresccd.org/ and pick the version you want. After you do this, download all the stuff in that directory and put them in their own folder (a work directory). The files that are named std-sources are the patches for the regular stable kernel, the patches named alt-sources are the patches for the alternate kernel. Once you have the patches, go to kernel.org and also download the initial release of the kernel sources you want. For example, if you want to build an srm for 3.4.2 which uses the 3.4.35 kernel, just download the 3.4 (3.4.0) kernel. You just need to download the initial release because one of the patches you downloaded earlier is the patch to update the 3.4.0 to 3.4.35.
Once you download the kernel you want, let's extract and patch it.
# tar xf linux-3.4.tar.bz2 # mv linux-3.4 linux-3.4.35-std342-amd64 # bzcat std-sources-3.4-01-stable-3.4.35.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64 # bzcat std-sources-3.4-02-fc16.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64 # bzcat std-sources-3.4-03-aufs.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64
Retrieve kernel configuration
Once that is complete, you will need to get the kernel config specifically for the kernel and architecture you want. The easiest way I found to do this was to download the System Rescue CD you want, and then boot it inside a VM. Once you are inside the VM, go to the /root directory, and it will be a file named kernel-<version>.conf. Copy this file over SSH and put it in a safe location. Also copy it over into the linux kernel directory and rename it to .config.
Build the kernel
Once you copy the kernel config over, do a make menuconfig to begin. You will only need to change two settings inside the config, add the proper kernel name, and remove the old initramfs source files directory. This directory doesn't exist locally. This is a remnant of upstream's build process.
Follow the below tree structure, and make it equal to what is below:
(-std342-amd64) Local version - append to kernel release [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support ( ) Initramfs source file(s)
The Local version above will end up making the kernel modules directory be 3.4.35-std342-amd64. The reason the kernel modules directory has to be equal to this is because our directory will be merged into the System Rescue CD later on, so the names need to be exactly the same so that the System Rescue CD system can find our kernel modules.
If you want to build an srm (which you do), you also need to change the following inside the kernel config so that squashfs-tools can work later on:
Miscellaneous Filesystems -> <*> SquashFS 4.0 - Squashed file system support [*] Squashfs XATTR support [*] Include support for ZLIB compressed file systems [*] Include support for LZO compressed file systems [*] Include support for XZ compressed file systems [ ] Use 4K device block size? [ ] Additional option for memory-constrained systems
Now save and exit, and continue to build your kernel.
# make bzImage modules # make modules_install
If you have multiple cores, do a make -j<# of processors+1> to build faster. Example: make -j9 for an 8 core machine.
Using the portage tree
Inside the portage tree, there are ebuilds already prepared that will download the kernel, patch it, and perform any required substitutions. Afterwards you literally just go into your /usr/src/<kernel> directory, and run make. To see the available versions, run the following:
Versions available for standard kernel # equery y std-sources [I]3.4.37-r1 | o ~ o o o o o o o o o o o | o 3.4.37 | gentoo Versions available for alternate kernel # equery y alt-sources [I]3.8.4 | o ~ o o o o o o o o o o o | o 3.8.4 | gentoo
I haven't written the ebuilds in a way where it's easy to tell (at first glance) what System Rescue CD version you need. However, you can check the ebuild and you will see the version of the CD inside there. You can also check the chart above.
If you wanted to install the standard kernel sources, you just emerge it like any other application:
# emerge std-sources
Once the kernel and the kernel module are installed, you need to make the SRM.
Creating the SRM
It's time to gather the required files and pack them together in order for it to become an SRM. An SRM is nothing more than a directory that has been compressed with squashfs. You can emerge the "Bliss Initramfs Creator" which has a feature that will automagically build the srm for you. You also need to have spl, zfs, and zfs-kmod installed on your system before you try to make the srm. Emerging "bliss-initramfs" should automatically pull those packages. If it doesn't, make sure you install them.
# echo "sys-kernel/bliss-initramfs srm" >> /etc/portage/package.use # emerge bliss-initramfsYou should now have the following directory layout inside the /opt/bliss-initramfs folder:
octopus bliss-initramfs # ls -l total 117 -rw-r--r-- 1 root root 6718 May 23 18:05 CHANGES -rw-r--r-- 1 root root 176 May 23 18:05 CREDITS -rw-r--r-- 1 root root 431 May 23 18:05 HELP -rw-r--r-- 1 root root 1397 May 23 18:05 LICENSE -rw-r--r-- 1 root root 1852 May 23 18:05 README -rw-r--r-- 1 root root 3194 May 23 18:05 USAGE -rwxr-xr-x 1 root root 2891 May 23 18:05 createInit drwxr-xr-x 3 root root 4 May 23 18:11 files drwxr-xr-x 3 root root 6 May 23 18:11 hooks drwxr-xr-x 2 root root 5 May 23 22:01 resourcesThen run the createInit script and follow the instructions for the kernel you want to make the srm for (In this case it's 3.4.37-std350-amd64):
----------------------------------- | Bliss Initramfs Creator - v1.8.1 | Author: Jonathan Vasquez <email@example.com> | Distributed under the Simplified BSD License ----------------------------------- >>> Which initramfs would you like to generate: >> 1. ZFS >> 2. Encrypted ZFS (LUKS + ZFS) >> 3. More Options >> 4. Exit Program >>> Current choice : 3 ↵ >>> More Options: >> 1. ZFS - System Rescue Module >> 2. Back >> 3. Exit Program >>> Current choice : ↵ >>> Creating a ZFS System Rescue Module! >>> Do you want to use the current kernel: 3.8.13-ALL? [Y/n]: n ↵ >>> Please enter the kernel name: 3.4.37-std350-amd64 ↵ >>> Detected 64 bit platform >>> Checking to see if modules directory exists for 3.4.37-std350-amd64... >>> Creating SRMs for 3.4.37-std350-amd64... >>> Creating directory structure for initramfs... >>> Checking preliminary binaries... >>> Checking binaries... >>> Using ZFS >>> Checking modules... >>> Copying binaries... >>> Copying modules... >>> Copying documentation... >>> Copying udev rules... >>> Compressing kernel modules... >>> Getting dependencies... >>> Copying dependencies... >>> Configuring files... >>> Creating and Packing SRMs... >>> Complete :)Now you should have two new files:
-rw-r--r-- 1 root root 2068480 May 24 01:05 zfs-core-3.4.37-std350-amd64.srm -rw-r--r-- 1 root root 483328 May 24 01:05 zfs-kmod-3.4.37-std350-amd64.srmNow all you need to do is put those two files in the root of your USB directory.
If you are making srms for both the standard and alternate kernels, you will end up with two zfs-core files and two zfs-kmod files (1 set for each kernel). You don't need to put the zfs-core that it makes for one of the kernels. The zfs-core srm only has zfs program binaries, man pages, udev rules, and a few other things. The zfs-kmod is the srm that has the kernel modules (and only the kernel modules). So you can easily just put two zfs-kmods (one for each kernel version) and just re-use the same zfs-core for both of them.
Using the prebuilt srm
Download the SRM
If you didn't build your own srm and want to use the prebuilt one, just emerge "zfs-srm" from the tree:
# emerge zfs-srm
You can check available versions just as you did above for the kernels:
Available versions of the zfs-srm # equery y zfs-srm [I]3.5.0 | o ~ o o o o o o o o o o o | o 3.5.0 | gentoo
(These versions match the version of the System Rescue CD).
Installing the zfs-srm will automatically pull the "bliss-isomaker" package which is just a script that assists you with rebuilding the System Rescue CD ISO so that the ISO includes the ZFS srms. The script lets you make a bootable ISO or a bootable USB.
Once it's installed, switch to the /opt/bliss-isomaker folder
# cd /opt/bliss-isomaker
You should now see a directory layout that looks similar to this:
octopus bliss-isomaker # ls -l total 100 drwxr-xr-x 2 root root 5 May 24 01:41 3.5.0 -rw-r--r-- 1 root root 1397 May 24 01:31 LICENSE -rw-r--r-- 1 root root 312 May 24 01:31 README -rw-r--r-- 1 root root 576 May 24 01:31 USAGE -rwxr-xr-x 1 root root 3228 May 24 01:31 create drwxr-xr-x 2 root root 3 May 24 01:41 iso drwxr-xr-x 2 root root 4 May 24 01:41 resources drwxr-xr-x 2 root root 3 May 24 01:41 srm
The layout is as follows:
- 3.5.0 - This folder contains the System Rescue CD 3.5.0 specific srms for both the standard and alternate kernel that were installed by emerge.
- create - A script to automatically recreate the system rescue cd iso or usb with the zfs stuff included
- iso - directory to place your system rescue cd iso in
- srm - directory that has the srms
- resources - the files in this folder contain function calls that the 'create' script uses. You don't need to worry about these.
Installing the SRM
There are a few ways to do this, you can either use one of the scripts, or you can do it manually. Before anything, make sure to copy the SRMs from the <Version> folder to the srm folder if you are using a prebuilt one:
# cp 3.5.0/* srm
Generating a new iso
If you just want to remake a new iso so that you can burn onto a cd or use in a virtual machine, just copy your iso over to the iso directory, and run the 'create' script. The new iso will be located in the iso directory as well with a -zfs ending.
Running the script with 1 (or iso) chooses to make an iso. You can also pass the version as well. # ./create 1 or # ./create iso 3.5.0
Creating a fresh usb
If you want to have zfs on a usb with system rescue cd, put the iso in your iso dir, and then run the usb script. It will ask you what usb you want to format (This will delete everything), and then install system rescue cd onto it. Once that is done it will copy the zfs stuff over.
Running the script with 2 (or usb) chooses to make an usb. You can also pass the version as well. # ./create 2 or # ./create usb 3.5.0
Manual installation onto a usb
Assuming that your installing to a flash drive and that the flash drive is mounted in /mnt
1. Mount your usb drive
# mount /dev/sdX# /mnt/usbstick
Where X# is the letter and number of your device. Immediately after you plug your usb in, type `dmesg | tail` in the console and you should see it. 2. Copy the zfs .srms to /mnt/usbstick
# cp zfs-core-3.4.37-std350-amd64.srm zfs-kmod-3.4.37-std350-amd64.srm zfs-kmod-3.8.4-alt350-amd64.srm /mnt/usbstick
3. List your /mnt/usbstick directory and you should see something similar to the following in your /mnt/usbstick
octopus 3.5.0 # ls -l /mnt/usbstick total 305028 drwxr-xr-x 3 root root 4096 May 23 20:51 boot drwxr-xr-x 2 root root 4096 May 23 20:51 bootdisk drwxr-xr-x 2 root root 4096 May 23 20:51 bootprog drwxr-xr-x 3 root root 4096 May 23 20:51 efi drwxr-xr-x 2 root root 4096 May 23 20:51 ntpasswd -rwxr-xr-x 1 root root 2349 May 23 20:51 readme.txt drwxr-xr-x 3 root root 4096 May 23 20:52 syslinux -rwxr-xr-x 1 root root 309252096 May 23 20:51 sysrcd.dat -rwxr-xr-x 1 root root 45 May 23 20:51 sysrcd.md5 drwxr-xr-x 2 root root 4096 May 23 20:51 usb_inst -rwxr-xr-x 1 root root 15889 May 23 20:51 usb_inst.sh -rwxr-xr-x 1 root root 877 May 23 20:51 usbstick.htm -rwxr-xr-x 1 root root 6 May 23 20:51 version -rwxr-xr-x 1 root root 2068480 May 23 20:51 zfs-core-3.4.37-std350-amd64.srm -rwxr-xr-x 1 root root 483328 May 23 20:51 zfs-kmod-3.4.37-std350-amd64.srm -rwxr-xr-x 1 root root 483328 May 23 20:51 zfs-kmod-3.8.4-alt350-amd64.srm
Now un-mount your flash drive and boot it into the machine that you want to use ZFS on.
# umount /mnt/usbstick
Booting into the correct kernel
If you are using the standard srm:
C) Standard 64bit kernel (rescue64) with more choice... > 1. SystemRescueCd with default options
If you are using the alternative srm:
E) Alternative 64bit kernel (altker64) with more choice... > 1. SystemRescueCd with default options
2. Run 'depmod' so that the new modules can be seen by the kernel.
You must run depmod. If you don't, then you will get failed to load the ZFS stack error!
3. Use ZFS as usual. If you type zpool status and then type dmesg | tail,
you should see something that says:
ZFS: Loaded module v0.6.1-1, ZFS pool version 5000, ZFS filesystem version 5
If you see the above, then the modules loaded successfully!
Enjoy System Rescue CD with ZFS :)
Using the premade iso
If you don't want to do any of the above stuff but just want the ISO with the ZFS SRMs already included, simply Download the ISO.