Using a proxy server for apt-get

by richard on Tue, 01/24/2012 - 10:45

Today, whilst simulating an entire network for my project, I found myself needing to use a proxy server for some Debian hosts (for some reason, they won't seem to connect just straight out!).

It's fairly simple to do. I set up squid on my laptop (what I'm virtualising all this on), and then added a single line to my apt.conf


Acquire::http::Proxy "http://proxy-server-or-ip:8080";

Obviously changing the hostname and port to the ones that you actually use.

Sony Vaio Display Brightness

by richard on Fri, 12/09/2011 - 22:57

Still working on getting my new laptop working exactly as I want it.

Today I wanted to use it in a low-light environment. Knowing that the hotkeys work (I've used the volume ones with much joy after my last laptop not having worked properly), I happily press the hotkey to lower the brightness. I watch the little OSD image with its lowering level, but no change to the brightness of my screen.

A little googling around points me in the direction of a kernel module called sonypi. I look for it on my local disk, and there's nothing. I look for it in apt-file, and it returns all the kernel sources. A bit more googling, and I find out that sonypi is now long gone (it was replaced by a module called sony-laptop)

A bit more hunting around my filesystem, and I have indeed got a module called sony-laptop. I make sure it is loaded, and try the brightness keys again. Still no luck.

The sys filesystem is used for such things as status of brightness, and there is a file called /sys/class/backlight/acpi_video0/brightness which takes values from 1 to 15. I manually set it to 1, and still no luck.

I finally found an answer, which was that it was the nVidia driver that was stopping it from dimming, nothing to do with the ACPI. I needed an extra option in my xorg.conf


Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
Option "RegistryDwords" "EnableBrightnessControl=1"
EndSection

Put that line in, restarted gdm3, and I'm sorted, I can now change the brightness using the function keys :)

Using a chroot environment

by richard on Fri, 12/09/2011 - 08:59

A Chroot environment is usually a folder on your filesystem that contains the entire base system for an operating system.

This tutorial will assume you are installing debian squeeze into a folder /chroot/squeeze

You can create a chroot environment itself using debootstrap.

richard@vpceh:~$ debootstrap squeeze /chroot/squeeze http://ftp.uk.debian.org/debian

That sets up the base packages, and then you need to mount the extra filesystems, and create the list of mounted systems.

The /dev filesystem contains all the device nodes for your system. I find it easiest to bind-mount this from the host operating system.

richard@vpceh:~$ sudo mount -o bind /dev /chroot/squeeze/dev

The /proc filesystem contains information about current running processes. This is mounted using the following command

richard@vpceh:~$ sudo mount -t proc none /chroot/squeeze/proc

you can then chroot into the system using the command

richard@vpceh:~$ sudo chroot /chroot/squeeze /bin/bash

Finally, just read the mounted filesystems into /etc/mtab by running

root@vpceh:/# cat /proc/mounts > /etc/mtab

and then you can perform operations as if you were on your own base system :)

debootstrap - creating a chroot environment on a Debian system

by richard on Fri, 12/09/2011 - 00:26

Being a software developer, and owning quite a few old computers (x86), I sometimes regret my choice of running a 64-bit operating system on my desktop. Then again, it allows me to use the full potential of my processor (whatever that may be - I'm not convinced that it's all that much better than running it 32-bit, but hohum), so I deal with it.

Having cut my metaphorical linux teeth on Gentoo, from before it had an automated installer, I'm no stranger to chroot. A wonderful command that allows you to isolate different installs of the operating system.

A chroot is by far the easiest way to compile 32-bit software on a 64-bit debian install (I know it's possible to install all the 32-bit libraries, but I've always found it to be a faff!).

Enter our friend debootstrap.

debootstrap allows you to create a minimal debian filesystem within a folder on your current system. If you look closely when installing Debian in the first place, you will notice that the installer uses debootstrap to set up your initial system.

It's really easy to use. You just need to point it at a directory, tell it what architecture and version you want to install, and point it at a mirror.

For example, to install a native chroot environment on a debian amd64 system, you would run

richard@nemo:~$ debootstrap squeeze /srv/chroot/squeeze-chroot http://ftp.uk.debian.org/debian

Thats basically telling it to bootstrap squeeze into the folder /srv/chroot/squeeze-chroot from the mirror http://ftp.uk.debian.org

If, however, you want a 32-bit environment on a 64-bit machine, and you want it from wheezy (testing) rather than squeeze (stable) then you would run

