Compacting (reducing maximum size of) VDI files for VirtualBox

One might pick a large maximum dynamic disk size for a VirtualBox guest OS, not realizing that even if one uses a small portion of that maximum size, the guest OS (especially Windows) will spread itself out, so that say a 10GB Windows XP NTFS image will consume say 30+GB of your host OS (assuming you set the maximum dynamic size >30GB).

Here’s a fairly painless procedure to fix this. Should take less than 1 hour on a modern PC. I assume your guest OS is Windows XP, and your host OS is Linux running VirtualBox 4.2.4.

BACKUP YOUR VDI FILE BEFORE DOING THIS PROCEDURE!

  1. in guest Windows XP, run Disk Defragmenter
  2. in guest Windows XP, in Command Prompt, run
    sdelete -z c:\ which can be downloaded fromĀ http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
  3. shutdown guest Windows XP, and “insert” the Gparted ISO file (obtained from http://gparted.sourceforge.net/ ). You do this by right-clicking the CD icon at the bottom of the guest OS VirtualBox window and selecting your ISO file.
  4. Resize your guest Windows XP partition so that you have only say 8GB free (e.g. original partition 40GB, only 10GB used–>resize to 18GB)
  5. reboot guest Windows XP, removing the Gparted ISO file from VirtualBox. you will see Windows XP automatically runs CheckDisk–this is normal. You will need to reboot guest Windows XP once more, then shutdown guest Windows XP
  6. in host Linux, in Terminal type cd ~/VirtualBox*/WinXP (or wherever your .VDI file is located. Then type in Terminal vboxmanage modifyhd --compact MyFile.vdi where MyFile.vdi is the name of your VDI file.
  7. Now you’ll see in Linux that the size of your VDI file has dropped a lot! Nice!

 

Note: for future reference, when you Defragment in guest Windows XP, this actually makes your host VDI file INCREASE in size by the amount of bytes that were moved to defragment!

To fix this, repeat steps 1,2, and 6 of the procedure above when you find your VDI has grown to an annoying size.

The take-away point is, do not make large maximum size Dynamic VDIs to start–this problem will only repeat itself over time.

Install Matlab Student R2012a (32-bit) in Ubuntu 12.10 (64-bit)

Note: if you have 64-bit Student Matlab (i.e. Matlab Student R2013a and higher), then you skip step 2.

Note: This procedure (step 2) is now obsolete for 32-bit Matlab as ia32-libs is no longer available.

Preliminary Checks:

  1. type ifconfig | grep eth0 and be sure you have an ethernet card listed–if not, you may need to consider renaming your ethernet card as in
    this link
  2. Get ia32-libs
    sudo apt-get install ia32-libs
  3. if you haven’t already downloaded your files, here’s how to run the “download agent” to get the matlab download
    javaws download_agent. This is an optional step.
  4. navigate to the mathworks files you downloaded, and cd ~/mathworks_downloads/R2012a*
  5. set executable permissions: chmod +x install
  6. set java executable permissions: chmod +x sys/java/jre/gln*/jre/bin/java
  7. finally, navigate to your ~/mathworks_downloads/R2012a_Student_Version
    and type:
    sudo ./install
  8. Be sure to use Custom, and to Install Symbolic Linux
  9. When starting Matlab, you will need to use matlab -glnx86 -desktop
  10. to put links to Matlab in your menus, etc. consider the procedure at: http://blogs.bu.edu/mhirsch/2012/12/ubuntu-fixing-desktop-icons-and-menu-items-for-matlab/

using FITSIO in Octave under Cygwin

Cygwin installs the minimal amount of packages necessary, so to do work with many programs, you must install the prerequisities. This is especially true when trying to read FITS files in Octave using the Octave-FITS package, which depends upon the CFITSIO library.

Here are the prerequisities you’ll need (get them using the Cygwin Setup.exe program)
make pkg-config gcc-g++ libgfortran3 libGraphicsMagick3
octave octave-devel octave-forge

Now, you’ll need to download the CFITSIO source code from http://heasarc.gsfc.nasa.gov/fitsio/ (get the “Unix .tar file”)
–copy this file to your Cygwin home directory (e.g. if your username is “joe”, then c:\cygwin\home\joe)

In cygwin, type tar -xvf cfitsio*.tar.gz

Type cd cfitsio
Type ./configure --prefix=/usr/local --enable-reentrant --enable-ssse3
type make && make install

Now you must tell pkg-config where your libraries are by typing
export PKG_CONFIG_PATH=c:\\cygwin\\usr\\local\\lib\\pkgconfig

Now, be sure you’ve downloaded the latest octave-fits package from Octave Forge, and put them in your cygwin home directory (e.g. c:\cygwin\home\joe if your username is joe)

Now in Cygwin type cd ~
and then
octave
and then
pkg install fits-1*.tar.gz
(you must change to your ~ directory or pkg install will fail!)
This should install FITS without errors. Type pkg load fits to enable the FITS functionality. Note, the command is NOT fitsread(), in octave the command is read_fits_image().

POSSIBLE CONFIGURATION CHANGES NEEDED:

  • If you get an error message upon ./configure that gcc/g++ can’t be found, in Windows go into Control Panel>System>Environment Variables and Delete variable named “CC”. Keep a record of what it was in case you need to put it back! Then reboot

Octave/MATLAB ‘bug’ with fileread()

Working with ASCII text files from various operating systems, you might encounter a case where Octave or MATLAB using fileread() reads an ASCII file with one character per line.

E.g. an input file in.txt containing:
Joe 100 eggs

and executing: data = fileread(‘in.txt’)

gives:
J
o
e

1
0
0

e
g
g
s

To workaround this problem, try doing:

data = fileread('in.txt');
data = data(:)';