Finding glibc and gcc Versions

2010 February 10
by SendDerek

Today I was asked to compile a program for one of the SBCs that I work with. The difficulty was in trying to choose the correct cross-compiling toolchain. Since there were several different toolchains each with a different version of gcc and glibc, I wanted to know what other utilities like ‘ls’ were compiled with so I had a good idea of which toolchain to use. I found several different methods of finding a suitable toolchain.

A good place to start is on the target system itself, and if it has ldd and gcc installed, then it’s as easy as using:

ldd --version
gcc --version

Another not-so-obvious method to find all information including gcc and glibc versions is simply using (may not work on all systems):

/lib/libc.so.6

If the above doesn’t work, there is yet another solution and that is to actually compile this short program and run it so that it spits out the glibc version used:

		#include <stdio .h>
		#include <gnu /libc-version.h>
		int main (void) { puts (gnu_get_libc_version ()); return 0; }

It may not be as common, but if a binary has not yet been stripped of it’s comments and extras you can use objdump and objcopy to view information about that file. For example, the following command will use objcopy to spit out the section named .comment within the /bin/ls binary to the /tmp/foobar file. The strings command will then spit out readable text from which you can derive the glibc and/or gcc version that was used to compile the binary. Again, keep in mind that this may not work for every binary. Use the objdump command to see which other fields are available.

objcopy -j .comment /bin/ls /tmp/foobar; strings /tmp/foobar

If you have any more methods for extracting this sort of information out of an already-compiled binary, I’d love to hear about it in the comments.

Create/Compress/Archive Almost Any File in Linux (tar, tar.gz, tar.bz2, gz, bz, zip, 7z, rar, etc…)

2010 February 9

This is a no-frills Linux command line guide/cheat sheet that will help you archive or compress just about any file that you’re bound to come across. If you’d like to have more options, read the man pages! Also, the opposite to this guide about extracting/uncompressing/unarchiving files in Linux can be found here.
read more…

Resizing Photos in Linux or Mac OSX

2010 February 8
by SendDerek

Forget pulling up Photoshop, GIMP, or any other GUI program for a simple CLI job. With utilities like ‘mogrify‘ for Linux and ‘sips‘ for Mac OSX, it’s incredibly quick and easy to batch resize images through the command line. For example, if I wanted to resize all images within a particular folder to a width of 800px without losing aspect ratio, I would use the following commands:

Under Linux:

mogrify -resize 800 *.jpg

Under Mac OSX:

sips --resampleWidth 800 *.jpg

There are many more options for these programs, so play around and be sure to read the man pages.

Another usage example that I heard about today was to use the commands above in a script that will automatically create a thumbnail, small, medium, and large image sizes from a supplied image and then copy them off to the appropriate folder.  This is useful in building a website that has a lot of different image sizes required for the same image.

Additional Resources:
http://www.smokinglinux.com/tutorials/howto-batch-image-resize-on-linux
http://www.ibm.com/developerworks/linux/library/l-graf/

How-To: Setup a Pre-Built VirtualBox Guest Image [Tutorial/Guide]

2010 February 6

Table of Contents

Introduction

This guide will assist in loading a pre-built VirtualBox image. The example used is a pre-built Ubuntu 9.10 “Karmic Koala” guest image. Any VirtualBox image can be used however.

read more…

Shrinking a Dynamic VirtualBox Disk Image

2010 February 4
by SendDerek

I hadn’t realized this before, but you can shrink a dynamic VirtualBox disk image. This is incredibly helpful if you’ve uninstalled programs or freed up a bunch of space and you want the .vdi image size to reflect that. Otherwise, the dynamic disk image will stay the same size it was before. The process is simple, but can be a bit involved so I’ll just touch on the basics and then refer you to a few guides that were really helpful when I did this for my Ubuntu 9.10 VirtualBox image. These guides can be applied to other guest images as well.

1.) Install “zerofree” on your virtualbox guest machine.
2.) Boot to safe mode (recovery mode) where you can access your root partition (/dev/sda1).
3.) Mount the root partition as read-only (mount -o ro /dev/sda1 /mnt/tmp)
4.) Run “zerofree /dev/sda1″
5.) Shutdown the virtual machine and run “VBoxManage modifyhd –compact /path/to/virtualboximage.vdi”

In-Depth Guides:
http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06 — Keep in mind that zerofree does in fact support ext4 (I think this article is a tiny bit dated, but it’s a great one).

http://www.virtualbox.org/manual/UserManual.html — The all important VirtualBox Users Guide.

http://forums.virtualbox.org/viewtopic.php?p=29272#29272 — Another good reference for VirtualBox