Wednesday, November 18, 2009

Shared Folders in VirtualBox with Ubuntu Server

I really enjoy VirtualBox. After knowing it a little, I quit thinking about VMWare, for my Linux courses. Now, there is something really necessary when you work with more than one Virtual Machines: a shared folder.

A shared folder exists in the host system, and accessed by one or more guest systems. Thus, if VM1 needs to copy a file to VM2, just copy it to that folder. Easy like that.

Defining the Shared Folders
First, in Virtualbox console, you set one or more folders to be shared, as shown:

In the right panel above, you can see "Shared Folders". In this example there are already 2 shared folders. Click "Shared Folders", written in blue.

All shared folders are listed here. To add one more, click the folder with a "plus" signal, at the right side.

Write the host's folder full location, at "Folder Path" field. Optionally, this folder can be set as Read Only.

Virtualbox will suggest a name according to the folder's name, as you can see above.

Preparing Virtualbox Software
Now, let's make it available in our virtualized Ubuntu Server. First, we need to install it:

$ sudo aptitude install build-essential dkms

After that, "install Guest Additions" in "Devices" menu. It is an ISO image, and will work as if it is a CD.

Let's access it's contents

$ sudo mount /media/cdrom
$ cd /media/cdrom

In this folder there are several scripts, one for each system. You need to know wich version you have. Type the following:

$ uname -m
x86_64

My VM is a 64 bits. In my case I should type the following:

$ sudo ./VBoxLinuxAdditions-amd64.run

If the answer is "i686", the script must be "VBoxLinuxAdditions-x86.run". Any of them will first verify it's integrity, and after start some compilations. It will take a couple of minutes. Since we are using Ubuntu Server, a message warns that "X Window drivers will not be installed".

Building VirtualBox Kernel Modules
After all that, we are ready to build Virtualbox kernel modules, which is a really simple step. First, you will need to install kernel headers. Verify your kernel version with the command

$ uname -r

My system is kernel "2.6.31-14-server". My kernel is "server" type, so my kernel headers are installed with the following command:

$ sudo aptitude install linux-headers-server

It is a good idea to always update your kernel. When the headers installation ends, type the following command:

$ sudo invoke-rc.d vboxadd setup

After recompiling, Virtualbox recommends you to reboot. As you know, few operations require a system reboot, and most of them are kernel changings.

Mounting Shared Folders
We can now access it normally by mounting, using the module vboxsf (VirtualBox Shared Folders). To mount it manually, we need to know the Shared Folders' name, which is "Example". I choose "/mnt" as mount point.

$ sudo mount -t vboxsf Example /mnt

After that, you can copy files to and from /mnt folder. All these files will be available to the host system (in my case, Windows Vista System). If you want, with Windows Explorer you can access these files.

You can also configure Linux to automatically mount this directory. As "root" user, edit /etc/rc.local and add the following lines by the end of the file:

if [ -z "$(grep '/media/SwitchFiles' /proc/mounts)" ]; then
/bin/mount -t vboxsf SwitchFiles /media/SwitchFiles
fi

/proc/mounts show all mount points. If "/media/SwitchFiles" is not listed there it will be mounted. Of course, you should create this directory, case it does not exist yet.

My application
Since I have many VMs with Ubuntu Server and Ubuntu Desktop working toghether, frequently I have to install some packages, thus downloading them. With shared folders, I can download once, through any VM and use it in all the others VMs. My "/var/cache/apt/archives" is the mount point of a shared folder in Windows, in "/etc/fstab" in all VMs, as follows:

if [ -z "$(grep '/var/cache/apt/archives' /proc/mounts)" ]; then
/bin/mount -t vboxsf AptArchives /var/cache/apt/archives
fi

Of course, in my Virtualbox console, I have created "AptArchives" shared folder in each VM.

Do not forget to comment and to tell if this was useful or not.

Thursday, November 12, 2009

ODT being read in MS Word

Maybe I am late with this, but ...

Until 2 weeks ago, I could not have my ODT document edited in MS Word 2007. All of a sudden, I open my work with Vista Home Premium (Legal Copy), and I saw my work with MS Word Icon. WOW!!! These last couple of days, Vista has warned several times it needed to restart, because of updates, and things like that. I understand updates, but I don't agree with all that everlastings restartings.

Anyway, I tried to watch the way MS Word understood my book. In past days, OpenOffice tried to understand DOC documents, but several troubles of formatting always were there, for
sarcasm of all: "it is awful, it will never do it, you will loose your work", and on.








MS did a really good job, except for some details:




1) Headings got off the margin:












2) Bullets were not correctly interpreted








3) Background images were not imported. In this image, there is a wall image behind the text "notas importantes", but it was not imported. Notice that, when I wrote this box, I inserted the image in the original ODT file. Also the watermark I defined (a Creative Commons license, converted to JPG) was not imported.




