Search

mhddfs: join several real filesystems together to form a single larger one

May 25th, 2008 edited by Tincho

Article submitted by Roman Mamedov. Guess what? We still need you to submit good articles about software you like!

Suppose, you have three hard drives - sized 80, 40 and 60 GB. And 150 GB of music files, which you need to store on these drives. How would you do it?

The two solutions I knew of, were:

  • either to simply have three separate «Music» folders - one per each drive;
  • or create some sort of RAID, joining all the drives into an array.

However, the first method is quite tiresome, as one needs to decide how to split the data between the drives and keep track of what is stored where. For example, I might decide to store all «Classical» music on the first disk, and «Rock» music on the second. Then, suddenly, the first drive fills up and the second one still has plenty of space. Now I need to move the files between the disks, or jump around with symlinks.

The RAID method, while solving this problem, always incurs significant loss of either storage reliability or usable disk space.

But recently, I found a better solution to this problem and similar ones: mhddfs. It is a FUSE filesystem module which allows to combine several smaller filesystems into one big «virtual» one, which will contain all the files from all its members, and all their free space. Even better, unlike other similar modules (unionfs?), this one does not limit the ability to add new files on the combined filesystem and intelligently manages, where those files will be placed.

The package is called «mhddfs» and is currently present in Debian Testing and Unstable. It does not seem to be available in Ubuntu at the moment.

Let's say the three hard drives you have are mounted at /mnt/hdd1 /mnt/hdd2 and /mnt/hdd3. Then, you might have something akin to the following:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
...
/dev/sda1              80G   50G   30G  63% /mnt/hdd1
/dev/sdb1              40G   35G    5G  88% /mnt/hdd2
/dev/sdc1              60G   10G   50G  17% /mnt/hdd3

After you have installed the mhddfs package using your favourite package manager, you can create a new mount point, let's call it /mnt/virtual, which will join all these drives together for you. The beauty of FUSE means you don't really have to be root for this (can be just a member of the fuse group), but for the sake of examples' simplicity, let's suppose we are logged in as root here.

# mkdir /mnt/virtual
# mhddfs /mnt/hdd1,/mnt/hdd2,/mnt/hdd3 /mnt/virtual -o allow_other
option: allow_other (1)
mhddfs: directory '/mnt/hdd1' added to list
mhddfs: directory '/mnt/hdd2' added to list
mhddfs: directory '/mnt/hdd3' added to list
mhddfs: move size limit 4294967296 bytes
mhddfs: mount point '/mnt/virtual'

The «-o allow_other» option here means that the resulting filesystem should be visible to all users, not just to the one who created it.

The result will look like this:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
...
/dev/sda1              80G   50G   30G  63% /mnt/hdd1
/dev/sdb1              40G   35G    5G  88% /mnt/hdd2
/dev/sdc1              60G   10G   50G  17% /mnt/hdd3
mhddfs                180G   95G   85G  53% /mnt/virtual

As you can see, the new filesystem has been created. It joined the total size of all drives together (180G), added together the space used by all files there (95G) and summed up the free space (85G). If you look at files in /mnt/virtual, you'll notice that it has files from all three drives, with all three directory structures «overlayed» onto each other.

But what if you try to add new files somewhere inside that /mnt/virtual? Well, that is quite tricky issue, and I must say the author of mhddfs solved it very well. When you create a new file in the virtual filesystem, mhddfs will look at the free space, which remains on each of the drives. If the first drive has enough free space, the file will be created on that first drive. Otherwise, if that drive is low on space (has less than specified by «mlimit» option of mhddfs, which defaults to 4 GB), the second drive will be used instead. If that drive is low on space too, the third drive will be used. If each drive individually has less than mlimit free space, the drive with the most free space will be chosen for new files.

It's even more than that; if a certain drive runs out of free space in the middle of a write (suppose, you tried to create a very large file on it), the write process will not fail; mhddfs will simply transfer the already written data to another drive (which has more space available) and continue the write there. All this completely transparently for to the application which writes the file (it will not even know that anything happened).

