Saturday, 3 March 2012

FreeBSD with ZFS

During the past few weeks I had a few installs of FreeBSD and PC BSD. Since everything regarding these installs were well documented, standard install went without a hitch. Installed x11, gnome, kde the lot... All the same as debian; but, I learned about some new things. For instance,  I never knew what Scroll-lock is for cos I didn't need it. But the knowledge I gained made be want more...wait....

Problems started to appear when my laptop could not properly go in to a sleep/resume cycle, which is mentioned as normal in the freebsd handbook. not content at all... But figured that I can debug ACPI if I compile the "kernel". ha ha .... On another note, I wanted small fonts in the consoles like I had in debian and ubuntu. Again documentation concludes that I need to do a "kernel" compile. great ha... This is starting to give me a bit of a chill ("kernel compile"). In linux I was used not to touch anything with "kernal" in the title or description, let alone compile it... Hmm... freebsd handbook chapter 9 talks in detail about that and seems to be a smooth ride... Let me see... And, I wanted ZFS instead of UFS; apparently, for no good reason.

Found some help pages and blogs and forums
1. This is how to partition MBR for freebsd 8 (official).
2. This is how to partition GPT for freebsd 9 in complete command line.
3. There is a video on how to partition GPT for freebsd 9 using part command line and part standard installer.

However I wanted to install in an MBR partion using freebsd 9. The problem is freebsd 9 uses a new installer making parts of official institutions in (1) invalid. With a little merging of (1),(2) and referring to (3) all the time, I managed to come up with something that really worked. Here's how.

  1. Boot from CD/DVD/USB and start installer as normal. Proceed until you reach partitioning. 
  2. Drop to "Shell" partitioning.
  3. In mine the disk was labelled 'ada0'. 'ada0s3' was the linux partitions and  'ada0s1' was simply the freebsd partition made during the previous installations. 
  4. Create freebsd zfs and swap partitions. Unlike UFS partitions, no need to create separate ones for /, /usr, /var. Even swap can reside inside the zfs but was warned against that in (1). So,
    gpart add -s 135G -t freebsd-zfs ada0s1
    gpart add -t freebsd-swap ada0s1
    
    My BSD partition was 145GB. So 135 for data and 10GB rest for swap.
  5. Then create a ZFS pool named 'zroot'. If for anything it fails add -f flag.
    zpool create zroot /dev/ada0s1a
  6. Then create the boot properties, checksum and mount points.
    zpool set bootfs=zroot zroot
    zfs set checksum=fletcher4 zroot
    zfs set mountpoint=/mnt zroot
    
  7. Now install ZFS Boot
    zpool export zroot
    dd if=/boot/zfsboot of=/dev/ad0s1 count=1
    dd if=/boot/zfsboot of=/dev/ad0s1a skip=1 seek=1024
    zpool import -o cachefile=/var/tmp/zpool.cache zroot
    
    if anything goes wrong refer to (1).
  8. Create the file system
    zfs create zroot/usr
    zfs create zroot/usr/home
    zfs create zroot/var
    
    Create other file system parts. Now the syntax is
    zfs create (-o PROPERTY=VALUE)* MOUNT
    
    eg. for compression(ON), exec(ON) and mount (zroot/tmp) type
    zfs create -o compression=on -o exec=on zroot/tmp
    
    Mountcompressionexecsetuid
    zroot/tmpononoff
    zroot/usr/portslzjboff
    zroot/usr/ports/distfilesoffoffoff
    zroot/usr/ports/packagesoffoffoff
    zroot/usr/srclzjboffoff
    zroot/var/crashlzjboffoff
    zroot/var/dboffoff
    zroot/var/db/pkglzjbonoff
    zroot/var/emptyoffoff
    zroot/var/loglzjb off off
    zroot/var/mailgzip offoff
    zroot/var/runoff off
    zroot/var/tmplzjb on off
  9. Add symbolic links to /home and set permissions for tmp
    chmod 1777 /mnt/tmp
    cd /mnt ; ln -s usr/home home
    chmod 1777 /mnt/var/tmp
    
  10. Exit to standard installation.
    exit
  11. Continue as normal and finally exit from the installation. and select LiveCD instead of Reboot.
  12. Login as 'root' without password.
  13. Copy zpool cache to file system.
    cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
    
  14. Edit /etc/rc.conf, /boot/loader.conf.
    echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
    echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
    echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf
    
  15. register swap space in fstab
    echo '/dev/ada0s1b  none  swap  sw  0  0' >> /mnt/etc/fstab
    
  16. Unmount everything and mount again
    zfs set readonly=on zroot/var/empty
    zfs umount -af
    zfs set mountpoint=legacy zroot
    zfs set mountpoint=/tmp zroot/tmp
    zfs set mountpoint=/usr zroot/usr
    zfs set mountpoint=/var zroot/var
    
  17. Reboot.
    reboot now

And it worked...
Next... kernel compiles....

Monday, 6 February 2012

Why FreeBSD/PCBSD ?

Why Not... I always had an interested in Linux when I first had a computer. Those days I tried installing Red Hat Linux 5.0 but had problems configuring hardware and soon lost interest. However, I had an Apple Mac during my undergrads; hence... a bit of a taste of unix(linux) there during programming... But I wasn't truly in need of ditching my Windows computer. When I started research I had to use external libraries which were primarily written for unix like OSs. I stil survived another year with Cygwin and Windows XP. But had difficulties in compiling and getting things work. That's the time I got this ThinkPad SL510 with Win 7 installed. I decided immediately to give Ubuntu 10 (at the time) a go with dual boot. I was simply addicted to it and never booted windows again. I was happy and got my work done in half the time  I could under Windows and external libraries, boost were all there with a simple apt-get. I even got used to EMACS for all my text editing.

Another year passed by, and I realised that Ubuntu lacked some oomph here and there and observed some lagging in multi tasking. I heard that mother of Ubuntu is still out there performing faster so I erased Windows completely to make space for a Debian installation of squeeze. It looked a bit out dated so soon upgraded to wheezy and unstable. I was truly happy.

I still have my Debian installation (as of this first post) and been experimenting with OSs since then. I gave Arch Linux a go... But realised that Debian could do the same... Hmmm.... Which ever distro I stumbled upon, It just confirmed Debian is strong and can't be beaten with the combined flexibility and stability, proving this review.

While day dreaming, I asked my self, why Apple is so nice but still stable and Linux is still short of that prettyness? GNOME can be a bit prettier and KDE can be a less prettier and more fluid (I mean...look less like Win 7). One reason for OS Xs to be stable is their set, tested hardware config. But why not give its base system FreeBSD a go.

Then I read about Beastie (BSD), and found manuals for everything. Not bad eh...