Monday, June 18, 2007

My Ubuntu Setup

Edit 7/23/07: Replaed the netkit-inetd with openbsd-inetd and fixed svn so it works now.

One of my big pastimes is to play around with Linux. This means I try out a lot of stuff, which often ends up breaking my install. This means I need to whip out the (FREE) install disc and wipe the hard drive and start all over again.
After doing this for the umty-odd time, I finally broke down and made a checklist of everything I do right after a fresh install. Granted this is all for my personal use, so whatever you don't want, skip over.
The one thing you'll need to do is know the basics of vim, which is a classic terminal text editor. Vim is very different than other text editors (The best known being notepad) in that it has different modes for entering text and editing the text. In insert mode you type normally like you would in notepad, and in command mode you would do things like you would with key chords in notepad (ie ctrl-c in notepad is y in vim)
To open a file, just type in a terminal vim /path/to/file. When you first open a file you will be in command mode. To switch to insert mode, press i. To save and quit press esc and then type :wq and press enter. That's all you really should need for the basic editing you're doing here.

Turn off IPv6:
IPv6 is the new system for computers to talk over the internet, unfortunately it really hasn't been implemented yet so it does you no good to have it turned on.
  • In /etc/modprobe.d/aliases change alias net-pf-10 ipv6 to alias net-pf-10 off #ipv6
  • Visit about:config in Firefox, type network.dns.disableIPv6 in the filter bar at the top and turn it to true. This make browsing the web usable again.
Turn on Boot Concurrency:
When your computer is first booting, it needs to run a lot of software right away. Normally what it does is load the first program, run it, load the second, run it, etc. But this isn't as good as loading programs as fast as possible and running them once they're loaded.
  • In /etc/init.d/rc change CONCURRENCY=none to CONCURRENCY=shell
Decrease Swappiness:
Swappiness determines how soon before Linux starts moving stuff from memory to the hard drive to make room for more stuff. Having this fairly high for a small amount of RAM makes sense because when you go to open a new program, you don't want to wait for Linux to swap out a bunch of files in RAM, you want it to have already swapped out a bunch of stuff you weren't using. The downside is that if you have a lot of RAM, (512MB+) it will swap stuff out sooner than it really needs to, and if that stuff it swapped out you really did need, it has to stop and swap it back in. Waste of time. I believe the default value for this is 60. Finding the best value is a bit of trial and error if you want to get it really good. I just use 10.
  • In /etc/sysctl.conf add vm.swappiness = 5
Installing Software:
Now for the first pass of installing software. First use the Symantec GUI to enable Universe and Multiverse. These are just third party software packages that Ubuntu can't guarantee are high quality. Run the following code:
sudo apt-get update
sudo apt-get install preload ssh firestarter mailx subversion openbsd-inetd mpg123
When it installs mailx it will ask what configuration you want, choose local only.
What it does:
  • apt-get update: updates the local database of what software is available to download and install. Ubuntu will usually auto-run this when you boot and check for patches for you. You only need to run this now because you just added two new databases.
  • apt-get install: This downloads and installs all the software packages listed after it.
  • preload: This program runs in the background and watches which programs and libraries you use. When the computer is idle it will take these logs and calculate which programs you're most likely to use next and caches them in memory to help them run faster once you do run them.
  • ssh: This is both the client and server for ssh, which is a remote terminal program that I use so I can work on my Linux box from my Vista laptop anywhere.
  • firestarter: Firestarter is a firewall mostly controlled from a GUI. Start it from System> Administration and make sure to open port 3690 TCP for whoever you want access to your svn server.
  • mailx: mailx is a mail system which is useful because some programs run automatically and will send you email through this to alert you if anything goes wrong.
  • subversion: SubVersion is a revision control system I use for all my programming projects. It's nice because it allows me to program on one computer, commit, switch to another computer, press update and be able to start from where I left off on the other computer.
  • netkit-inetd openbsd-inetd: inetd is the master internet daemon, which you configure to listen on whichever ports you want it to and it will respond to connections on that port by starting the server for it. I only use this with the subversion server. Edit: the openBSD inetd was ported to Linux and is better maintained than the netkit one.
  • mpg123: This is a very lightweight text-based mp3 player. The developers of it take great pride in being able to run it on a 100MHz desktop. Another plus about it is that I run it in a virtual terminal (Ctrl-Alt-F(1-6)) so if I need to restart the X Server (Ctrl-Alt-Backspace) my music keeps playing and I don't miss a beat. (FYI, to switch back to the GUI, press Ctrl-Alt-F7)
Upgrade Vim:
Vim is an extension of another text editor, vi, and normally will try and act like vi, which is great if you're used to vi, but vi was before my time so I've never used anything other than vim, thus I want all the added functionality:
touch ~/.vimrc

Install Hamachi:
Hamachi is a VPN program I use to virtually connect all of my computers plus some of my friends so we can always access the computer no matter where we are. I use it the most to access my SVN server and to log into my Linux box's SSH server.
tar -zxvf hamachi-
sudo su
mkdir /usr/src/hamachi
mv hamachi- /usr/src/hamachi
cd /usr/src/hamachi/hamachi-
make install
hamachi-init -c /etc/hamachi
At this point Hamachi will be installed and you can setup/join your network using these commands:
hamachi -c /etc/hamachi set-nick nickname
hamachi -c /etc/hamachi login
hamachi -c /etc/hamachi create network password
hamachi -c /etc/hamachi join network password
hamachi -c /etc/hamachi go-online network
hamachi -c /etc/hamachi list
hamachi -c /etc/hamachi go-offline my-net
And lastly you need to create a script so Hamachi will start every time you turn your computer on, which is nice, right?
vim /etc/init.d/hamachi-control
And paste the following script into it:


hamachi_start() {
echo "Starting hamachi..."
/usr/bin/hamachi -c /etc/hamachi start

hamachi_stop() {
echo "Stopping hamachi..."
killall tuncfg
/usr/bin/hamachi -c /etc/hamachi stop

hamachi_restart() {
sleep 1

case "$1" in
Edit 11/20/08: Apparently this script has problems starting Hamachi after a power failure.  I no longer use Hamachi on my network, so I can't confirm or deny any solution left in the comments.

Next, make it executable:
chmod a+x /etc/init.d/hamachi-control
And finally add it to the list of scrips to be run on startup and shutdown:
update-rc.d /etc/init.d/hamachi-control defaults
We're done being root for now, exit back to your normal user:
Thanks to this post for most of this, BTW.

Setup Hamachi with Firestarter:
Now that we've installed Hamachi, we need to allow people to access this computer through it. First step is to configure our firewall to recognize it, then to allow access to the ports needed, which in my case is 22 for SSH and 3690 for SVN.
  • In /etc/firestarter/user-pre add:
    • $IPT -A INPUT -i ham0 -j ACCEPT
    • $IPT -A OUTPUT -o ham0 -j ACCEPT
      • Note: I use ham0, type ifconfig to double check that on your system.
  • Since Hamachi is my private network, I'm not very worried about it and allow all traffic on all ports. Add this rule to System > Administration > Firestarter > Policy > Allow connections from host in the GUI:
  • In the bottom box add rules to allow anyone access to ports 22 and 3690 so I can log into this box from any computer over SSH and so anyone can checkout my svn repositories.

Profile the Boot Files in GRUB:
GRUB is the bootloader that first loads everything Linux needs to boot when you first press the power button. Now that we have most of the software setup, we can have GRUB make a list of where all these files are so it can load them faster on boot:
  • On the GRUB splash screen right after the BIOS, press ESC to get to the GRUB menu.
  • Use the arrows to select the Ubuntu kernel and press e to edit the options
  • Move down the the second line and press e again
  • move to the end of this line and add a space and profile
  • press enter, then b to boot the kernel with this extra option
FYI: This option is temporary and will only run this one time. Expect it to boot noticeably slower this time, but after this first time it will boot somewhat faster.

Setting up the SVN Server:
You really have two options here, either run the basic svn server which has no bells or whistles, but just runs and is easy to setup, or run it as an Apache module, which I have never gotten to work before... So I went the first route since it's one of only two services I'm running on this computer, no need for all of Apache.
  • Create a new user to be in charge of the svn repositories. I called my user svn. I gave it a totally random password because I'm never going to be logging in as this user.
  • Switch to this user using su:
    • sudo su - svn
  • In their home directory create a folder called repos to store all the repositories:
    • mkdir repos
  • Create a new repository in repos:
    • cd repos
    • svnadmin create NewRepo
  • Enable the password file
    • cd ~/repos/NewRepo/conf/
    • vim svnserve.conf
      • Uncommect (delete the #) before password-db = passwd
    • vim passwd
      • Add users to the repo in the form username = password
  • Add svn to inetd, so it will start when someone makes a request on port 3690
    • vim /etc/inetd.conf
    • Add this line to the end
      • svn stream tcp nowait svn /usr/bin/svnserve svnserve -i -r /home/svn/repos
    • What this does:
      • svn: defines the service, which is stored in a table in /etc/services, svn uses port 3690
      • stream tcp nowait: this service uses a tcp connection, compared to the simpler udp
      • svn: run this service as the svn user, which protects the rest of your computer
      • /usr/bin/svnserve: this is the program to run to service the client making a connection
      • svnserve -i -r /home/svn/repos: start svnserve, telling it that it's being called by the inetd (-i) and restrict it to the repos folder so it can not access the rest of your computer. (-r /home/svn/repos)
    • restart the inetd so this takes effect
      • /etc/init.d/openbsd-inetd restart
  • We're done, exit out back to your normal account
    • exit
Configure ddclient:
ddclient is a third-party script used to update your IP address for a dyndns account. I use this mainly so I can find my computer anywhere on the internet with the URL Of everything, this is probably by far the most challenging to set up. First download ddclient from the internet and extract it:
tar -xvvjf ddclient-3.7.2.tar.bz2
cd ddclient-3.7.2
sudo su
cp ddclient /usr/sbin/
mkdir /etc/ddclient
cp sample-etc_ddclient.conf /etc/ddclient/ddclient.conf
vim /etc/ddclient/ddclient.conf
And change your hostname, logins, and passwords. Also set your username for mail and turn off SSL, it doesn't work by default. Next add the script so this runs automatically.
cp sample-etc_rc.d_init.d_ddclient /etc/init.d/ddclient
update-rc.d /etc/init.d/ddclient defaults
At this point ddclient should be working, unfortunately it will constantly send you "CAUGHT SIGTERM" emails every time you turn off your computer. I really don't care about what happens to this script when I turn off my computer, so I commented out that line in the script.
vim /usr/sbin/ddclient
And find the line with sigterm and add a # at the beginning of it. Its line number should be somewhere in the 600s.

That pretty much does it. Once I have it setup I obviously add other software like the java compiler and some games, but all of the back-end software is here.

Saturday, June 16, 2007

Laptop Battery Care

First off, in case you didn't already know, rechargeable batteries will wear out. Thats why after 3 years your cell phone doesn't seem to last as long as it used to, and even worse with cordless phones that get used for decades. Over time the batteries inside these devices just can't hold as much of a charge.

So there's a myth/mentality floating around that the best way to extend the life of these batteries was to always make sure to discharge the battery all the way so it doesn't "forget" how much energy it can put out. At one point this was true, but not any more. Most new batteries (Lithium-ion) operate differently than when this was true. As you discharge new batteries, the farther you go, the more you damage it. So to get the best life you want to charge your phone/laptop/etc as often as possible.

The one hangup with this is that if the battery never gets discharged, the battery sensor never gets calibrated and will do the annoying thing of dropping to low battery and stay there for a long time. So to get the best of both worlds, when you get your new laptop, first thing you do is run it all the way down. Don't worry because once the battery gets low enough your computer will go into hibernate (usually, no guarantee) and you can just plug it in and get everything back that you were working on. After draining it this first time, you should be calibrated, so try and keep your batteries charged as much as possible from then on.

The last note on this subject is that if you're putting batteries into long-term storage, it's been found it's good to store them partially discharged. I'm blanking on the number right now but it's either 30% or 70%.

Thursday, June 14, 2007

Cheap Computers with Freedom

So today I was bored, per usual during the summer, so I finally broke down and went to go check out Weird Stuff with Fetter. Weird Stuff is a salvage electronics store, so you can't go there looking for anything specific, but we wanted to see what they had. We've been talking about checking the place out for a few weeks now, but never thought of it until after hours. It's right across the street from the dump so not really on our normal beat.

So we show up at 3:30 and browse around for an hour and play the Atari. It was a pretty cool store over-all. It wasn't anywhere near as bad as I feared it would be. One thing I was really hoping for was an old junker laptop good enough to check email, and not much else. Going camping this summer, I'm not thrilled about taking up my brand new laptop, or to go without email for 9 days. The one thing I did find there that was most tempting was the 10GB hard drives for $15. It's always nice to have an extra hard drive to swap out if I want to test some new OS.

The most interesting part, I thought, was that they had a whole pallet of counter top desktops with PIII and 256MB RAM for $50 each. That means for $65 I can set up a completely useful computer for word processing, email, web browsing, etc. (That is ignoring getting a monitor) This probably won't matter to anyone, but if someone really is desperate to get their own computer, I can hook you up. Granted it will be running Linux, but for $65, even that limitation is irrelevant. It really just means you can't run iTunes on it. (Probably couldn't run iTunes on a PIII anyways...)

On a related note, if anyone has a computer they want to get rid of, I'll take it. I've already gotten a few computers from places. If I deem them useful I'll use them. If not, I'll pick out what will be useful to me and take the rest of it down to the Smart Station. (Which is totally free, so it won't cost me anything)

Sunday, June 3, 2007

Pimped Out My 1kBWC Deck

So tonight after we played a game of 1kBWC at Coffee Society I decided that I was tired of trying to carry all these piles of index cards, so we went to Office Depot and picked out a box to keep it all in, another 500 index card pack (already burned through 60% of last one), and some more pens. The box was $10 and 20 pens were on sale for $2.50.

1000 Blank White Cards

1000 Blank White Cards (or 1kBWC for short) is a game of almost complete freedom with little to no point, goal, or rules. The point of the game is to just have fun and make an utter fool of yourself and your friends in public.

A good intro to the game mechanics is on Wikipedia here. The gist of the game is you start with blank halves of index cards and some from the previous game written on and anyone can fill in the blank cards as they draw them during the game. You then play the cards on each other and follow the instructions on the cards. There are many small variations on the rules so here is our specific rules:
  • Hands are 5 cards by default and players draw back up to the 5 at the end of their turn.
  • Points usually range +/- 100-1000 but is not a hard limit.
  • Players may play counter cards or cards with instant effects any time they want, but must wait until the end of their next turn to redraw to 5.
Our deck is fairly technology oriented with a few different theme sets that we've gone through at times. We save good cards as they phase out so later we can start skipping the pregame when everyone just makes 5 new cards because it's hard to just come up with 5 cards out of nowhere and is rather boring. Since each game is reseeded from the previous game, you collect all the leftovers and they form a huge pile, which you dream reaches 1000 at some point. Most of these collections are named so to distinguish ours it is called the Phire deck.

This is a great game to play with close friends. It's extremely cheap to pick up a $3 pack of 500 index cards, cut them in half, and then go to a coffee shop and play. We scan many of our better cards and upload them to flickr here. I can't recommend this game enough for groups of creative friends dynamic enough to be able to go out and make fools of yourselves.