Running Windows 7 natively and in a virtual machine (VirtualBox)

June 19th, 2010

Do you fancy linux, but have to work with Windows once in a while because there is no linux equivalent available?
WINE can not handle the complex program you want to run?
Then you may faceing the same problem as me :)

I got tired of switching back and forth. The better solution is to get VirtualBox to run your Windows OS.
(Note: I didn't get this to work for VMWare.)
Let me expound how:

My current setup:
Host OS: Linux Mint 9 Isadora x64
VM OS: Windows 7 x64
Using Oracle VM VirtualBox 3.2.4 (hey! Sun has been taken over!)

! You're assumed to have installed both your OS'es in dualboot already.
! You best know what you're doing, and know that what you're doing may have fatal consequences which I will not be held responsible for :P
! This is hardly a tutorial. These are the big lines I followed when setting up the box. Getting the required packages etc is your responsibility.
! You will need your Windows 7 CD (altho ISO will do fine too).

First, add yourself to the "disk" and "vboxusers" group. This will allow you to access the other partitions without needing root permissions.
This may be considered dangerous for some reason :) Also logout and back in after doing this. In the examples, I'm the user "cedric".

$ sudo usermod -G disk,vboxusers cedric

Now backup your MBR (Master Boot Record):
(Just run this from your homedirectory or so.)

$ sudo dd if=/dev/sda of=bootrec.mbr bs=512 count=1

Now find out which partitions you have installed Windows on.
Usually you will see a 100MB sized boot partition, and your NTFS partition with Windows 7 on. You need both for the next step!

$ fdisk -l
/dev/sda1 * 1 13 102400 7 HPFS/NTFS
/dev/sda2 13 22557 181082112 7 HPFS/NTFS
/dev/sda3 22557 60802 307200001 5 Extended
/dev/sda5 22557 59334 295409664 83 Linux
/dev/sda6 59334 59595 2099589+ 82 Linux swap / Solaris
/dev/sda7 59596 60801 9687163+ b W95 FAT32

We'll now create a Virtual Machine Disk (VMDK) of the partitions we want to use in the VM.
Sometimes you may also want to add extra partitions to have them shared between Linux & the VM.
In my case, the required partitions are sda1 and sda2. I also choose to add sda7.
Note: It's useless to add linux partitions to the VMDK. Windows can not read them anyway, and you don't want to raise the chance of fucking up Linux as well :)


$ sudo VBoxManage internalcommands createrawvmdk -filename win7.vmdk -rawdisk /dev/sda -partitions 1,2,7 -relative -mbr bootrec.mbr

Now go in VirtualBox and add a new VM for Windows 7 x64. Load win7.vmdk which you created earlier.
In my case I got to deal with permissions problems. Make sure you are the owner of win7.vmdk files and bootrec.mbr.

$ sudo chown cedric:cedric win7* bootrec.mbr
$ sudo chmod 777 win7* bootrec.mbr

If that still doesn't solve the issue, you may have not logged out and logged in again after the first step.
Otherwise, do for all partitions you need:

$ sudo chmod 666 /dev/sda[127]

You may have to repeat this on every boot of the VM.

Now go in the settings for the VM. In the System tab, enable I/O APIC.
When you have done that, it's time to boot up your VM. Startup will most likely fail.
Mount the Windows 7 CD and let it launch startup repair. "Repair installation", not "Install now" :P
The VM may restart and hopefully you will be able to get to your login screen.

Well done!
My congratulations also come directly with a warning. Do not attempt to install the VirtualBox tools. In v3.2.4 they make integration work perfectly in the VM, but when running native your mouse and keyboard will go loco.
There are also drivers available to get your audio working (make sure to select AC97 as your audio driver in the VBox settings), get them here and install them on your VM.

Troubleshooting:

If you can't use the first option after "Repair installation" (screeny), then click the second one "Restore your computer using a system image you've created earlier". An alert will popup, but cancel/ignore/kill it.
Cancel this dialog too, and you will get to a screen that will give you a couple of options (screeny).
Open the command prompt and type
$ bootrec.exe /fixmbr
Hopefully that fixed a couple of things. Reboot.

Kudos:

http://forums.virtualbox.org/viewtopic.php?f=2&t=31759
http://www.rajatarya.com/website/taming-windows-virtualbox-vm

Cross-compiling QT C++ for windows on linux

June 8th, 2010