Now you can simply work with files in /mnt/virtual, not caring about what is being read from which disk, etc. Also, the convenience of having large «contiguous» free space means you can simply drop any new files into that folder and (as long as there's space on at least one member of the virtual FS) not care about which file gets stored where.

If you decide to make that mount point creating automatically for you on each boot, you can add the following line to /etc/fstab:

mhddfs#/mnt/hdd1,/mnt/hdd2,/mnt/hdd3 /mnt/virtual fuse defaults,allow_other 0 0

For more details, see man mhddfs.

The last, but not the least important thing to mention, is the fact that it's very simple to stop using mhddfs, if you later decide to do so - and not lose any file data or directory structure. Let's say, at some point in time, you purchase a new 500 GB hard disk, and want to sell the smaller disks on Ebay. You can just plug in the new drive, copy everything from /mnt/virtual onto it, and then remove mhddfs mount point and disconnect old drives. All your folders, which were previously merged in a «virtual» way by mhddfs, will now be merged in reality, on the new disk. And thanks to the fact that files themselves are not split into bits which are stored on different drives, even in the unlikely event when mhddfs suddenly no longer works for you (or disappears from existence), you can still copy all your data from all three drives into one single folder, and have the same structure you previously had in that /mnt/virtual mount point.

Posted in Debian, Ubuntu | 30 Comments »

potrace: Transform bitmap images into vector graphics

May 19th, 2008 edited by Tincho

Article submitted by András Horváth. Guess what? We still need you to submit good articles about software you like!

You can face the task sometimes that you need a high resolution material from a particular image. Most probably when you’re a graphic designer (or even a tattoo artist), you might want to have a good quality result from a low resolution image that you can magnify no matter how much, it will give you smooth edges in high quality.

For this, you have the following possibility without a trace program: using a pixel graphic software like Gimp, you can resize the image with the best resampling method and apply a selective blur filter on it. Most of the times this doesn’t give the necessary quality.

There is a small but powerful utility called potrace developed by Peter Selinger, a mathematics professor at the Dalhousie University.

With a trace program like potrace, all you have to do is to give the image as an input, and there you have the result in the standard SVG format. potrace can produce even PDF format as an output.

Command-line example:

$ potrace -s image.bmp

With this process, the program transforms the images’ pixels into filled curves that have infinite resolution with smooth lines at any zoom.

In my personal experience while working as a graphic designer, potrace gave me very good results to many input images. Compared to other high expensive proprietary software, when the input image had sharp endings, potrace gave sharp edges in the result and other programs gave bad results, curving the edges. That needed a lot of manual correction.

Pros (compared to other programs):

  • Very good results
  • Pretty fast
  • Can be easily run from a command-line
  • Can be used from the Inkscape open-source vector graphics software (Path / Trace Bitmap menu or Shift+Alt+B)

Cons:

  • Only 2 colors output (Black & White), no colored process is available yet
  • potrace does not support PNG images as an input (though images can be converted easily from PNG with a whole variety of free programs)

This is an example found in the homepage, you can see the original bitmap and the vectorised image:

Original bitmap potrace output

The package has been available both in Debian and Ubuntu since a long time ago.

Related links:

http://en.wikipedia.org/wiki/Potrace

http://wiki.inkscape.org/wiki/index.php/Potrace

Posted in Debian, Ubuntu | 10 Comments »

kteatime - Small tray utility which reminds you of steeping tea

May 11th, 2008 edited by Patrick Murena

Article submitted by Stephan Windmüller. Guess what? We still need you to submit good articles about software you like!

For some people coffee seems to be the only liquid they drink in front of their workstation. But for those who enjoy a cup of tea once in a while, kteatime may be a neat little helper.

I expect every one of them knows this situation: The water just boiled, you put some green tea in your cup, add the water and return to your work. 15 minutes later you realize that you forgot your tea and only dozens of sugar cubes will rescue it. ;)

kteatime helps you to prevent this situation in form of a little timer in the tray.

kteatime configuration window

After selecting the appropriate kind of tea and starting the timer it will display a little circle which turns from red to green. The tooltip informs you how long your tea will need.

