Wednesday, April 4, 2007

Facing the beast 3: hardware

My fingers are starting to get tired, can I leave the prompt yet? No. You've only installed Slackware and upgraded to Slackware-current. Now we need to use arcane configuration files to manually set up and optimize some devices. My first step is to discover what devices are currently connected to the machine. The lspci command will provide you with just such a list. I will assume if you've made it this far that you'll be able to discover from the kernel documentation which kernel modules may be necessary for your hardware, and many things work without much configuration at all by building them into the kernel. Due to force of habit from using ancient hardware I still build most of what I want into the kernel and completely exclude the things I don't, without creating many modules. The loading times of modules on modern hardware is undetectable, so anything you think you might need you can compile into a module and load on the fly with virtually no performance loss.

I build my kernel with the networking driver included, but if you decided against that, make sure to edit /etc/rc.d/rc.modules to probe that hardware on startup. Usually the device takes the name /dev/eth0, and on systems with more than one NIC, there will also be /dev/eth1, et cetera. To manually give this a static IP address, use
ifconfig eth0 192.168.1.5

Where eth0 would be your card and 192.168.1.5 would be replaced by the IP address of your choice. If you are connecting directly to your ISP, or have a router in the house, odds are you'll want to go with automatic configuration.
dhcpcd eth0

This will contact the DHCP server and inform your computer of how to communicate with the network. Configuring this behavior on startup is a matter of a few quick edits to /etc/rc.d/rc.inet1.conf using vi, nano or your favorite text editor. For static IP addresses, the first few lines should look like this
# config information for eth0
IPADDR[0]="192.168.1.5" # Your IP address
NETMASK[0]="255.255.255.0" #Your Netmask
USE_DHCP[0]="" # Use DHCP?
DHCP_HOSTNAME="" # DHCP Hostname

For dynamic ones:
# config information for eth0
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME=""

If you have more than one card, replace the 0s with the number of the specific card.
It is handy to create a set of firewall rules with iptables, this is another topic I will be discussing in the future. If the file is named /etc/rc.d/rc.firewall it will be called automatically by /etc/rc.d/rc.inet2 on startup.
With networking configured, I'll go on to sound. Without fail I always compile my sound card as a module and take advantage of a great tool, alsaconf which does all the hard work for you, all you need to do is tell it which card you want installed. To eliminate confusion, I rarely compile the modules for any sound cards other than the one or two that I might be using with any given computer. On this machine, the on board sound is a generic Intel AC97 controller, which I've opted to replace with a VT1720/24 card to get 5.1 capabilities.
The basic configuration of this system does not make 5.1 readily (or even easily) available to you, but with the help of this post on the ubuntu forums, I came across the contents for /etc/asound.conf to enable the functionality. What I am using with this card looks like this:
pcm.!default {
type plug
slave.pcm "surround51"
slave.channels 6
route_policy duplicate
}
pcm.!spdif {
type plug
slave.pcm "hw:0,1"
}
pcm.analog {
type plug
slave analog_slave;
}
pcm_slave.analog_slave {
pcm surround51;
format S32_LE;
}

and it upmixes my music into 5.1 sound. Test it out with speaker-test -c 6 or speaker-test -c 2 for stereo sound.

Once sound is working, move on to video. Finally, we'll have a GUI. Running xorgconfig will set up your Xorg Server. This will include mouse, keyboard, video drivers and some information about your monitor. After completing this it is safe to enter X using the startx script.

With the onboard stuff configured, we should also create some udev rules for the peripherals that will be commonly connected to this system. I'm only using a Kingston 1GB Jump Drive and a video iPod, so those will be my two demonstration rules. Anything that will be dynamically connected and disconnected from your system is a good candidate for udev rules, to ensure a relatively normal interface. Instead of plugging in my iPod and having it become /dev/sda [/dev/sda1 /dev/sda2] it will be known simply as /dev/ipod. The jump drive will be /dev/jump. They'll be mounted in known places, /media/ipod and /media/jump. Reactivated.net has a great how to write udev rules document. Unless you set otherwise, udevd launches automatically when the computer starts up, so we might as well take advantage of it's functionality. Go into /etc/udev/rules.d and create the file 10-local.rules (as per the how to) and add the following lines:

BUS=="usb",SYSFS{manufacturer}=="Apple",SYSFS{product}=="iPod",SYMLINK+="ipod"
BUS=="usb",SYSFS{manufacturer}=="Kingston",SYSFS{product}=="DataTraveler*",SYMLINK+="jump"


restart udevd (/etc/rc.d/rc.udevd restart) and plug in your ipod to find that it's located at /dev/ipod. This /dev name can be used for things like eject and mount. You will also need some corresponding entries in your /etc/fstab to handle these new filesystems

/dev/ipod /mnt/ipod auto noauto,user,rw 0 0
/dev/jump /mnt/jump auto noauto,user,rw 0 0

I find this is especially handy in the iPod's case when configuring Amarok to control the device.

For your specific device, to acquire all the data to tailor make your udev rules you should plug the device in and wait a moment for it to connect. Once the device is connected, run dmesg and note the last thing it reports. One of the lines should be something like

usb 1-7: new high speed USB device using ehci_hcd and address 6

Next, run lsusb to give a little more detailed output. To discover your manufacturer, take the usb number from above and

cat /sys/bus/usb/devices/1-7/{manufacturer,product}

Plug these values into the /ect/udev/rules.d/10-local.rules we created above.

You should now have a totally functional, very modern and efficient Linux system at your fingertips.

No comments: