RSS

Install Ubuntu 10.04 server on ZFS « 下海去

09 Gen

Last year, Knowledge Quest (zfs.kqinfotech.com) announced their ZFS Linux port, and a closed beta was released late last year. Yesterday, I tried to install Linux on a ZFS file system, just in case. Surprisingly, I succeeded, partially though. I was surprised because according to information from KQ’s website, rootable Linux ZFS is currently unsupported.

The installation is, in fact, not too difficult, just hack initramfs-tools.

Before trying the instructions on your system, make sure you have a good backup of everything. You should know how to install a basic ubuntu system with debootstrap, and you should be familiar with grub/grub2 commands. Some programming skills will make things much easier.

Let’s rock!!

1. Install ubuntu 10.04 64-bit server edition on some place.

Yes, this is a huge step. Other Linux distributions/editions might work, I haven’t tried, but it must be a 64-bit Linux, because zfs-linux only works on 64-bit systems.

2. Get zfs-linux.

You can download the binary distributions or compile from source. The binaries can be found here, sources can be found here. I compiled zfs-linux from source, because the binary kernel modules simply don’t load.

If you compile from source, pass option –prefix=/usr to the configure scripts. If you install from binaries, mv all the shared libraries zfs and zpool need to /usr/lib.

4. Create your pool and root file system

Change the command according to your own system setup.

1
2
3
zpool create Vault /dev/sdb1
zfs create Vault/system
zfs create -o mountpoint=legacy Vault/system/linux

5. Install a basic system with debootstrap or cp.

1
2
3
mkdir /tmp/root
mount -t zfs Vault/system/linux /tmp/root
debootstrap lucid /tmp/root

After debootstrap, you should configure your basic and install zfs on it. If you know exactly which files a basic Linux needs, you can just copy all the files Linux needs to /tmp/root! In fact, I just copied all the files on the system I was working on to /tmp/root. Because the system I was working on was a basic ubuntu 10.04 server installed with debootstrap :)

6. Hack initramfs-tools.

For me, this was the most difficult step, I have rebooted my computer for more than 20 times to get this correct and it took me a whole day. But for you, this probably is the easies step.

Create file /etc/initramfs-tools/hooks/zfs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cat > /etc/initramfs-tools/hooks/zfs
#!/bin/sh
case $1 in
    prereqs)
    exit 0
    ;;
esac
 
. /usr/share/initramfs-tools/hook-functions
 
copy_exec /usr/sbin/zpool /sbin
copy_exec /usr/sbin/zfs /sbin
 
mkdir -p ${DESTDIR}/usr/bin
 
# The SPL kernel module needs these two executables to work.
# XXX This is very bad design, send your complaints to the developers
copy_exec /usr/bin/gawk /usr/bin
copy_exec /usr/bin/hostid /usr/bin
 
manual_add_modules lzfs
manual_add_modules zpios
EOF
chmod x /etc/initramfs-tools/hooks/zfs

Create file /etc/initramfs-tools/scrits/zfs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
cat > /etc/initramfs-tools/scripts/zfs
#!/bin/sh
 
mountroot()
{
    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
    run_scripts /scripts/local-top
    [ "$quiet" != "y" ] && log_end_msg
 
    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
    run_scripts /scripts/local-premount
    [ "$quiet" != "y" ] && log_end_msg
 
    ZFS=${ROOT#/}
    ZPOOL=`echo ${ZFS}|sed 's/\/.*//'`
    modprobe lzfs
    zpool import
    zpool import -f ${ZPOOL}
 
    # Only mount the root filesystem
    zfs umount -a
    mount -t zfs ${ZFS} ${rootmnt}
 
    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
    run_scripts /scripts/local-bottom
    [ "$quiet" != "y" ] && log_end_msg
}
EOF

You should tune these two files according to you own hardware setup, for example, to load a special disk driver. Read file /usr/share/initramfs-tools/init before change anything.

Generate your own RAM disk:

1
2
3
4
5
mkinitramfs -o /boot/zfs.img
## The following line is also OK, as long as your pool is a single drive
## pool or a mirrored pool. Just make sure that grub/grub2 can find
## you RAM disk and you kernel image.
# mkinitramfs -o /tmp/root/boot/zfs.img

7. Reboot

On the grub2 prompt, type the following commands, don’t miss the “boot=zfs” kernel argument.

1
2
3
linux root=/Vault/system/linux boot=zfs
initrd
boot

Caveats:

When ZFS is used as the root filesystem, every newly created file got a “0000″ permission, which makes the system almost unusable.

ZFS on Linux is still buggy. I lost all the uncompressed frame pictures for the movie “Big Buck Bunny”, it took me a whole week to download these pictures. Fortunately I got backup.

Happy ZFS’ing

This entry was posted on Sunday, January 9th, 2011 at 1:58 pm and is filed under Unix. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Annunci
 
Lascia un commento

Pubblicato da su 9 gennaio 2011 in Senza categoria

 

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

 
%d blogger hanno fatto clic su Mi Piace per questo: