Pixelastic

You can cut our wings but we will always remember what it was like to fly.

Posts tagged with "ubuntu"

Increasing VirtualBox hard drive size

While trying to import a huge (1.7Go) mysql dump file into my VM I was blocked by mysql telling me that not enough space was left on the device to complete the operation.

As I was running a VM, I thought it would be a simple matter of increasing the virtual hard drive size.

Turns out it wasn't that simple. After much trial and error, here is how I finally did it.

Creating a new hard drive

VirtualBox let you easily add new devices, such as hard drives to your VM. I simply created an empty 120Go hard drive and booted my VM.

Here, under Ubuntu, I cloned my current hard drive to the new one using :

sudo dd if=/dev/sda of=/dev/sdb

Fixing the guest partition

Once finished, I opened Gparted, selected /dev/sdb and saw that I had 112Go unallocated. I couldn't easily add them to the initial partition as a swap partition was in the way.

I finally decided to remove the swap partition and resize the initial one to the (almost) complete size of the hard drive.

I left 1Go free in case I ever needed to create a new swap partition later to fix the one I deleted.

Then, I closed the VM. Get back to VirtualBox panel and remove the original drive, keeping only the new 120Go one.

One reboot later, my Ubuntu was proudly displaying its 120Go.

Working on Wednesday #11 : First steps with my Dreamplug

A while back, I ordered a Dreamplug. It's a micro computer more or less the size of a hard drive. It uses very little electricity, has ethernet, usb, sata and sd ports as well as bluetooth and wifi connectivity.

I wanted one to primarily work as a git and mercurial server to host my repos, as well as host a few websites I might be working on. As it's not the more powerful of device and will be using my home ADSL connection, it's also a good fit for testing web performance optimisations.

Actually, I have a lot of ideas for this plug (ssh tunnel, dropox-like server, etc).

First, let's establish a connection

To do any of that, you first have to log into your device. This first step might have been the one that caused me the much trouble.

I simply wanted to connect to the plug through SSH. I didn't want to plug it to my router because it would then have emit an open wifi network. Instead, I wanted to access it through a simple ethernet cable.

To do that I had to plug the Ethernet cable on the second slot (the one the closer to the lights) on the plug, then turn it on. I didn't manage to connect with the cable in the other plug nor if I plugged it after turning the device on.

What took me a while to figure is that the Dreamplug have its own ip address : 10.0.0.1. To enable transfer between your host and the plug, you have to set a fixed ip address to your ethernet (mine was eth0)

$ sudo ifconfig eth0 10.0.0.2 

I chose 10.0.0.2 because it's close to the Dreamplug address and I will remember it better, but you can actually choose anything you want, it absolutely does not matter.

Connect through ssh

Once the first step is done, you are now able to connect to the device through SSH.

$ ssh root@10.0.0.1

The default password is nosoup4u. I chose to keep it for now, as I'll have to type it a lot, but I'll change it once everything is installed.

First thing you should do is create a new user. Using root for the day to day activities is a bad habit.

$ adduser pixelastic 

You'll be prompted for password and other misc informations. Once done, we will give sudo power to this user.

On others Ubuntu machines, I usually do a adduser pixelastic admin or adduser pixelastic sudo, but this didn't work here. There wasn't even an admin group, and adding to sudo didn't seem to change anything.

Instead, I had to edit the /etc/sudoers file, using visudo.

If you've never used vi before, press i to enter edit mode, and vi will acts as a common editor. Press Esc when you've finished, then :x to save and exit

I added a new line just below the one starting with root and copied it, simply by changing the user name.

root    ALL=(ALL) ALL
pixelastic ALL=(ALL) ALL

Your new user should now have the sudo powers.

Unfortunatly, on my build one more thing was missing. It might not be the case on your plug, but we'd better check.

$ which sudo
/usr/bin/sudo
$ ls -l /usr/bin/sudo
-rwxr-xr-x 1 root root 114976 2011-02-14 08:08 /usr/bin/sudo

Check the permissions, if you have this output, then something is wrong. The sudo executable should have the s permissions, otherwise it won't work.

$ chmod u+s /usr/bin/sudo

Now, we can logout from the root session, and login back with our new user

$ ssh pixelastic@10.0.0.1
$ sudo pwd
/home/pixelastic

What next ?

Now, one last sensible thing to do is to change the root password for something stronger, and even disable login as root through ssh. To do that, simply edit the /etc/ssh/sshd_config file and set PermitRootLogin to no.

You could also add your keys to the plug to avoid typing your password, install your softs, and link the plug to your router to make it accessible from the outside.

I plan to replace Ubuntu for Debian on my Dreamplug, I'll post about that later.

Working on Wednesday #3 : The long path to get it done

This morning I started reading a lot of online blog post, framework description and other webdev material online I had in my bookmarks. After reading them, I saved them on my pinboard account to find them easily later.

Lot of good JS and CSS framework/libraries in there, I hope to be able to test them soon.

I also check my mailbox and respond to mails from my normal job. I shouldn't. I'm on a day off, I have to force myself to completly cut out those external calls.

Now, let's the work begin

Anyway, I finally finished the vimtutor. I still have a some difficulties to remember the mapping of the basic hjkl movement keys (I always want use k to move down instead of j). However, I feel confident enough in it to try writing my new code in it.

So, I headed to the Rails for Zombies tutorial. I thought it was free but the "win $5 worth of online teaching" / "next course costs $5" make me doubt it a little. Well, we'll see.

After registering to it, I wanted to save my login and password to KeePass as I always do.

Unfortunatly, KeePass on my Ubuntu machine works by using mono, and the keyboard interaction weren't that good (caret is slightly misplaced, inputs lags before getting displayed, text selection is weird). So I thought "Hey, let's see if there is a new version". Big mistake.

It appears that there was indeed a new version, a real one, with apt-get and stuff while mine was some hackish install I manually made a few month ago.

But wait, this means manually adding a ppa directory. No big deal, I trust the author. What ? Still doesn't work ? Hmm, I see. I need mono 2.6, and I only have 2.4.

What ? 2.4 is the latest available version on Ubuntu 10.10 ? You mean I must upgrade to 11.04 ? Hmm. Why not. I'll have to do it eventually, so let's go.

So I ran all my updates, to have the most up to date system. Unfortunatly, language-pack-gnome-fr doesn't want to upgrade so the OS upgrade isn't displayed.

Wait, what am I doing ?

And that's when I remember that my initial wish was to learn Ruby on Rails and that I was now on the road to upgrading my whole operating system. That is not exactly speaking procrastination, but it makes me do so much other things that my initial goal that I really looks like it.

I finally managed to purge my packets, upgrade to 10.10 and then to 11.04. But this took me 4 hours, and now it's 11PM and I guess I won't start this rails tutorial today, after all.

Installing Ubuntu in VirtualBox to work as a development server

I was tired of trying to install Lighttpd on Windows (hint : don't try, it's a mess. I found no way to get vhosts and php as cgi at the same time). So I finally decided that Linux was the way to go.

I have always developped using Windows, and even if I'm slowly migrating to Ubuntu at home, I'm still using Windows 7 at work. The solution that best fits me was still using my Windows environment for coding, but using Ubuntu inside a VM to act as a server.

Let's see how I did that :

Required components

First, let's clarify what I'll have to install for this project : Lighttpd as the webserver, mysql and memcached for storing data and php5 to run cakePHP.

Step One : Running Ubuntu inside a VM

Start by downloading the Ubuntu iso (i's 687Mo, you'd better start this download first). I personnaly used the 10.04 Desktop version (I tried the 10.10 Server version first but I feel more confident with a UI).

Then, download the latest VirtualBox version (4.0.4 at the time of this writing).

And mount the iso in VirtualBox and start the install. This is pretty easy and you should be done in 10mn. Once the install is finished, you'll be prompted to reboot. Do not reboot just now. Instead, shutdown your guest machine (you can type sudo halt if the GUI does not work).

Once back in Windows, go to your VM config and unmount the install iso, otherwise the install procedure will be started again everytime you load your VM.

Once it's done, you can reboot the gues and once loaded, select the in VirtualBox Menu => Devices => Install guest additions. The next popup can take some long minutes to show, so be patient. This will install the guest additions that will allow you to easily communicate between the guest and host machines.

Once installed, reboot once more, and you should have the guest addition image sitting on your desktop.

Start a terminal and install the guest additions by doing :

cd /media/{name of your VBOX image}
./autorun.sh

This will finish the guest addition installation. Reboot your guest machine one last time and you'll be ready for step 2.

Step 2 : Installing the server stuff

We will now install the various components we'll need. You could probably install them all with one command but I'll split them in different line so you'll correctly see what's installed.

First, lighttpd :

sudo apt-get install lighttpd

Now, memcached

sudo apt-get install memcached

And mysql server. This one will prompt you to enter the root password you'll want.

sudo apt-get install mysql-server

Now we will install php5 as CGI (Lighty will run php as cgi), as well as the needed dependency so php can connect to both mysql and memcache.

sudo apt-get install php5-cgi php5-memcache php5-mysql

Ok, you should now have everything correctly installed. We will configure all that stuff later. You should now completely close your Virtual Machine and get back to Windows. It's time to configure your host and guest so they can correctly communicate

Step 3 : Enabling communication between host and guest

What we will do in this section is configure your network so the guest machine is considered part of your network and so you can connect to id using SSH and classic http.

First, go back to your VM config and change the Network mode to "Bridged". This will allow both machine to see each other in your network easily.

Then, define the Shared folder you want shared from your host in your guest. I shared my websites directories so Lighty could access them from the guest.

Now, start your VM, and type sudo ifconfig in a terminal. You should see your guest machine ip. Mine was 192.168.1.16.

Knowing that IP, you can define hosts in your Windows C:\Windows\System32\drivers\etc\hosts

You should also install openssh server so that you'll be able to connect to your guest machine using ssh :

sudo apt-get install openssh-server

We will now take care of the shared folder defined earlier. Selecting them in VirtualBox only made them available for mounting in the guest, but you'll now have to type some more commands to effectively see them. I needed to have access to a project I coded in my host (let's name it myproject).

Here's how I made it available to Lighty :

sudo mkdir /var/www/myproject
sudo mount -t vboxsf -o rw,uid=$(id -u),gid=$(id -g www-data) myproject /var/www/myproject

This will create a directory in /var/www to hold the project, and will then mount the shared folder to that directory. The uid/gid stuff indicate that you (the current user) is the owner and www-data is the group. Doing so will fix access rights issues you may have with Lighty.

You should have to re-run the last command on every login, so I strongly suggest you to put it in /etc/rc.local so it gets executed automatically.

Step 4 : Configuring all that stuff

I won't go into much details on how to configure lighty or php because it is not the scope of this post. I might post on that subject later, though. But here is one important step you shouldn't forget : uncomment the cgi.fix_pathinfo=1 line in your php.ini.

Don't forget to reload Lighty after changes to its config files by running:

sudo /etc/init.d/lightppd restart

I also had one additional side-effect on my install : installing php5 also installed Apache, causing Lighty to fail on startup because Apache was already using the port 80. I fixed it by removing every reference to Apache by running :

sudo update-rc.d -f apache2 remove

Final note :

If you followed this instruction, you should have a server running inside a VM that runs your website stored in your host. Isn't that pretty ?

Migrating from Windows to Ubuntu : KeePass

I'm slowly trying to move my development machine from a desktop Windows Xp to a laptop running Ubuntu. This is quite a long task because there are so much softwares I depend on on my day to day work. Most of them are crossplatform but I often need o find a Ubuntu equivalent, and sometimes it does not exists and I have to run the Windows app using an emulator.

This is exactly the case with KeePass. KeePass 2.0 is an improved version of KeePass 1.0 (obviously), that allows one to save all password in one place. The 2.0 version also permit to save more than single password, virtually anything, and adding little icons to each entry (when you start having 200+ entries, icons are a must have).

Enter Ubuntu world

The official 2.0 version is not supported under linux. There is a linux port, named KeePassX, but it does not support the .kdbx file format used by the official 2.0 version.

So I tried to run the Windows .exe file with Wine at first (I already had Wine installed to run another app), but it wasn't working with KeePass. I tried instead an other emulator, Mono, and running mono KeePass.exe totally worked.

Little tweaks ahead

First of all, I had to install two additionnal packages to make it open without errors : System.Windows.Forms and System.Runtime. So far, so good.

But, I quickly discovered that one of the most usefull features of KeePass, auto-type (Ctrl+V automatically fills a login/password field) wasn't working correctly. There was one more missing dependency : xdotool.

If you are running Ubuntu like me, do not install it from the official packages, this version is completly outdated and won't work. Instead, you have to manually install the latest version. If you are lucky and running a 64bits system, you can download directly the .deb file from here.

If you are running under a 32bits system like me, you'll have to manually install it. First grab the files from this link. Then, install the libxtst-dev package (it is needed for the install to complete), export the content of the .tar.gz file into a temporary directory and execute sudo make install.

Finally !

Now, you got KeePass 2.0 working under Ubuntu, and installed all dependencies needed to run the auto-type feature.

In a Windows environment, one can change KeePass preferences so that closing it only send it to the tray bar.This option does not seem to be working under Linux, KeePass still shows in the task bar even when minimized. I spent some time trying to fix that too, tetsing AllTray and other tray softs for linux but didn't managed to get what I wanted.