Archive for August, 2010

VirtualBox Setting Screen Resolution

VBoxManage setextradata “CustomVideoMode1” “
where screen-resolution = 1440x900x32 or 1280x1024x16 for example

No Comments

Mounting Shared Drives in VirtualBox

mount -t vboxsf <share> <mount_point>

where  <share> is the name of the share (not the original drive or directory)

and where  <mount_point> is the linux /mnt directory (point)

,

No Comments

Increase Size of Hard Disk in VirtualBox

I quite like VirtualBox, originally from Sun, now Oracle – probably because it is free!  But seriously, it isn’t a bad little system and desperately needed for desktop use if nothing else (I truly welcome the day when every PC comes pre-installed with a standards-based virtual machine and the operating system is installed inside that virtual machine – allowing one to (a) install other operating systems to execute concurrently very easily, and (b) to move a nicely setup environment from one PC to another without the enormous hassle of re-installing and re-configuring everything all over again.  Anyway, back to the story at hand).

I very easily created a Ubuntu 9.04 virtual machine, and like many other people, I set the virtual hard disk size too small, as I found out in the end.  I set it to 8Gb, thinking that for “test” purposes that would be fine.  As is always the case, I loaded software after software package, et voila, the 8Gb is almost completely gone, to the stage that ubuntu starts complaining about not enough disk space to do things or upgrade to 10.04.

So, I dive into the world of trying to increase the size of a virtual hard disk in VirtualBox.

Firstly, the VirtualBox documentation does say that you can not do it.

The documentation also has references to other possible solutions, such as VBoxManage clonehd etc etc – all of which appear to be red herrings.

Searching across forums etc reveals the following basic pattern:

  1. Create a new empty virtual hard disk of the required (new larger) size, using the VirtualBox Virtual Media Manager (under the File menu of the main VirtualBox program).  This can be a dynamically expanding or fixed size disk;
  2. Attach this new disk to the existing virtual machine image, as a secondary disk.  For ubuntu purposes, the original diskj should generally be /dev/sda and the newly attached disk should be /dev/sdb, assuming that you only originally had a single disk in your setup and only attached this new disk as the next disk;
  3. Restart the virtual machine and copy everything from the old disk to the new disk using the command: dd if=/dev/sda of=/dev/sdb  Note that you must copy the whole disk, since the boot sectors etc must be copied across.  I did try to just copy the main os partition (ie /dev/sda1 to /dev/sdb1 but because the boot information was obviously not copied, when I came to reboot using the new disk it failed (obviously);
  4. Run ‘gparted’ (may need to install on the ubuntu system).  The new disk should be ‘sdb’.  You will see that it has a partition with the old disk on it, but also partitions for the boot sectors and for the linux swap and unallocated space.  The idea is to allocate the unallocated space to the end of the partition with the old disk in it, but in my attempts, gparted would not allow me to do so, since the linux-swap partition was in the way and could not be moved to the end or another position.  The old disk partition could also not be unmounted or mounted, since I think it was mounting to ‘/’, which was already used by ‘sda’.
  5. This then was the end of the road for me.  I decided that it would be more effective to install a new ubuntu in a new larger virtual hard disk (since I had already downloaded the new version of ubuntu) and jsut re-install whatever packages I had installed in the old disk.
  6. Obviously this would not be effective if the old disk contained systems and data of importance, rather than just test packages etc.  In this case, it is a relatively simply matter to attach the old virtual hard disk as a secondary disk to the new machine, then mount that disk from /dev/sdb and copy across (or re-use) whatever one needed.

, , ,

No Comments

Environment Variables in Windows (Vista, XP)

See http://www.vistaonwindows.com/environment_variables.php

Sometimes it is desirable to edit certain of the environment variables such as %PATH%. Or it may be useful to create a user-defined environment variable. Vista contains a command-line method SETX that provides a variety of options. It can be used to either create or modify environment variables. Variables can be in the user or the system environment. The command has a number of switches that make it useful in scripts. (Needs administrator privileges.)

Environment variables can also be edited directly in the Registry. They are stored in the same Registry keys as they are in Windows XP. System variables are in the key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
User-specific variables are in
HKEY_CURRENT_USER\Environment

SETX

SetX has three ways of working:

Syntax 1:

  SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]

Syntax 2:

  SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]

Syntax 3:

  SETX [/S system [/U [domain\]user [/P [password]]]]
       /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]

Description:

  Creates or modifies environment variables in the user or system
  environment. Can set variables based on arguments, regkeys or
  file input.

Parameter List:

  /S     system          Specifies the remote system to connect to.
  /U     [domain\]user   Specifies the user context under which
                         the command should execute.
  /P     [password]      Specifies the password for the given
                         user context. Prompts for input if omitted.
  var                    Specifies the environment variable to set.
  value                  Specifies a value to be assigned to the
                         environment variable.
  /K     regpath         Specifies that the variable is set based
                         on information from a registry key.
                         Path should be specified in the format of
                         hive\key\...\value. For example,
                         HKEY_LOCAL_MACHINE\System\CurrentControlSet\
                         Control\TimeZoneInformation\StandardName.
  /F     file            Specifies the filename of the text file
                         to use.
  /A     x,y             Specifies absolute file coordinates
                         (line X, item Y) as parameters to search
                         within the file.
  /R     x,y string      Specifies relative file coordinates with
                         respect to "string" as the search parameters.
  /M                     Specifies that the variable should be set in
                         the system wide (HKEY_LOCAL_MACHINE)
                         environment. The default is to set the
                         variable under the HKEY_CURRENT_USER
                         environment.
  /X                     Displays file contents with x,y coordinates.
  /D     delimiters      Specifies additional delimiters such as ","
                         or "\". The built-in delimiters are space,
                         tab, carriage return, and linefeed. Any
                         ASCII character can be used as an additional
                         delimiter. The maximum number of delimiters,
                         including the built-in delimiters, is 15.
  /?                     Displays this help message.

NOTE: 1) SETX writes variables to the master environment in the registry.

    2) On a local system, variables created or modified by this tool
       will be available in future command windows but not in the
       current CMD.exe command window.
    3) On a remote system, variables created or modified by this tool
       will be available at the next logon session.
    4) The valid Registry Key data types are REG_DWORD, REG_EXPAND_SZ,
       REG_SZ, REG_MULTI_SZ.
    5) Supported hives:  HKEY_LOCAL_MACHINE (HKLM),
       HKEY_CURRENT_USER (HKCU).
    6) Delimiters are case sensitive.
    7) REG_DWORD values are extracted from the registry in decimal
       format.

Examples:

  SETX MACHINE COMPAQ
  SETX MACHINE "COMPAQ COMPUTER" /M
  SETX MYPATH "%PATH%"
  SETX MYPATH ~PATH~
  SETX /S system /U user /P password  MACHINE COMPAQ
  SETX /S system /U user /P password MYPATH ^%PATH^%
  SETX TZONE /K HKEY_LOCAL_MACHINE\System\CurrentControlSet\
       Control\TimeZoneInformation\StandardName
  SETX BUILD /K "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
       NT\CurrentVersion\CurrentBuildNumber" /M
  SETX /S system /U user /P password TZONE /K HKEY_LOCAL_MACHINE\
       System\CurrentControlSet\Control\TimeZoneInformation\
       StandardName
  SETX /S system /U user /P password  BUILD /K
       "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\
       CurrentVersion\CurrentBuildNumber" /M
  SETX /F ipconfig.out /X
  SETX IPADDR /F ipconfig.out /A 5,11
  SETX OCTET1 /F ipconfig.out /A 5,3 /D "#$*."
  SETX IPGATEWAY /F ipconfig.out /R 0,7 Gateway
  SETX /S system /U user /P password  /F c:\ipconfig.out /X

No Comments

ecoder – online programming editor

I have been looking around for a reasonable online (ie available over the internet from any location) editor for programming purposes.  There appears to be a dearth of available offerings (as at August 2010), and there certainly does not seem to be any online Interactive Development Environment (IDE) products out there (and by making this statement, I am hoping that people will disabuse me of this notion and apprise me of numerous excellent offerings!).

One of the online programming editor products I found was “ecoder” (http://ecoder.gmeditor.com/) – the “demo” site made it look OK – simple yet effective.  So, I downloaded it and had a try.

It is a PHP and Javascript play.  Download the zip file to a directory on your server, unzip it and follow the installation instructions.

I made the changes to code.php in the root directory as instructed:

  1. Created a directory to store my documents in – outside the www directory of the server (probably a good security idea to do so, based on experiences with other such products) and indicated that directory in the $code[‘root’] variable
  2. Changed $code[‘domain_cookie’] to my domain name (ie without the www. in front of it)
  3. Set $code[‘name’] to my own ecoder title name – even though the instructions indicated that this variable currently did not really do anything – what the heck, might as well
  4. Did not do anything with the security settings.  I could not figure out exactly what was required with respect to these security instructions.  After posting something on the forum for ecoder (in sourceforge.net) re security, the answer virtually reflected the instructions – set up your own security script, call that immediately when going to the ecoder main page (index.php), then if the operator has logged in correctly, go back to ecoder with a variable set indicating it has passed security.  What variable (name, etc)?  Does the security module have to be in PHP?  Where to put the code (in index.php or code.php)?  Having no idea of the structure of the ecoder application and not being a PHP guru (and not having a security module lying around), I decided to ignore these security instructions for the moment.
  5. I wanted to be able to edit Python and Java programs, so I modified the $_SESSION[‘tree_file_types’] variable to include py and java extensions
  6. I then set the error log path to be a directory under my repo directory (why not?) and set my error email address properly.

Now, by simply going to the address of the website folder I had loaded ecoder into, believe it or not, it actually worked.  The editor came up and I could see the home page with the dummy text in it – and I could edit it.  Well done to the author of ecoder – not too shabby in terms of getting something running in less than half an hour.

So, onto doing something with the product.

I uploaded a python program I had written.  Upload seemed to go OK.  The program made it into the left hand file listing panel – BUT, there was no way that I could edit the file I had just uploaded.  Repeated clicking on it did nothing (it’s amazing isn’t it, that when something won’t work, you keep clicking and clicking on the same area, in the hope that by the hundredth click, something miraculous might happen and it will suddenly work when it had not worked for the last 99 attempts.  I am sure that it has happened for someone in the past, but never for me – yet I keep repeating the same monkey behaviour every time).

So, upload had some problems.  I then tried to create a new program with the py extension from scratch.  Clicking “new file” gave me the dialog box to enter the filename and the drop down list with all the right extensions in it – with “py” at the top (just as I had specified in the code.php program).  Except, that when I sent to save the new file, an error occurred – the type of file was not allowed, the extension was wrong.

Next I managed to create a file with the txt extension (a plain text file) and edit it.  All OK.

Which bought me back to thinking about security.  I still couldn’t be bothered with the instructions in the code, so I went for the raw basic .htaccess and .htpassws solution.  Real basic stuff, but enough to work OK (provided I loaded the variables for Auth in .htaccess properly – made a mistake in the URL referencing the .htpasswd file and got errors – but managed to fix that relatively quickly) and got myself some raw security over the site.  Maybe one day I will go and create a nice login script – maybe a generic one for any system I have.  I am sure someone has written something out there for that as well.

But then, back to the Python editing.  Tried the py extension again (remember – Monkey see, Monkey click).  Still no luck.

Not to be defeated, I thought I would look through the code (I know PHP well enough to be able to read what was going on).  Took a little longer than I expected.

I eventually found that in “code/save/add.php” line 50, the system checks that there is a file which exists called “template.ext” where “template” is the actual string “template” and “ext” is the extension of the file to be created. Thus creating such a template file allows the file to now be created. It places the newly created file in the tree display on the left, but it now can not be selected and edited.

Uh – the whole structure of the thing now not looking so good – in that there seem to be dependencies all over the place in terms of simply specifying that one wants to edit with a different extension to a file (and no documentation at all).

But, being a determined little soul (I was going to write “sole” – with reference to the soles of one’s shoes, or feet – meaning that I now felt trodden upon and thoroughly down-trodden, but that would be an inaccuracy – I was pressing ahead!), I went searching for where the next error lay.

In the code for “type.php” (in the code/tree folder), every single extension appears the be hard-coded into this code, with specific other fields specified for a particular type of extension.   Copying the “php” lines at the bottom of this file and making it “py” finally allowed the code to work for a new type of extension.

I tried to create another file – lo and behold it not only saved, but placed the file in the left hand panel with the ability to click on the filename and edit it in the right hand panel.  Everything now seemed to be in a working state – at least working enough for me to be happy that I had an online programming editor that at least allowed some editing from my own site.

Mind you, at the end of the process, the conclusion I came to was that  it maybe a good idea to refactor some code to allow this new extension specification to all happen within the code.php file (or better still, have the complete code.php set of variables read in from a YAML file, for instance), to set the required controls.  These are the types of situations that one should probably consider building into one’s code from the beginning – have absolutely everything specified as sets of variables in configuration or control files using a standardised format, right from the beginning of the exercise.  A little more work coding wise, especially if the system is being built as one goes along, but worth the effort at the end of the day.  It would be nice to actually have a series of standard libraries to assist one in that area (I am sure they are our there – and I will need to try to find them and see how good they are).

The original author of ecoder responded to say that not much work had been done on the product for a while and that maybe it would get looked at over winter (I presume the Northern Winter, since we are in winter right now where I am – but our part of the world doesn’t count as real) – with a hint that someone may like to look at it and make some changes themselves.  Not really wanting to code in PHP (currently, Python and Groovy are the languages of choice), I might think about this a little longer.  And do some more research – now looking into the Mozilla Labs Bespin product to see whether that is what I want/need/can use.

No Comments

Time Management

In the never ending quest to get more done in the shrinking time vortex, the following are resources of note:

,

No Comments