Using a proxy server for apt-get
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
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
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 :)
Kernel 3.0
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!).
Gnome power - Do nothing on lid close
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!
Finding Linux Version information
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.
Using get_iplayer to download from iPlayer
get_iplayer is a nifty little tool that allows you to download iPlayer programmes (either radio or TV) to your computer.
Installation on Debian is very easy. Just fire up a terminal, and use apt-get.
You can, of course, use synaptic or any other package management tool that interfaces with apt, but I use apt-get
richard@eee:~$ sudo apt-get install get-iplayer
apt-get will ask you to confirm that you want to install the dependencies, which is fine.
Once it is installed, you can browse available programmes, download specific programmes, or download any programme that matches a string. Examples are below:
Browse Programmes
richard@eee:~$ get_iplayer torchwood
get_iplayer v2.78, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.
Matches:
704: Torchwood - Miracle Day: Episode 1, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
705: Torchwood - Miracle Day: Episode 2, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
706: Torchwood - Miracle Day: Episode 3, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
707: Torchwood - Miracle Day: Episode 4, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
708: Torchwood - Miracle Day: Episode 5, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
709: Torchwood - Miracle Day: Episode 6, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
710: Torchwood - Miracle Day: Episode 7, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
711: Torchwood - Miracle Day: Episode 8, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
712: Torchwood - Miracle Day: Episode 9, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
713: Torchwood - Miracle Day: Episode 10, BBC HD, Audio Described,Drama,Guidance,Popular,SciFi & Fantasy,TV, default,audiodescribed,
INFO: 10 Matching Programmes
Download Specific Programme
richard@eee:~$ get_iplayer --get 713
get_iplayer v2.78, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.
Matches:
713: Torchwood - Miracle Day: Episode 10, BBC HD, Audio Described,Drama,Guidance,Popular,SciFi & Fantasy,TV, default,audiodescribed,
INFO: 1 Matching Programmes
This will then go on to download the programme.
Download all programmes matching a string
richard@eee:~$ get_iplayer --get Torchwood
get_iplayer v2.78, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.
Matches:
704: Torchwood - Miracle Day: Episode 1, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
705: Torchwood - Miracle Day: Episode 2, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
706: Torchwood - Miracle Day: Episode 3, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
707: Torchwood - Miracle Day: Episode 4, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
708: Torchwood - Miracle Day: Episode 5, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
709: Torchwood - Miracle Day: Episode 6, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
710: Torchwood - Miracle Day: Episode 7, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
711: Torchwood - Miracle Day: Episode 8, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
712: Torchwood - Miracle Day: Episode 9, BBC HD, Audio Described,Drama,Guidance,SciFi & Fantasy,TV, default,audiodescribed
713: Torchwood - Miracle Day: Episode 10, BBC HD, Audio Described,Drama,Guidance,Popular,SciFi & Fantasy,TV, default,audiodescribed,
INFO: 10 Matching Programmes
Downloading a programme from a URL
If you've found the programme you want on the iPlayer website, then you can download from a specific URL. To do this:
richard@eee:~$ get_iplayer --get "http://www.bbc.co.uk/iplayer/episode/b014vy02/Doctor_Who_Series_6_The_God_Complex/"
get_iplayer v2.78, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.
INFO: Trying pid: b014vy02 using type: tv
INFO Trying to stream pid using type tv
INFO: pid found in cache
Matches:
208: Doctor Who: Series 6 - 11. The God Complex, BBC One, Drama,Highlights,Popular,SciFi & Fantasy,TV, default,
INFO: 1 Matching Programmes
Note the quotation marks around the URL. These are required
It is worth noting that get_iplayer will default to downloading as an FLV file (which won't play on everything) unless it can find ffmpeg on the system. To install ffmpeg, just run
richard@eee:~$ apt-get install ffmpeg
then get_iplayer will convert it to a nice mp4 for you
SSH Keys
SSH and SCP are wonderful tools. I use them all the time for moving files, managing servers, and anything else I need to do on a remote system.
One thing that gets me though is the way I have to type my password every time. Enter SSH Keys...
SSH keys are a private/public keypair system for authenticating you when logging into a remote machine by SSH. The private key sits on the client, and the public key can sit on as many servers as you wish.
Setting up SSH keys is easy. On your client machine, you need to generate the keypair. Fire up a shell, and runrichard@eee:~$ ssh-keygen
There are options for ssh-keygen, such as setting the encryption type, and number of bits, but I'm happy with the defaults.
The program will prompt you for where to save the file (the default ~/.ssh/id_rsa is fine), and then for a passphrase. It isn't good form to leave an empty passphrase, as then anyone who gets your private key would be able to use it to get into any of your servers. I know, it means that you have to enter a password when you're using SSH, but at least you can have a shorter password than the 41 character alpha-numeric password your sysadmin forces you to use!
ssh-keygen will then show you what your key looks like (as a randomart picture), and write the keypair to the file you specified.
So now you have a keypair, you need to copy the public part to your server.
richard@eee:~$ scp .ssh/id_rsa.pub remoteserver:~/
This will copy the id_rsa.pub file (the public part of your key) to your remote server, into your home directory.
Then, ssh to your server, and runrichard@remoteserver:~$ cat id_rsa.pub >> .ssh/authorized_keys2
This will append your public key to the authorized keys for this account.
Note, you can have more than one key for a single account. So, if you have a laptop, and a desktop, then you might have the key that is on your laptop able to log into some servers, and the key from your desktop able to log into more servers (because your desktop is less likely to be stolen!).
Terminate the SSH session, and then try logging in with your new SSH keys. It should drop you straight in!
How to tell if your CPU is 64 bit (in Linux)
richard@bx296:~ cat /proc/cpuinfo | grep flags
then it will output something like:
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
There are four lines because the OS sees four processors. In actual fact, there are only two physical processors, but both have two cores.
So, the flag you are looking for is lm. This server doesn't have it, which tells me that it is a 32-bit CPU, but if it did have it, then I would know that it was 64-bit.Nano Search & Replace
Neat little trick - Use Ctrl-\ in Nano to open the search and replace function. Enter the search term, and then what you want to replace it with and voila, a search and replace with yes/no/all choice for each match!