I've been trying to get cross-compiling to work on my linux box for quite some time now.
Now that it's finally working, I decided it was something that had to be shared :D
I wanted to cross-compile to build nightlies for a new, open-source and cross-platform p2p application :)
To be clear, I'm not trying to write a full tutorial, just some basic guidelines to get you started.

Step 1: Set up a MinGW cross-compile environment

Normally this would take some time, but you can get a script that does it all for you from http://www.mingw.org/wiki/LinuxCrossMinGW.

$ sh x86-mingw32-build.sh
Follow the steps on your screen, this should be straight-forward.
For this guide, I assume you have installed MinGW in /home/user/mingw32/.

Step 2: Compile QT

We have two options here:
- Cross-compile QT on linux: don't. It'll take you too much time. There is a guide that covers this pretty well though on Divided Mind. It's for an older QT version, I didn't get it to work.
- Pre-compile QT on windows: this will take you far less time :) This is what I'll try to cover a bit:
Install the SDK on your windows box (if you have QT Creator installed, you have the SDK already).
For me, QT was installed in C:\Qt\2010.02.1\qt. (Mind the qt subdirectory!) Now copy this whole directory and transfer it to your linux box.
I will assume you have put the contents in /home/user/qtwin/, which should contain an "include" and "lib" directory.

Step 3: Modding QT on linux

You should have QT installed on your linux box as well. Amongst the lines I executed on my debian box were:
$ apt-get build-dep qt4-qmake

I also needed this one:
$ apt-get install libphonon-dev

Now find out where the QT "mkspecs" directory is located on your linux box.
$ find / -type d -name "mkspecs"
This should at least return the directory where APT installed QT, and the directory that you transfered to /home/user/qtwin.
The APT directory was /usr/share/qt4/mkspecs in my case. Changedir to it, now:

