Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ [1] 2 3 4 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: unionfs examples, using unionfs for a variety of things< Next Oldest | Next Newest >
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: April 17 2006,02:50 QUOTE

I thought that the unionfs.dsl I made needs a little explanation and a few examples.  The reason it needs explanation is because some people really hate unionfs (one person commented it was why they stopped using Knoppix) and I'm not suggesting it gets incorporated into the dsl base.  Things work fine the way they are and there's no need to change this drastically now.  It would cease to be dsl if you did that.  I think unionfs has some great uses besides basing the distro around it.  The examples might help people think of even better ways to use it to make things easier.

The easiest way to describe unionfs is to say that it combines two or more directories so that they appear to be a single directory.  On the surface that might not seam like such a big deal.  Say you have a directory called dir_one containing a file called one and a directory called dir_two with a file called two.  If you make a third directory called dir_sum , you can run the following command to make the contents of dir_one and dir_two to appear to be in dir_sum:

Code Sample
sudo mount -t unionfs -o dirs=dir_one=ro:dir_two=ro unionfs dir_sum


Now running the ls command on dir_sum shows one and two.  This is typical of the type of example you see and while it shows the basics, it misses some of the finer points.

It is also possible to combine read/write directories with read only ones, the result of which is a directory that appears to contain all of the files in the read only directory, but also allows writes to it.  One massivly usefull application of this is in the remastering process on lower memory, no ext2 formatted drive machines.  During the remastering process, I typically create a source directory and copy the contents of /KNOPPIX into a source/KNOPPIX directory.  This takes up a lot of memory since I remaster to my ramdisk.  I found I could save a substantial amount of resources by doing the following:

Code Sample
mkdir KNOPPIXtemp
mkdir source
mkdir source/KNOPPIX
sudo mount -t unionfs -o dirs=KNOPPIXtemp=rw:/KNOPPIX=ro unionfs source/KNOPPIX


Using this method rather than the normal route of

Code Sample
mkdir source
sudo cp -Rp /KNOPPIX source


I saved 245724 kilobytes according to the free command (the unionfs way used 119140Kb and the normal way used 364876 Kb).  Now you can add things to the source/KNOPPIX directory and they get put into the KNOPPIXtemp directory.  You can delete files and a .wh file for the deleted file gets created in KNOPPIXtemp that removes the file from the virtual drive.  The rest of the remastering process can take place normally, and the new source/KNOPPIX directory behaves the way you would expect.

Another neat example I found was when you want to have a /usr/src/linux-2.4.26 directory but you dont't want to take up all that room in the ramdisk.  By using unionfs, you can not only add that directory by combining the files from a CD or from somewhere in KNOPPIX (say you remastered with it) but you can write to the directory as well.

Code Sample
sudo mkdir /usr/src
sudo chown dsl /usr/src
sudo chgrp staff /usr/src
mkdir /usr/src/linux-2.4.26
mkdir srclinuxtemp
sudo mount -t unionfs -o dirs=srclinuxtemp=rw:/mnt/cdrom1/linux-2.4.26=ro unionfs /usr/src/linux-2.4.26


You can now run everything you need to in the /usr/src/linux-2.4.26 directory to compile drivers and the only thing that gets added to the ramdisk are the changed and created files.  So there is a huge space savings in terms of memory.

There are other possibilities, like creating a CD that has your programs and files on it, and the using a temp directory and unionfs to make the files writeable even though they are on a CD.  Or patching a CD by using unionfs to combine the CD with a directory of patched files.
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: April 17 2006,12:51 QUOTE

hmmmmm....I don't see the usefulness of adding another tool to accomplish the same thing you can already do with cp -s
Anything else it does besides share files between directories?

Not saying it's not useful...just trying to figure out if it would be useful to me.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
clivesay Offline





Group: Guests
Posts: 935
Joined: Dec. 2003
Posted: April 17 2006,13:23 QUOTE

This is all a little over my head, I think, but if I understand the first example correctly, would this allow you to run .dsl files as .uci's without using additional ram by making the filesystem writable? It seems you are saying you can take exisitng dirs and basically point them to another location? If that was true, then all .dsl files could be like uci's? I've never quite understood the whole unionfs thing :)
Back to top
Profile PM MSN YIM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: April 17 2006,14:02 QUOTE

Correct me if I'm wrong, but i don't think it would work that way.  You create a separate directory, so that directory would not be in PATH, LD_LIBRARY_PATH, etc.  The original directory is untouched, so the system would not behave any differently. You would still need a wrapper for many uci-like packages to work.
As far as I can tell, this is similar to what mkwriteable does for the base DSL system, in that you can write to these directories but the original files are untouched.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: April 17 2006,19:42 QUOTE

mikshaw, the real use is to start with a directory that isn't writeable and make it writeable, but it also makes the files that were in the read only directory writeable.  If you used the cp -s command, yes, you would wind up with a writeable directory populated with links to the files in the read only directory.  But you wouldn't be able to change or write to those files without deleting the link and replacing it yourself with the real file.  With unionfs, if you needed to overwrite a something.conf file that was in the original directory, it would do it without an error.  Your way would say that the file is write only.

So sure, the ln -s or cp -s way works, but only if none of those files need to change.  Take the example of the /usr/src/linux-2.4.26 directory.  If I had a .config file in there when I started, I wouldn't be able to write over it after running make menuconfig.  Using unionfs you could.  For the remastering and creating the source/KNOPPIX directory I gave, your way doesn't work because the mkisofs command creates an iso of the links and not the files as well as not allowing file modifications.

clivesay, yes you can make uci files writeable using unionfs.  This is similar to what slax does in their distro.  You would mount the something.uci file (really a compressed file system created with mkisofs and create_compressed_fs) to /opt/something_ro rather than to /opt/something like you normally would, create /opt/something and /opt/something_rw directories, and use unionfs to merge them into a writeable directory in /opt/something.  You could do:

mount -t unionfs -o dirs=/opt/something_rw=rw:/opt/something_ro=ro unionfs /opt/something

Now the /opt/something directory is writeable, as are the files it already contained.  Any changed files get added to the /opt/something_rw directory.
Back to top
Profile PM 
19 replies since April 17 2006,02:50 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ [1] 2 3 4 >/
reply to topic new topic new poll
Quick Reply: unionfs examples

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code