GetStartedMounting

From Elektra Initiative

Get started

Download the package from ftp://markus-raab.org/elektra-0.7.0.tar.gz or http://markus-raab.org/ftp/elektra-0.7.0.tar.gz

or follow instructions of Get

run ./configure maybe with --prefix=/your/home (read INSTALL or ./configure --help) You can uninstall anytime my running "make uninstall." (only some empty folders may stay on your system but you need to use the same source package for uninstall)

Watch out to set $PATH that the executables in /your/home/bin will be found and set $LD_LIBRARY_PATH so that the library in /your/home/lib will be found. If you did not set any prefix, you need:

export PATH="$PATH:/usr/local/bin"
export LD_LIBRARY_PATH=/usr/local/lib 

if you used the DESTDIR feature add (dont do it, its for another purpose)

export LD_LIBRARY_PATH=/usr/local/lib/elektra

too

Make sure to have write access to $PREFIX/etc/, using /usr/local you now might need root privilegies. You can't use sudo, because it will throw away LD_LIBRARY_PATH.

get and set keys

Considered that you can start set and get a key:

kdb set system/filesystems/rootfs/type ext3
kdb get system/filesystems/rootfs/type

It is now stored with the default backend, the so called "filesys" backend in the file $PREFIX/etc/kdb/system/filesystem/rootfs/type.

Mounting

Thats the old story, the new tool "preload" preloads configuration into your fresh elektra namespace. There is a special place inside the elektra namespace under system/elektra/mountpoints where you can define what backend is mounted where. These keys can be set easily with "preload mount".

preload system
preload conf
preload mount hosts system/hosts/ hosts /tmp/hosts

Make sure to copy the hosts file and let us see the content:

cp /etc/hosts /tmp/hosts
kdb ls system/hosts/ 

set and get works as expected:

kdb get system/hosts/localhost
kdb set system/hosts/newhost 120.180.200.100

(See /tmp/hosts if the newhost was really added)

But you can also add and change aliases:

kdb set system/hosts/localhost/alias00 ip4-localhost

will change in /tmp/hosts:

127.0.0.1       localhost

to

127.0.0.1       localhost       ip4-localhost

Of course you can also show it with

kdb get system/hosts/localhost/alias00

Make sure to get the alias number right, it begins with 00 as first alias.

You can even set comments:

kdb -c "This is your localhost-comment" set system/hosts/localhost 

You can't get comments with kdb (kdb needs a rewrite...), but you can see it in /tmp/hosts:


127.0.0.1       localhost       ip4-localhost   #This is your localhost-comment


Now lets try it with the fstab file, mounting goes as expected:

preload mount fstab system/filesystems/ fstab /tmp/fstab

Now copy your fstab file and lets output the keynames.

cp /etc/fstab /tmp/fstab
kdb ls system/filesystems/ fstab

Wow, you get a output of your fstab. /tmp/fstab is used to be on the safe side, but for 0.7.0 you can trust elektra enough to use your /etc/fstab ;)

This works only if you enabled the fstab backend with ./configure --with-fstab

What happend is self-explainable. The backend fstab was mounted to system/filesystems/ using /tmp/fstab as file. Everything below system/filesystems/ is now under the control of the fstab backend. The rest is still controlled by filesys.

Now lets get and set single keys. This is as easy as

kdb get system/filesystems/rootfs/type
jfs
kdb set system/filesystems/rootfs/type ext3
kdb get system/filesystems/rootfs/type
ext3

Take a look into /tmp/fstab, you see the value actually changed.


All of this was possible without changing the kdb-tool, everything was done inside the elektra library featuring kdbSetKey() and kdbGetKey().

But the possibilities of mounting backends go far beyond editing existing files like /etc/fstab, /etc/mtab or /etc/hosts (or copies of them). Any application using elektra wanting key/value pairs representing a canonical name, another name and aliases for it could store this configuration in the hosts backend, leading to easy access from programs without losing editable files.

Additionally kdb importing and exporting makes your life easier. Just run

curl http://www.markus-raab.org/Info/Config/Elektra/filesystems.xml | kdb import -

to import a filesystem config done by me, directly in your desired backend. Be sure to trust the url ;)

(Be sure to have libxml-dev installed while installing elektra, otherwise libelektratools will be disabled and xml importing does not work. In version rc2 there comes an error "Key has no name" because of wrong return values, but it works. kdb-tool will be tackled for rc3)

Views
MediaWiki