richard@nemo:~$ debootstrap --arch=i386 wheezy/srv/chroot/wheezy-chroot http://ftp.uk.debian.org/debian

You can then chroot into your new environment with

richard@nemo:~$ chroot /srv/chroot/wheezy-chroot /bin/bash

In order to make it usable, you would need to create the /dev layout, and mount the proc and sys filesystems. I'll cover them in another post!

Kernel 3.0

by richard on Fri, 12/09/2011 - 00:06

I'm getting a new laptop for Christmas this year. Well, I say for Christmas, but I've actually already got it, and today I started using it (my Final Year Project was refusing to compile on my old one. No idea why, but it just wouldn't have it!).

So I installed Debian (as I was always going to), and off it goes. All happy, a couple of tweaks to the grub boot command to get the touchpad working, and I'm sorted. Or so I thought.

I was happily sitting at Uni, listening to my music, when I realise that the sound is not only coming through my headphones, but also out of the inbuilt speakers. Thinking that odd, I fiddle around with the headphone jack in case it's a loose connection or something.

No ball.

After a quick google, I realise that this is a common problem with the sound chip I have (I'll have to update this post with the name of it if I remember!). It seems that the speaker cut-out is handled by the driver rather than by the hardware (who knew!).

So, I add squeeze-backports to my apt-sources and upgrade to Kernel 2.6.38 hoping that the ALSA driver in that will have it.

Again, no ball.

Deciding to just see if it'll work (although there's nothing more permanent than a temporary solution) if I upgrade to Kernel 3.0, I grab the associated packages from the wheezy repository. After a bit of faffing with dependencies (and about 10 package downloads, one after the other), I get Kernel 3.0 installed. Which is all well and good, but it refuses to install the nVidia driver I spent oh-so-long installing earlier. Kernel 3.0 is compiled with gcc-4.6 which doesn't appear in squeeze, and as I don't really want to upgrade large swathes of my fresh squeeze install, I refuse to let it install. Still, at least the alsa is now working and it mutes the speakers when I plug headphones in!

Eventually, I debootstrap-ed a chroot of wheezy, and compiled the nVidia dkms module in there, copied it out, and ran depmod. It worked perfectly, and now I have a nice running 3.0 kernel, with full ALSA support for my sound card, and an nVidia binary driver for the display (I would use one of the open source ones, but my video card, a GeForce 410M appears to be a bit new!).

Audacity - Making a mono track stereo

by richard on Mon, 11/21/2011 - 10:03

I'm writing a little application at the moment that will create atmospheric sounds (I'll have it up here as soon as I have a version that actually works!)

Unfortunately, the audio library I'm using (see previous post) only accepts 44100 stereo tracks at the moment (I'm going to look at fixing that at some point!), so I found myself needing to convert some mono tracks into stereo.

I fire up audacity as I normally would, and after about 20 minutes of cursing at the computer because every time I paste, it shifts the other tracks along a bit (still need to find a fix for that!), I find that there's a duplicate function.

Et voila, select the mono track, press Ctrl-D to duplicate, change the two mono tracks to stereo (the little drop-down list on the track > Make Stereo Track), and there you have a nice stereo track :)

Operator Overloading and Namespaces

by richard on Sat, 11/19/2011 - 14:22

Operator overloading is really useful. I've written a time class (literally just has an hour and a minute), and wanted to be able to compare two times (so I can tell if I am between a beginning and a start time). I knew about operator overloading, and how I could use my own code for < and > comparisons.

Thinking I knew how it was done, I wrote some code. It looked something like this:

class Time {
public:
	Time();
	virtual ~Time();
	int hour;
	int minute;

	friend bool operator< (Time lhs, Time rhs);
	friend bool operator> (Time lhs, Time rhs);
	friend bool operator<= (Time lhs, Time rhs);
	friend bool operator>= (Time lhs, Time rhs);
	friend bool operator== (Time &lhs, Time &rhs);
	friend ostream& operator<<(ostream& output, Time theTime);
};

in the header and
bool operator<(Time lhs, Time rhs) {
	return false;
	cout << "Comparing " << &lhs <<  " to " << &rhs << endl;
	if (lhs.hour < rhs.hour) return true;
	if (lhs.hour > rhs.hour) return false;
	//The hours must be the same
	if (lhs.minute < rhs.minute) return true;
	if (lhs.minute > rhs.minute) return false;
	//The hours and minutes must be the same
	return false;
}

bool operator<=(Time lhs, Time rhs) {
	return true;
	if (lhs.hour < rhs.hour) return true;
	if (lhs.hour > rhs.hour) return false;
	//The hours must be the same
	if (lhs.minute < rhs.minute) return true;
	if (lhs.minute > rhs.minute) return false;
	//The hours and minutes must be the same
	return true;
}

bool operator>(Time lhs, Time rhs) {
	if (lhs.hour < rhs.hour) return false;
	if (lhs.hour > rhs.hour) return true;
	//The hours must be the same
	if (lhs.minute < rhs.minute) return false;
	if (lhs.minute > rhs.minute) return true;
	//The hours and minutes must be the same
	return false;
}

bool operator>=(Time lhs, Time rhs) {
	if (lhs.hour < rhs.hour) return false;
	if (lhs.hour > rhs.hour) return true;
	//The hours must be the same
	if (lhs.minute < rhs.minute) return false;
	if (lhs.minute > rhs.minute) return true;
	//The hours and minutes must be the same
	return true;
}

bool operator==(Time &lhs, Time &rhs) {
	if ((lhs.hour == rhs.hour) && (lhs.minute == rhs.minute)) return true;
	return false;
}

ostream& operator<<(ostream& output, Time theTime) {
	output << theTime.hour << ":" << theTime.minute;
	return output;
}


in the source file.

So I write some tests to see it working. But for some reason, it's not calling my operator functions.

Thinking I had it wrong with pointers and pointees and the such (which I had, I was passing a pointer rather than a pointee!), I try de-referencing the pointer, which gives me a really weird series of errors.

I eventually manage to work out that because my class "Time" is in a namespace "RainyMood", I need the operators to be in the Rainymood namespace as well!

Fixed that up with some forward declarations in the namespace file, and added a Rainymood:: to the beginning of all the operators, and it works beautifully!

C++ - getting the time

by richard on Sat, 11/19/2011 - 12:13

So, I've been working on a program that provides atmospheric sounds (rain, thunder, owls, that kind of thing). All well and good, got the system playing sounds (through a nice audio library that was actually written by some of the members of Radio at Warwick a couple of years ago - http://www.broadcastsoftware.org/), and I have a nice data structure layout all sorted for random sounds playing between specific times and the such.

Which is where it all falls down. I don't know how to do times in C++.

I do a quick Google, and find that there is a header file which includes time stuff. All well and good, import it, and do a quick cout of the time that it's returning (it returns seconds since the epoch). Randomly, it's giving me the time from 6 hours ago.

Turns out that there's another function (localtime) which then converts it into local time.

No idea what timezone it's working on though (as my hardware clock is set to UTC, which we should be on at the moment, what with it not being summer).

Hohum, localtime here I come!

Gnome power - Do nothing on lid close

by richard on Sat, 11/12/2011 - 09:04

I use Gnome. I know, it's heavy, but I like it. It has lots of features that I just don't notice until I don't have them.

One thing that I did want to do, though, is have it so that when I close my laptop lid, it does nothing.

Thinking I knew how to change this, I fire up the gnome Power Management tool (System > Preferences > Power Management), and go to the On AC tab. I drop down the list for "When laptop lid is closed". There is no "Do Nothing" option. I have Blank Screen (which is no good, because I have an external screen connected), a Suspend (definitely no good!), a Shut Down and a Hibernate (also no good because I actually want to use the laptop!)

However, as this is Linux, of course there's a way of doing it. It just requires gconf-editor.

So, in gconf-editor, you look under /apps/gnome-power-manager/buttons/ (I didn't necessarily think of the lid as a button, but hrm!) and change lid_ac (or lid_battery, depending on what you're running it on) to "nothing".

Sure enough, when I close my laptop lid, the screen doesnt blank!

Tags: 

Finding Linux Version information

by richard on Fri, 09/23/2011 - 17:44

So, I am working on a project where I need to be able to work out what version of linux a server is running.

Did a bit of googling, and found that /etc/debian_version shows it for debian, and there are similar files for other distros, but then stumbled across the command lsb_release.

lsb_release is an application that "provides certain LSB (Linux Standard Base) and distribution-specific information". Which is just what I need.

To use it, simple as lsb_release -a (shows all data), but you can also get it to show you more specific information.

Tags: 

Pages