Other features I used in OOWrite worked perfectly. After all, opening ODT files in this updated version of Word was not as complicated as opening old DOCs format in OOWriter, but it was not perfect. Anyway, it is a good step for MS, having in mind interoperactivity.

If you know about more details, let me know. Also, do not forget to comment and to tell if this was useful or not.

Update:
MSWord also does not natively export to PDF documents.

Wednesday, October 7, 2009

Colored man pages

I found a really interesting post about in a brazilian site named DICAS-L, and thought it would be really helpful to have it here, for me or anyone else. Man pages may be read with colored keywords, what helps understanding the (usually complicated) text within.


Pagers
It should be good to first understand the idea behind pagers. They are tools that ease the reading of long texts, as man pages are.

For Unix, probably the oldest pager is more, created by Daniel Halbert, in 1978. With ENTER the text is rolled up line by line, with SPACE we can read the next page, and for search the "/" character is used, as it is in vim. Thus, more became very important for Unix operator.

After, less was created by Mark Nudelman, from 1983 to 1985, offering more resources than more. The names were meant to be a joke, obviously. less allows the use of arrow keys for "navigating" the document, and much more interesting features than it's predecessor.

And finally, John Davis, from MIT, creates most, a pager with more features than the well known less. It is the basis of our article.

MAN pages
I strongly believe that MAN pages are simultaneously the best and the worst Unix documentation source, because (generally) they are written by the software author, but at the same time, not only it does not offers (many) examples, as it mostly make wide use of technical jargon, which can be complicated to newbies. Another good point is that most of man pages are written in English, and usually not localized, or at least as it should.

As said before, man pages are huge, and a pager should be a great help. pager is the default pager, and it is a symlink to some pager, as we can see:
$ whereis pager
pager: /usr/bin/pager
$ file /usr/bin/pager
/usr/bin/pager: symbolic link to `/etc/alternatives/pager'
$ file /etc/alternatives/pager
/etc/alternatives/pager: symbolic link to `/usr/bin/less'
We will replace less by most. What we need to do is to declare it with the environment variable MANPAGER.

Installation
As usual, installing a software is really easy, specially in Debian-based distros:
sudo aptitude install most
Configuration
To manualliy configure most as man pager, type the following:
$ export MANPAGER="/usr/bin/most -s"
But, by finishing your user session, this configuration vanishes. We really need to make it permanent, and we do so making smooth changes to start scripts:

If this pager must be ready only for the current user:
$ echo 'export MANPAGER="/usr/bin/most -s"' >> ~/.bashrc
If this pager must be ready for all users:
$ sudo su -
# echo 'export MANPAGER="/usr/bin/most -s"' >> /etc/profile
# exit
From now on, man pages are all colored. Some tips about most
  • b - bottom of the text
  • t - top of the text
  • / - search for
  • q - quit the text

Of course, we should always try to edit the files above (~/.bashrc or /etc/profile) and add those lines manually, with correct comments, and on. Enjoy it !

Don't forget to let down here what you thought about this article: useful, interesting or unuseful for you ?
Comments are welcome.


Tuesday, September 22, 2009

My old Acer has finally gone ...

After almost 5 years wth me, my Acer laptop (Celeron) has been sold. Since it's arrival, it has mostly worked with Ubuntu in a partition, and Windows XP in another.

After some months, only Ubuntu, and until last month, Ubuntu 9.04. I bought a brand new one (thanks, Lon !!!) from Toshiba. And a friend of us asked me that laptop for his son. I told him to keep Ubuntu, for it is better, safer, and all the stuff we know about it.

- No, because he will have to learn lots of new concepts, and on.

And that is for studying only. After some words, I finally gave up, and had to start reinstalling Windows XP on it. Vista would not work well. My first problem was with drivers, since I didn't have them. Not that difficult, Acer's site is really a breeze. I downloaded almost 10 drivers and started a painful path of OS rebuilding. More than 8 reboots after, I had a fully functional Windows: sound, video and anything useful else. Typical. No Compiz, jelly windows, cube desktop, or many other useful stuffs. Hummm ... I mentioned it was only a Celeron with 1G ?

Office, Avira, hotfixes, all this stuff to be installed AFTER ending OS on Partition. More than 1:30 hours, My future ex-Acer is ready to serve someone else: a teenager ... (brrr).

One week after, all the system was compromised with "some" viruses. Now, after all that problems, he'll give Linux a chance. I'll let you know about it after.

Sunday, May 3, 2009

Speed up your Internet in Ubuntu

Where I live, fast Internet is a dream for most users. So, I need to do something to make my Internet speed increase. We will read here how to make a good use of the advantages offered by a Linux Distro as Ubuntu.

The scenario
I am using a 3G modem. Unfortunately here it does not work as it should, being unstable and slow, most of time. Only 10% of the full contrated speed is guaranteed. It still is expensive, but for mobility, it is what it is. One other detail: I am always in the same sites. A great number the sites, but usually the same.