When your tea is ready, kteatime informs you with a beep and a little pop-up. You can also specify a command which should be run.

tea ready pop-up

For me kteatime is the only reason besides k3b to keep the KDE libraries installed. Even as a KDE application it just works fine under XFCE.

kteatime is available since Debian Sarge (perhaps even longer) and also part of every version of Ubuntu.

Posted in Debian, Ubuntu | 8 Comments »

cu: Simple serial communication program

May 4th, 2008 edited by Tincho

Article submitted by Floris Bruynooghe. Guess what? We still need you to submit good articles about software you like!

If you have servers, embedded systems or high end routers (or old PC’s doing those jobs) chances are that they will have a console on a serial port instead of being equipped with a display and keyboard. Even when normally you use ssh(1) or similar to log in to those machines, in debugging and rescue sessions you often want to see console messages, pull down the network interface or maybe play with the boot loader (like launching alternate kernels from within grub). You then need a null modem cable (often supplied by vendors when they use RJ45 plugs for the serial console instead of RS232) to connect the serial port of your computer to the serial console of the device.

Now you also need a program, often called a “serial communications” program, that can connect to your serial port and allow you to use your terminal as the console of the attached device. Most serial communication programs however where actually made in an era when most networking happened by using a modem —attached to the serial port— to dial up other systems. As a result of this they tend to have very heavy and bloated interfaces, giving you all sort of modem-specific functionality via a complicated interactive interface. This is where cu comes in! It is a very simple version of it: a simple command line program doing the bare minimum needed.

In it’s simplest scenario, described above, invocation is trivial:

$ cu -l /dev/ttyS0

For example this is how I connect to my home router (normally I’d use apt-get over ssh though):

flub@laurie:~$ cu -l /dev/ttyS1
Connected.

Debian GNU/Linux 4.0 balder ttyS0

balder login: root
Password:
Last login: Sun Apr 13 19:58:46 2008 on ttyS0
balder:~# apt-get update
...
balder:~# apt-get upgrade
...
balder:~# logout

Debian GNU/Linux 4.0 balder ttyS0

balder login: ~.
Disconnected.
flub@laurie:~$ 

As you can see here I used the seconds serial port (ttyS1) of my local machine (laurie) to connect to the first serial port (ttyS0) of the router (balder), which is configured to run a getty on it. This allows me to log in and do any task I want just like from any other terminal. Disconnecting is done just as in ssh by default: by typing `~.‘ just after you have typed a newline.

The above will connect you to the serial line configured as 9600, 8n1 (9600 baud rate, 8 data bits, no parity, 1 stop bit). This is most likely the default setting on the device. However as this is sometimes a little slow you might want to configure your server (or whatever the device is) to use a faster baud rate, or maybe your vendor did that already and told you in their documentation what speed to use. The speed is easily changed by another command line switch:

$ cu -l /dev/ttyS0 -s 150000

If you need to change the parity this can be achieved by using -e for even and -o for odd parity. The stop bits and data bits can’t be changed by command line switches unfortunately, but needing them seems very rare.

cu does have a fair few more options and some more commands starting with the `~‘ escape character. Most of these have to do with using modems to dial other systems however and are not applicable for null modem use. The manual page, cu(1), gives a detailed description of more advanced features.

(1) If you’re unlucky enough to not have a serial port anymore, like many modern laptops, a USB-dongle with a serial port is usually assigned to /dev/ttyUSB0.

Posted in Debian, Ubuntu | 11 Comments »

Thanks!

May 3rd, 2008 edited by Tincho

Hi again,

A few weeks ago, I wrote a call for help as we were lacking material for keeping the site alive. I’m very happy to say that it was a success! We received many great articles that we’re currently drafting for publication (you have already seen some), and lots of support. You people rock!

We will be keeping the weekly schedule for now, just to be on the safe side. If the contributions keep flowing, we might be able to do twice a week posts again.

So thanks to all of you: silent readers, commenters and writers. You’re great and you are the reason and life of this site!

Posted in Debian, Ubuntu | 3 Comments »