Aug 6, 2014

Booting FreeBSD with the RAM disk as root file system from GRUB 2

Recently I needed to boot FreeBSD on our development laptop that normally boots from the network using PXEGRUB. Traditionally the kernel is loaded using PXE and then mounts a NFS root file system. In my case I didn't have any ready NFS shares, and I didn't really want to setup any -- after all, I needed the running FreeBSD system to do a couple of quick tests.

In Linux world, there is a thing called initrd -- a small (or, well, sometimes not so small) disk image that is loaded into memory and that is used by the kernel to setup a minimal environment. Loading initrd is implemented in GRUB using the "initrd" command.

*BSD kernels may be booted using the GRUB as well. Additionally, there are a couple of extra commands for dealing with *BSD modules and ramdisks, for example kopenbsd_ramdisk command. As the name suggests, it loads an OpenBSD ramdisk into the memory so the kernel is able to mount it after boot.

There is no such command for the FreeBSD kernel, which made me a bit sad.
But after looking through the source code of GRUB and FreeBSD kernel, I have found a way to do it without any modifications of either kernel or GRUB.
There is an undocumented parameter for the kfreebsd_module command, which allows to specify the type of an object being loaded as a module. Its name is, unsurprisingly, "type" :-) GRUB adjusts the type attribute of the loaded object so that kernel is able to initialize the memory disk. Thanks to the flexible FreeBSD module loading system, no special GRUB code is needed to load the FreeBSD disk image.

So the configuration entry for loading the FreeBSD kernel with the ramdisk from some location is:

menuentry "FreeBSD" {
        kfreebsd $rootloc/fbsd-kernel
        kfreebsd_module $rootloc/fbsd-rd.img type=mfs_root
}
Of course the GRUB should be able to load "bsd" GRUB module (or have it statically compiled in), otherwise kfreebsd* commands won't be available.

fbsd-rd.img is a normal disk image with an UFS file system on it.
If $rootloc is somewhere in the network (for example, we load the binaries using GRUB HTTP loader), you can compress the image using gzip, since GRUB automatically detects compressed data and uncompresses it before loading into the memory. I use a compressed FreeBSD 10/amd64 memstick image that can be downloaded from the FreeBSD website.

Feb 25, 2012

Мастерство упаковки

Переезд -- хороший способ отделить то, что нужно по жизни, от того, что не нужно. Когда всё, с чем жил до этого много лет, нужно упаковать в 2 сумки по 20кг, это заставляет хорошо задуматься над смыслом этих вещей.
А пока в прихожей растёт гора пакетов, которым предстоит сегодня отправиться на помойку.

Apr 24, 2011

Simple sharding in YCSB's JDBC driver

Recently I've started using YCSB benchmarking framework while writing my PhD thesis. I like it because it has clear and simple architecture, and allows benchmarking not only SQL-based database systems, which is critical for me.

However, it would be wonderful to have an opportunity to compare non-SQL based database systems with traditional SQL-based ones. Recently it was made possible thanks to the great work of Sudipto Das, who has contributed JDBC driver to YCSB. So now any database that has SQL interface can be benchmarked with YCSB.
The only thing that was missing was sharding. If we want to see behavior of database systems while dealing with really HUGE amounts of data, it's desirable to run the database system on multiple servers. But while such systems as Cassandra have built-in clustering capabilities, other ones (such as MySQL) don't. So application developers are forced to implement "sharding" for those databases by writing some application logic to spread data across multiple database servers.
I have added simple sharding capability to JDBC driver for YCSB, to make it possible to benchmark real sharded setups. The pull request can be found here. I was able to run the benchmark against 3 MySQL servers, each holding 1/3 of dataset. Since YCSB uses very simple queries by primary key against only one table, it's easy to define sharding function S(key), S = hash(key) % number_of_shards. This works well when number of shards is constant. By now I'm not sure if it reasonable to test elastic speedup of hand-made sharding MySQL setup, because it offers no automatic cluster rebalancing anyway.