The solution
A proxy is the best way to make it go faster. According to wikipedia, a proxy is "a server (a computer system or an application program) that acts as a go-between for requests from clients seeking resources from other servers".

Thus, every web access will be requested to the proxy, and it will fetch it in Internet. This web page will remain a little in the system, because if it is requested again, some components will already be downloaded. That means that your browser will show the page faster.

We will see some changes to be made in proxy server, and some others in browser.

The Software
We'll be using Squid, a well-known proxy server, famous, free and widely used. This configuration is not difficult, but requires attention. You should know how to use vim.

Squid installation
As usual, installing a sofware in Ubuntu is a breeze. We will work using CLI, instead of GUI. I recommend you to copy the commands written here and paste them in BASH, to avoid typos.

First, let's assure that Ubuntu has informtion about the most recent packages. Open the CLI, and paste the following lines:
sudo aptitude update
sudo aptitude install squid
Remeber that if you want, you can dispose the whole squid configuration with the following lines:
sudo chattr -i /etc/squid/squid.conf.original
sudo rm
/etc/squid/squid.conf.original
sudo aptitude purge squid
You need vim to be installed. If you are not sure about it, copy this line and paste it on Bash:
sudo aptitude install vim
Squid Configuration

First of all, let's do a backup copy of it's configuration file:
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original
sudo chattr +i /etc/squid/squid.conf.original
Squid Configuration file has lots of comments. They are really helpful, but can be annoying sometimes. So we will "clean" it all:
sudo egrep -v "^$|^ *#" \
/etc/squid/squid.conf.original > /etc/squid/squid.conf
We must know the version of our software. This is how I can identify squid version:
sudo dpkg -p squid

Package: squid
Priority: optional
Section: web
Installed-Size: 1748
Maintainer: Ubuntu Core Developers
Architecture: i386
Version: 2.7.STABLE3-4.1ubuntu1
Replaces: squid-novm
Depends: libc6 (>= 2.4), libcomerr2 (>= 1.01), libdb4.7, libkrb53 (>= 1.6.dfsg.2), libldap-2.4-2 (>= 2.4.7), libpam0g (>= 0.99.7.1), netbase, adduser, logrotate (>= 3.5.4-1), squid-common (>= 2.7.STABLE3-4.1ubuntu1), lsb-base (>= 3.2-14), ssl-cert (>= 1.0-11ubuntu1)
Pre-Depends: debconf (>= 1.2.9) | debconf-2.0
Suggests: squidclient, squid-cgi, logcheck-database, resolvconf (>= 0.40), smbclient, winbind
Conflicts: sarg (<<>
This another way to do te same:
sudo dpkg -l | grep squid
In my system, this was the result:
ii squid 2.7.STABLE3-4.1ubuntu1 Internet object cache (WWW proxy cache)
Note that if your version is different, may ther be some differences.

Finally, let's start with the changes in Squid:
sudo vim /etc/squid/squid.conf -c ":set number"
I did the following changes:
...
35 icp_access deny all
36 http_port 127.0.0.1:3128
37 hierarchy_stoplist cgi-bin ?
...
48 extension_methods REPORT MERGE MKACTIVITY CHECKOUT
49 dns_nameservers 200.169.116.23 200.169.116.22
50 hosts_file /etc/hosts
Line 36 makes my Ubuntu more secure. In line 49 I stated both DNS IPs from my provider. acrescentei a linha 49, com os IPs do DNS do meu provedor. If you don't know about these IPs (they should be given by your ISP), you may see them in your Ubuntu system:
sudo cat /etc/resolv.conf
In my system, I had the following:
nameserver 200.255.121.39
nameserver 200.169.117.14
After these changes, we need to restart squid. So, let's do it:
sudo /etc/init.d/squid reload
To assure it is working, we can search the open ports. Squid uses port 3128:
sudo netstat -ltnp | grep -i squid
In my system:
tcp 0 0 127.0.0.1:3128 0.0.0.0:* OUÇA 3216/(squid)
What is bold in this line, is the same content of line 36 of squid's configuration file.

Browser configuration
The changes in our browser will be much easier. Let's do it in Firefox, which is already present in Ubuntu:






Let's first access Preferences, in edit menu.














After, we need to push Advanced button. In network tab, click on CONFIGURE.
















Do the same changes I did in this screen. Mine is in Brazilian Portuguese, but the fields are in the same place.











It is done. Proxy server installed and configured, and browser configured to talk to proxy server. In my computer, in about 8 days of use, I had the folowing use of HD:
sudo du -sh /var/spool/squid/
32M /var/spool/squid/
You should always control the space used by squid. If it increases too much, you can empty this cache. Type the following:
sudo squid -z
Don't forget to answer our poll, saying if this was useful, interesting or unuseful.