$ cp -r win32-g++ win32-x-g++
The win32-g++ directory (and now win32-x-g++ too) contain a file called qmake.conf. It tells QT which tools to use for compiling.
Standard, it uses windows tools (like "xcopy" and "del"). You have to replace the ones in win32-x-g++/qmake.conf with their linux counterpart.
You'll also have to modifiy include and library dirs, and make it use the MinGW tools.
You can find my own modded qmake.conf on pastebin (it isn't perfect, but will give you an idea). This is a very important step, so make sure to get it right :)

Step 4: Compiling your application

Yes, we're here already :)
Changedir to your project directory and execute:
$ qmake -spec win32-x-g++

So generally compile as you do usually but with another -spec flag.
$ make
And, see if it works!

Kudos:

Links that helped me a lot:
http://silmor.de/39
http://divided-mind.blogspot.com/2007/09/cross-compiling-qt4win-on-linux.html

Setting up SSH (or SCP/SFTP) to remember your password

January 21st, 2010

If you are tired of inputting your password each time for a SSH or SCP connection or if you're setting up a cronjob to transfer files, this will guide you through the process:

The LOCAL machine is the machine that inits the connection for SSH / SCP.
The REMOTE machine is the machine that accepts the connection.

The following command generates a private and a public key. The private key is for your eyes only,
the public key goes to the remote machine.

LOCAL $ ssh-keygen -t rsa -N ""

Now execute:

LOCAL $ scp ~/.ssh/id_rsa.pub USER@REMOTE:.ssh/

This will copy the public key to the relative .ssh/ dir in your remote user's homedir.
(And ofcourse you have to substitute the needed fields.)

Now login to you remote server with SSH. I assume you can handle this step yourself.
Then execute:

REMOTE $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

That will add the id_rsa.pub file to the authorized keys-file on the remote machine.
You can safely remove the id_rsa.pub file now if you wish

REMOTE $ rm ~/.ssh/id_rsa.pub

TROUBLESHOOTING

Well, in fact, it's not always that easy. If you've completed these steps, and the remote server still keeps asking for a password, you might want to pay attention to the following:

In some cases (and it must've been annoying me for at least two hours now,) people forget to chmod the authorized_keys file or .ssh directory.
That can be easily fixed with this command:

REMOTE $ chmod -R 700 ~/.ssh

In my case, my homedir was chmodded to 707 (weird uh..). However, the SSH server didn't seem to like that and therefor I changed it back to 755.

REMOTE $ chmod 755 ~

Depending on your SSH version (or if compatibility mode is not enabled in the SSH server settings), you might have to use authorized_keys2 instead of authorized_keys. Newer SSH-server versions will look in both of these files, I've been told.

My last remarks: if you're trying to login as root, you have to explicitly enable this in the SSH server on the remote machine. Open etc/ssh/sshd_config and change PermitRootLogin to yes. Some users using empty passwords will also have to set PermitEmptyPasswords to yes.

Mobile Vikings tetheren naar laptop

December 24th, 2009

Ik ben jarenlang trouwe klant geweest bij Proximus: ik kocht elke maand braaf een herlaadkaart van 15 euro om mijn bonus van 1000 gratis sms'en te blijven behouden, die je kreeg bij het Generation tariefplan. Ik ben echter dat type klant die net iets meer verwacht van zijn operator: mobile internet om te beginnen en een API o.i.d. :)
Voor mobile internet betaal je je helaas blauw bij Proximus. Over een API was nergens iets terug te vinden, en hun klantendienst was enkel bereikbaar via telefoon. Op heel het internet heb ik geen enkel e-mailadres teruggevonden van Proximus.

Dat (en nog enkele kleine ergernissen) dwongen me om over te schakelen naar een andere operator (hoewel ik verder tevreden was van Proximus).
Zodoende ben ik nu lid van Mobile Vikings, een nieuwe gsm operator in België. Zij benutten het netwerk van Base om hun diensten aan te bieden. Ze zijn een MVNO ofwel Mobile Virtual Network Operator.

Voor elke 15 euro die je herlaadt bij Mobile Vikings krijg je maar liefst 1000 SMS'en en 1 GB datavolume!
Er zijn geen abonnementskosten, en je kan je kaart herladen via PayPal / overschrijving / Ogone.
Als je je huidig nummer wil behouden, ontvang je je nieuwe SIM-kaart zelfs gratis :)
Verder zijn ze ook druk bezig met hun API (waarvoor enkele sympathisanten al wat apps hebben gemaakt). Dat is voor mij een groot pluspunt.

Vanaf m'n nieuwe SIM-kaart ontvangen, geactiveerd en opgeladen was, ging ik the beauty booty dan ook meteen eens uitproberen!
Ik moest eerst m'n gsm nog instellen (access point name e.d.) maar nadat die klus geklaard was kon ik meteen op internet.

In eerste plaats was ik echter overgeschakeld om de internetverbinding te kunnen tetheren naar mijn laptop. (Daarmee kan je dus surfen in de auto, op de trein, overal.)

Tethering in draadloze communicatie is de mogelijkheid om een apparaat zonder internetverbinding (zoals desktop, notebook of laptop) aan te sluiten op een mobiel apparaat (zoals gsm of PDA) met mobiel internet om zo toegang tot internet te verschaffen aan het apparaat zonder internetverbinding. (Wikipedia)

Toen ik een nieuwe bluetooth adapter instelde op m'n laptop, wou die helaas niet direct werken... dus hoe loste ik dat op? :)
Vanaf hier ga ik ervan uit dat je internet werkend gekregen op je gsm (in mijn geval een Nokia 3120 classic), indien dat niet het geval is, zijn daar tutorials voor te vinden op de site van Mobile Vikings zelf ;)

Welnu, er is altijd te mogelijk om aan de slag te gaan met software bloat zoals de Nokia PC Suite, maar hier doe ik het even op de propere manier:
Als je gsm via bluetooth verbonden is met de computer en de bluetooth modem bij je Netwerken/Adapters staat, kun je normaal gesproken op die manier verbinden met internet. Helaas is dat in de realiteit niet zo. Wanneer ik probeer te verbinden krijg ik fout 777 naar mijn hoofd gesmeten: "De verbindspoging is mislukt omdat de modem (of een ander verbindgsapparaat) op de externe computer niet werkt."

Dit valt gelukkig heel makkelijk op te lossen! Vul voor zowel de gebruikersnaam als het wachtwoord "web" in. Bij het telefoonnummer zet je dan *99***1#. Tadaam :) That works like a charm! De 1 in de code staat voor de standaardinstellingen op je gsm waarmee hij probeert te verbinden (als je met je gsm op internet kan, moet dit dus ook werken). Verder zou ook de code *99# moeten werken indien je een data kabel (usbkabel) gebruikt om je gsm aan te koppelen op je pc.

Toen dat allemaal achter de rug was, ging ik even naar speedtest.net uit nieuwsgierigheid naar de downloadsnelheid.
Geklokt op 25KB/s viel dat al bij al goed mee voor mobile internet! MV heeft momenteel slechts een Edge netwerk, maar de upgrade naar 3G in januari komt dichterbij, en de hogere snelheden dus ook :)