Ubuntu
[VirtualBox/Linux/Windows] Copied Linux Guests Increasing eth devices
by Chuck Kozler on Jan.13, 2010, under Computers, Linux/Unix, Ubuntu, Windows
I noticed that when you copy Linux guests (VBoxManage clonevdi) and then try to use them, your ethernet device adapters keep increasing by one (eth0,eth1,eth2..etc).
This happens because the OS is looking in /etc/udev/rules.d/70-persistent-net.rules to look for the MAC address and corresponding adapter. Since the MAC address on the now new guest has been changed by VirtualBox, obviously the Guest OS can not find this MAC address. Naturally, it disables eth0 and creates eth1 with the new VirtualBox generated MAC address.
This can become quite troublesome, especially if you make a copy of a copy of a copy and so on.
I wrote a quick script to swap these MAC addresses around for you. I had to write something like this because I had to deploy about 20 Virtualized Guests and I created a base VDI to copy over and over as I needed it. I placed this script in the /root directory so I could just “su” and execute it, restart, and my address was fixed.
#!/bin/bash user=`whoami` if [ $user != "root" ]; then echo "You must be root to run this. Exiting." exit 300 fi function swapMacs { eth0_mac=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth0" | cut -d ',' -f4 | cut -d '=' -f3 | cut -d '"' -f2 | sed -e 's/:/\\\\:/g'` if [ -z $eth0_mac ]; then echo " ! MAC Address for eth0 is empty. Could not retrieve MAC from udev file." exit 100 fi eth1_mac=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth1" | cut -d ',' -f4 | cut -d '=' -f3 | cut -d '"' -f2 | sed -e 's/:/\\\\:/g'` if [ -z $eth1_mac ]; then echo " ! MAC Address for eth1 is empty. Could not retrieve MAC from udev file. ( Are you sure the line exists? )" exit 100 fi echo " * Find old mac: $eth0_mac" echo " * Replacing with: $eth1_mac" sed -i "s/$eth0_mac/$eth1_mac/g" /etc/udev/rules.d/70-persistent-net.rules if [ $? -eq 0 ]; then echo " + Successfully swapped mac addresses" echo " * Setting new udev file" new_rule=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth0"` echo $new_rule > /etc/udev/rules.d/70-persistent-net.rules if [ $? -eq 0 ]; then echo " + We have successfully updated the udev file" else echo " ! Problem updating the udev file" exit 100 fi else echo " ! Problem swapping mac addresses" exit 100 fi } swapMacs
[Ubuntu/Linux] Set networking script
by Chuck Kozler on Dec.09, 2009, under Computers, Home, Linux/Unix, Networks/Servers, Ubuntu
Hi Everyone,
I have to manually change my network configuration settings a lot on my laptop when I’m at work and jumping between routers and other networks.
I got tired of manually entering all the commands so I wrote this. I expanded it a bit so other people can use it.
Its a quick and dirty script so it doesnt catch errors. Just checks if ifconfig and route commands were executed successfully.
Its pretty self explanitory. It takes in arguments of
device = the device you want to modify (eth0, eth1, etc…)
ip = the IP you want to set for yourself
gateway = The gateway you’re connecting to
dns = This is optional but you can set your own single DNS server address. If you do not enter one, the script will ask you if you want it to set you default ones with OpenDNS’ DNS server (http://opendns.org).
#!/bin/bash script_name=`basename $0` echo "" if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then echo "Usage is: " echo "" echo " $script_name [device] [ip_addr] [gateway] [Optional: one_dns_server]" echo "" echo "Note: Only one DNS server can be set. Manually update resolv.conf if you want more" echo "Note: If no DNS is specified, the script will ask you if you want it to set you one." echo "" echo "" echo "Example: " echo "" echo " $script_name eth0 192.168.1.135 192.168.1.1 4.2.2.2" echo "" exit 0 fi device="$1" ip="$2" gw="$3" primary_dns="$4" user=`echo $USER` ans='y' if [ $user != "root" ]; then echo "You must be root to run this" exit 108 fi if [ -z $device ]; then echo "You must specify a device to modify" exit 5 fi if [ -z $ip ]; then echo "You must specify an IP address for your machine" exit 5 fi if [ -z $gw ]; then echo "You must specify a default gateway address" exit 5 fi if [ -z $primary_dns ]; then echo "* No DNS server set." echo "* You do not need to specify a DNS server but it is suggested" echo "* Would you like the script to write default DNS for you (using OpenDNS)? [y/n] (default: y)" read ans echo "Write DNS = " $ans fi # Do the networking configuration # ifconfig eth0 $ip if [ $? -eq 0 ]; then success=1 fi route add default gw $gw ret="$?" if [ $ret -eq 0 ] || [ $ret -eq 7 ]; then success=2 fi if [ ! -z $primary_dns ]; then su -c "echo nameserver $primary_dns > /etc/resolv.conf" else if [ $ans == 'y' ] || [ $ans == 'Y' ]; then su -c "echo nameserver 208.67.222.222 > /etc/resolv.conf" su -c "echo nameserver 208.67.222.220 >> /etc/resolv.conf" fi fi device_ip=`ifconfig eth0 | grep -i $ip | cut -d ':' -f2 | cut -d ' ' -f1` route_gw=`route -n | grep -i 192.168.155.1 | awk '{ print $2 }'` route_flag=`route -n | grep -i 192.168.155.1 | awk '{ print $4 }'` if [ $success -eq 2 ]; then echo "" echo "* Success!" echo "" echo "* IP: $device_ip" echo "* Gateway: $route_gw ( $route_flag )" echo "" fi exit
[Ubuntu\Mono\Gnome] GtkMountISO Application Release
by Chuck Kozler on Sep.27, 2009, under Computers, Home, Linux/Unix, Programming, Ubuntu, Windows
So, I guess this is my actual first application release in about 4 years since I stopped writing cheats/hacks for Counter-Strike and Counter-Strike source. You can see the video of this in action below and underneath, a link to download it from. You can find all the information you need in the readme. Please, make sure you read the readme, it will save us all a lot of time. For whatever reason, I am going to post the flow chart I made for the bash installer script. Maybe *someone* can find it useful in the future.
Sphere: Related Content[Ubuntu/Gnome] Gtk ISO Mount Program
by Chuck Kozler on Sep.24, 2009, under Computers, Home, Linux/Unix, Programming, Ubuntu
This is a program I wrote to mount ISO’s under Linux. I wrote it in C# utilizing the Mono libraries. I must say, I love C# so much more now. The video is below and the unedited/uncleaned code is below the video. Hope you enjoy!
using System; using Gtk; using System.Diagnostics; using System.Text.RegularExpressions; public partial class MainWindow: Gtk.Window { string Users_Home = Environment.GetEnvironmentVariable( "HOME" ); public int runCommand( string command, string args, bool wait ) { Process proc = new Process( ); proc.StartInfo.FileName = command; proc.StartInfo.Arguments = args; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; if( proc.Start() ) { if( wait == true ) { proc.WaitForExit( ); return proc.ExitCode; } else { return proc.ExitCode; } } return -1; } public void runCommand( string command, string args, bool wait, int milliseconds ) { Process proc = new Process( ); proc.StartInfo.FileName = command; proc.StartInfo.Arguments = args; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; if( proc.Start() ) { if( wait == true ) if( milliseconds > 0 ) proc.WaitForExit( milliseconds ); else proc.WaitForExit( ); else proc.Close( ); } } public string getOutput( string command, string args, bool wait ) { Process proc = new Process( ); proc.StartInfo.FileName = command; proc.StartInfo.Arguments = args; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; if( proc.Start( ) ) { if( wait == true ) { proc.WaitForExit( ); string output = proc.StandardOutput.ReadToEnd( ).TrimEnd( ); string error = proc.StandardError.ReadToEnd( ).TrimEnd( ); if( output.Equals( "" ) || output.Equals( " " ) ) { return error; } else return output; } else { string output = proc.StandardOutput.ReadToEnd( ).TrimEnd( ); string error = proc.StandardError.ReadToEnd( ).TrimEnd( ); if( output.Equals( "" ) || output.Equals( " " ) ) { return error; } else return output; } } else return "Could not start process. Check process file name."; } public string getCommand( string command_name ) { return getOutput( "which", command_name, false ); } public void UpdateMountList( ) { runCommand( "sh", "-c \"mount -l | grep -i \"" + Users_Home + "/.GtkMountISO\" | cut -d ' ' -f3 > " + Users_Home + "/.GtkMountISO/mounts.current\"", true ); int ln_count = 0; string cur_line = ""; System.IO.StreamReader file = new System.IO.StreamReader( Users_Home + "/.GtkMountISO/mounts.current" ); while( ( cur_line = file.ReadLine( ) ) != null ) { CurrentMounts.AppendText( cur_line ); ln_count++; } file.Close( ); CurrentMounts.RemoveText( ln_count ); } public MainWindow (): base (Gtk.WindowType.Toplevel) { Build (); if( !( System.IO.Directory.Exists( Users_Home + "/.GtkMountISO" ) ) ) { //If hidden GtkMountISO folder does not exist, create dir string mkdir = getCommand( "mkdir" ); Console.WriteLine( "GtkMountISO folder does not exist. Creating." ); int retval = runCommand( mkdir, Users_Home + "/.GtkMountISO", true ); if( retval == 0 ) { Console.WriteLine( "Created directory for GtkMountISO" ); } } else { UpdateMountList( ); } } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { int rm_retval = runCommand( "rm", Users_Home + "/.GtkMountISO/mounts.current", true ); Console.WriteLine( "Del retval = " + rm_retval ); Application.Quit (); a.RetVal = true; } protected virtual void OnMountISOClicked (object sender, System.EventArgs e) { string zenity = getCommand( "zenity" ); string xterm = getCommand( "xterm" ); string echo = getCommand( "echo" ); string sleep = getCommand( "sleep" ); try { /* * 1.) Get Filename */ //Get Full file name string ISO_Name = SelectISOButton.Filename.ToString( ); Regex r = new Regex( @"\s+" ); string ISO_Name_Regex = r.Replace( ISO_Name, @"\\ " ); //Split it based on slashes string[] ISO_Name_Parts = ISO_Name.Split( '/' ); //Get length to subtract one and get single file name int Parts_num = ISO_Name_Parts.Length; string ISO_Parsed_Name = ISO_Name_Parts[ Parts_num - 1 ]; //Split string again based on "." to get standalone file name with no extension string[] ISO_Strip_Extension = ISO_Parsed_Name.Split( '.' ); int ISO_Parsed_Num = ISO_Strip_Extension.Length; string ISO_Cleaned_Name = ISO_Strip_Extension[ ISO_Parsed_Num - 2 ]; string iso_extension = ISO_Strip_Extension[ ISO_Parsed_Num - 1 ]; Console.WriteLine( "Extension = " + iso_extension ); if( iso_extension.Equals( "iso" ) || iso_extension.Equals( "ISO" ) ) { Console.WriteLine( "Cleaned Name = " + ISO_Cleaned_Name ); /* * 2.) Make folder name @ /_USERS_HOME_DIR_/_FILE_NAME_ */ string Users_Home = Environment.GetEnvironmentVariable( "HOME" ); Console.WriteLine( Users_Home ); string mkdir = getCommand( "mkdir" ); string make_dir_cmd = mkdir + " " + Users_Home + "/.GtkMountISO/" + ISO_Cleaned_Name; Console.WriteLine( make_dir_cmd ); int make_dir = runCommand( mkdir, Users_Home + "/.GtkMountISO/" + ISO_Cleaned_Name, true ); string mount_point = Users_Home + "/.GtkMountISO/" + ISO_Cleaned_Name; int zenity_retval = -1; if( make_dir != 0 ) { zenity_retval = runCommand( zenity, "--question --text=\"Folder exists. Would you like to mount anyway?\"", true ); Console.WriteLine( "Zenity reval = " + zenity_retval ); } if( ( make_dir == 0 ) || ( make_dir != 0 && zenity_retval == 0 ) ) { Console.WriteLine( "Folder created" ); /* * 3.) Execute "mount -t iso9660 _FULL_FILE_NAME_ /_USERS_HOME_DIR_/_FILE_NAME_ -o loop */ string gksudo = getCommand( "gksudo" ); string mount = getCommand( "mount" ); Console.WriteLine( "ISO_Name = " + ISO_Name ); Console.WriteLine( "Mount_Point = " + mount_point ); //Need to some how account for white space without corrupting the commands sent to the system... int retval = runCommand( gksudo, "\"" + mount + " -t iso9660 " + ISO_Name_Regex + " " + mount_point + " -o loop\"", true ); Console.WriteLine( " Mount Retval = " + retval ); if( retval == 0 || retval == 1 ) { //Success if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " Success! && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--info --title=\"Success\" --text=\"Success!\n\n You can find the ISO mounted at " + mount_point + "\"", true, 0 ); string nautilus = getCommand( "nautilus" ); if( nautilus.Equals( "" ) ) return; else runCommand( nautilus, "\"" + mount_point + "\"", false, 0 ); } else if( retval == 7 ) { //Mount Failure if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " Failed to mount. Is the file an actual ISO? && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--error --title=\"error\" --text=\"Failed to mount. Is the file an actual ISO?\"", true, 0 ); } else if( retval == 32 ) { //Mount Failure if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " Failed to mount. Is there already something mounted there? && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--error --title=\"error\" --text=\"Failed to mount. Is there already something mounted there?\"", true, 0 ); } /* * 4.) Add to flat file database of mounted folders */ UpdateMountList( ); } } else { if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " File is not an ISO image && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--error --title=\"error\" --text=\"You must select an ISO image file\"", true, 0 ); } } catch( NullReferenceException nullexception ) { string error = nullexception.ToString( ); if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " You must select a file first && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--error --title=\"error\" --text=\"Error Thrown: \n\n" + error + "\n\nYou must select a file first\"", true, 0 ); Console.WriteLine( error ); } } protected virtual void OnUnMountISOClicked (object sender, System.EventArgs e) { Console.WriteLine( "Unmounting " + CurrentMounts.ActiveText ); string zenity = getCommand( "zenity" ); string xterm = getCommand( "xterm" ); string echo = getCommand( "echo" ); string sleep = getCommand( "sleep" ); string gksudo = getCommand( "gksudo" ); string umount = getCommand( "umount" ); string iso_to_unmount = CurrentMounts.ActiveText; int umount_retval = runCommand( gksudo, "\"" + umount + " -f " + iso_to_unmount + "\"", true ); Console.WriteLine( "Umount retval = " + umount_retval ); if( umount_retval == 0 ) { if( zenity.Equals( "" ) ) { runCommand( xterm, "-e \"" + echo + " File successfully unmounted && " + sleep + " 5\"", true, 0 ); } else runCommand( zenity, "--info --title=\"error\" --text=\"File successfully unmounted!\"", true, 0 ); } UpdateMountList( ); } }
[Ubuntu/Wine] Windows Installer Service Could Not Be Accessed
by Chuck Kozler on Aug.27, 2009, under Computers, Linux/Unix, Ubuntu
I have noticed running Wine version 1.1.28 and trying to install some programs and/or games returned the error
“The Windows Installer Service could not be accessed. This can occur if you are running Windows in safe mode, or if the Windows Installer is not correctly installed. Contact your support personnel for assistance.”
This is how I went about fixing it:
1.) Download “winetricks” from here => http://wiki.winehq.org/winetricks – more specifically, you can execute this command:
wget http://www.kegel.com/wine/winetricks
2.) Execute winetricks
sh winetricks3.) Scroll down until you see “msi2″ and put a check next to it. This will install the Microsoft Installer version 2.0 for wine.
4.) Execute the command “winecfg”
winecfg
5.) Scroll down until you see msi(native, builtin)
6.) Click it and click the “edit” button to the right
7.) Click the radio button next to “Builtin then Native”
For whatever reason, this fixed the above problem for me. If it doesnt for you, let me know what problems you encountered.
Sphere: Related Content[Bash] Stop hddtemp/Conky populating netstat
by Chuck Kozler on Mar.17, 2009, under Computers, Linux/Unix, Ubuntu
Hi everyone,
I noticed when using Conky and hddtemp application that most conky scripts will query hddtemp through
nc localhost <hddtemp_port>
and would populate netstat command with a whole ton of TIME_WAIT connections. I have developed a fix for this.
1.) First, edit the hddtemp script where you report the temperature to look something like this:
Temperature: ${alignr}${exec cat /etc/hddtmp_out }
Then:
sudo touch /etc/hddtmp_out
Then, utilize this script or create a simliar one to generate the same effects:
#!/bin/bash date=`date` touch /root/gettemp.log #change your harddrive to /dev/sda1 if it is not /dev/sda1 /usr/sbin/hddtemp /dev/sda1 | cut -d ":" -f3 > /etc/hddtmp_out if [ $? -eq 0 ]; then echo "Command completed successfully" elif [ $? -gt 0 ] || [ $cmd != " " ]; then echo "Caught error" fi #temp=`hddtemp /dev/sda1 | cut -d ":" -f3` #log=`echo Get temp finished @ $date reporting $temp >> /root/gettemp.log` exit 0
What this script does:
First it gets the date and touches gettemp.log in /root/ to ensure it is there. Then, it executes the hddtemp executable querying the appropriate hard drive. Make sure to change to your appropriate hard drive (read hddtemp manual). The script then parses out the temperature and outputs it to /etc/hddtmp_out (hint: cat /etc/hddtmp_out from the conky script). Finally, for logging and error reporting purposes, it outputs to the gettemp.log file in the root directory. This was more or less used when I was debugging so you can remove it if you like. You can place that in /usr/local/bin for easy access as that is how I created the cron job (read below). Also, if you notice that your conky script is not updating, remove the comments next to the two lines for logging so you can see if it is in fact writing to the file at the write times (every minute).
Then create a cron job to run every minute. This wont be too intensive on the system seeing as to query the temperature through the cron job is about as equal as running the netcat command.
sudo su - crontab -e
Add this line:
* * * * * test -x /usr/local/bin/gettemp && ( sudo /usr/local/bin/gettemp )
This will create a cron job to execute every minute to report and output to the hddtmp_out file in /etc.
Sphere: Related Content[Linux/Bash] Update DNS Script
by Chuck Kozler on Mar.04, 2009, under Computers, Linux/Unix, Networks/Servers, Ubuntu
I am currently doing a project that involves me creating my own DNS servers in virtual environments. To utilize those DNS servers I will need to, of course, edit the host computer’s /etc/resolv.conf to point to my new DNS servers IP addresses. For some odd reason I could not set a static IP (my Universities network is complete crap) and I required the dhclient/dhcp3-client package to be able to utilize my network. Since dhcp3-client likes to overwrite the /etc/resolv.conf file (regardless of what is in the /etc/dhcp3/dhcp.conf file) I had to hand edit the /etc/resolv.conf file ALL the time. Well, I got sick of that and this is what came of it.
I hope you enjoy
#!/bin/bash user=`whoami` if [ $user != "root" ]; then echo "You must be root to run this" exit 0 fi basename=`basename $0` location=`dirname "$0"` ans='n' if [ $location != "/usr/local/bin" ]; then echo "" echo "If this were in /usr/local/bin then it would be easier to use (or set PATH variables)" echo "" echo "Would you like to copy it there? [Y/n]" read ans fi function usage { echo " " echo "Usage is: " echo " " echo " makedns <domain> <domain_to_search> <ip_of_dns_1>" echo " " echo " " echo "Example:" echo " " echo " makedns test.local test.local 192.168.1.101" echo " " } if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] ; then usage if [ -z "$1" ];then echo "You left field 1 blank. Please fill in a DNS domain name" elif [ -z "$2" ]; then echo "You left field 2 blank. Please fill in a DNS search to search" elif [ -z "$3" ]; then echo "You left field 3 blank. Please fill in a primary DNS IP" fi echo " " exit 0 fi # # TODO: Possibly do this in a loop and store them in an array? # lines=`wc -l /etc/resolv.conf | cut -d " " -f1` dnsdomain=`sed -n "1 p" /etc/resolv.conf | cut -d " " -f2` dnssearch=`sed -n "2 p" /etc/resolv.conf | cut -d " " -f2` dnsip1=`sed -n "3 p" /etc/resolv.conf | cut -d " " -f2` dnsip2=`sed -n "4 p" /etc/resolv.conf | cut -d " " -f2` _in_dnsdomain="$1" _in_dnssearch="$2" _in_dnsip1="$3" _in_dnsip2="$4" # # # #echo text_to_pipe | sed s/<old>/<new> complete=0 if [ $lines -gt 0 ]; then echo "domain $_in_dnsdomain" > /etc/resolv.conf if [ $? -eq 0 ]; then complete=1 fi echo "search $_in_dnssearch" >> /etc/resolv.conf if [ $? -eq 0 ]; then complete=2 fi echo "nameserver $_in_dnsip1" >> /etc/resolv.conf if [ $? -eq 0 ]; then complete=3 fi if [ $_in_dnsip2 != "" ]; then echo "nameserver $_in_dnsip2" >> /etc/resolv.conf fi if [ $complete -ge 3 ]; then echo "DNS update/reconfiguration complete and successful." echo " " echo "New Configuration: " echo " " cat /etc/resolv.conf echo " " echo "Exiting." fi fi #If they want to move it or not to /usr/local/bin if [ $ans == "y" ] || [ $ans == "Y" ]; then echo "Moving..." cp $basename /usr/local/bin/ chmod 755 /usr/local/bin/$basename fi
[Linux/Mono]C#: Execute Shell Commands (function)
by Chuck Kozler on Feb.14, 2009, under Computers, Linux/Unix, Programming, Ubuntu, Windows
Hi everyone,
This is a short function I wrote to execute a shell command in C#. This needs to be used with Mono on Linux but should run natively on Windows.
protected virtual bool RunCommand( string szCmd, string szArgs, int wait ) { if( szCmd == null ) return false; System.Diagnostics.Process myproc = new System.Diagnostics.Process( ); myproc.EnableRaisingEvents = false; myproc.StartInfo.FileName = szCmd; myproc.StartInfo.Arguments = szArgs; if( myproc.Start( ) ) { //Using WaitForExit( ) allows for the host program //to wait for the command its executing before it continues if( wait == 1 ) myproc.WaitForExit( ); else myproc.Close( ); return true; } else return false; }
If you’re viewing this page then this is pretty self explanatory.
Called as such:
if( RunCommand( "/usr/bin/zenity", "--warning", 0 ) ) Console.WriteLine( "Command ran" );
[Ubuntu]Troubleshooting HDA Intel Sound Problems
by Chuck Kozler on Feb.03, 2009, under Computers, Linux/Unix, Ubuntu
Alright, lately I have seen on the Ubuntu forums where people will receive a kernel upgrade and after they restart/reboot they no longer have sound. This tutorial is not EXPLICITLY for HDA Intel Sound cards and NOT EXPLICITLY for a case where someone receives a kernel upgrade then has no sound, but, because that is what I have seen repeatedly, I wrote it for those cards. This can be broadened to troubleshoot almost any sound device because of the commands used, such as “lshw” and “lspci”.
sudo lshw -C sound
lshw is a listing of your hardware in your system. The “-C” switch says to specify a class and “sound” is the class we are looking at. If you look at the output of lshw, it can almost tell you exactly what you need to do. For instance, here is the output of my lshw -C sound command.
[10:47:50][kozler@kozler-laptop:~]$ sudo lshw -C sound [sudo] password for kozler: *-multimedia description: Audio device product: 82801G (ICH7 Family) High Definition Audio Controller vendor: Intel Corporation physical id: 1b bus info: pci@0000:00:1b.0 version: 02 width: 64 bits clock: 33MHz capabilities: pm msi pciexpress bus_master cap_list configuration: driver=HDA Intel latency=0 module=snd_hda_intel [10:48:01][kozler@kozler-laptop:~]$
lshw is useful in showing if your hardware is showing a driver associated with that device or not. For instance:
*multimedia - DISABLED
Would mean the device is disabled.
*multimedia - UNCLAIMED
Would mean that the device does not have a device driver associated with it and you can continue with troubleshooting and reinstalling the driver.
*multimedia
Would mean that your device is assumed to be working fine and a driver is associated with it. lshw cuts a lot of time out of the guess work when it comes to troubleshooting hardware.
As you can see here:
configuration: driver=HDA Intel latency=0 module=snd_hda_intel
I am using the HDA intel driver. That first part can tell me a lot.
Another very useful command is the lspci command. Running:
sudo lspci -v
Will output all your PCI devices. You can run:
sudo lspci -v | grep -i audio
To identify your audio device area. Then, run “lspci -v” again and search for that section. For instance, mine looks like this:
[11:04:45][kozler@kozler-laptop:~]$ sudo lspci -v | grep -i audio 00:1b.0 Audio device: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller (rev 02) [11:04:50][kozler@kozler-laptop:~]$
So then I run “lspci -v” again and search for that section, then I find:
00:1b.0 Audio device: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller (rev 02)
Subsystem: Lenovo Device 2010
Flags: bus master, fast devsel, latency 0, IRQ 17
Memory at ee400000 (64-bit, non-prefetchable) [size=16K]
Capabilities:
Kernel driver in use: HDA Intel
Kernel modules: snd-hda-intel
So, once again, I can see that the HDA Intel driver is loaded and the module is loaded as well. So, now we know it probably comes down to some simple configuration problem.
First, run this command in a terminal:
alsamixer -c 0
and make sure nothing is muted or turned down all the way. I know for me, when I do a fresh install of Ubuntu, my surround sound speakers on my Desktop are all turned down except the front two speakers. It wasnt until a way down the line that I realized I had to open alsamixer and turn them all up. So, make sure to check this.
Now from here, open up sound settings located in:
System -> Preferences -> Sound
and you will see a screen like this:
Now, knowing you are using the HDA Intel driver by default, you drop down the “Sound Playback” area where it is by default set to “Autodetect” and you can do one of two things. For me, I have a few options:
HDA Intel AD198x Digital (ALSA)
HDA Intel AD198x Analog (ALSA)
HDA Intel AD198x Analog (OSS)
HDA Intel AD198x Analog (OSS)
HDA Intel AD198x Analog (OSS)
ALSA – Advanced Linux Sound System
OSS – Open Sound System
PulseAudio
I do not know why OSS HDA Intel is listed three times, but, it is. Now, its all about trial and error. Try each one and see which one works for you. To do this, drop down the “Sound playback” menu and select each device listed there. Then, click “Test”. Most likely, HDA Intel Analog (OSS) will work, but for me, ALSA – Advanced Linux Sound System is what I use on this laptop BUT HDA Intel 198x Analog (OSS) works for me as well. I prefer ALSA. On my Desktop, I can utilize the Nvidia ALSA Digital sound. You will receive one of these results from testing these.
1.) No sound output (remember to check the volume)
2.) An error message similar to this
If you get the second, then that selection will NOT work, what-so-ever. If you get no sound output from one of the HDA Intel selections then try ALSA or OSS selections. Pretty much, if the sound worked before, it will still work, you just need to reconfigure it.
Here are my test results:
HDA Intel AD198x Digital (ALSA) – NO SOUND
HDA Intel AD198x Analog (ALSA) – ERROR BOX (from above)
HDA Intel AD198x Analog (OSS) – SOUND
HDA Intel AD198x Analog (OSS) – SOUND
HDA Intel AD198x Analog (OSS) – NO SOUND (?)
ALSA – Advanced Linux Sound System – SOUND
OSS – Open Sound System – SOUND (seems to be louder than the rest)
PulseAudio – SOUND (seems to be equal volume output to OSS)
I wish I could explain why two of the HDA Intel AD198x Analog (OSS) work fine but the third one doesnt. Either way, I am not concerned with that, I am only concerned with having working sound. As you can see, one of the listings must work if it had worked before. Sometimes the autodetect doesnt work all the time or it autodetect fine for separate users or at the login screen. I prefer to set my own so I can avoid later problems and then if that selection no longer works, then I know the recent update actually broke something.
Sphere: Related Content[Ubuntu]Video Problems or BadAlloc Error when viewing movies FIX
by Chuck Kozler on Jan.27, 2009, under Computers, Linux/Unix, Ubuntu
We are going to observe a few cases here that generally all lead to the same solution.
Case 1:
This tutorial was sparked by a post on the Ubuntu forums where the user was having a problem viewing AVI’s, they would receive this error:
X11 error: BadAlloc (insufficient resources for operation) 2.1% 0 0
This error is usually thrown by X11 when, as the error says, there is insufficient resources to play the movie. This would of course happen with any other extension of movies as well. This is usually caused by Compiz.
Case 2:
Your video output will suddenly start to flicker in and out between black, your desktop, and the video you are watching. Not exactly in that order or pattern, I used that order as that is what happened to me on my laptop.
Case 3:
Your video output will suddenly start to distort. For me, on my laptop with ATI fglrx drivers installed and working properly, my video output turned into a cyclone of triangles. Kind of like a visualization was running.
There are one of two ways to solve these cases:
- Opening a terminal or alt+f2 to run a command and type:
metacity –replace
or
Modifying the output modules for movie players you use. Here I will show you how to edit properties for VLC and Totem (gstreamer).
VLC:
- Open VLC (Applications -> Sound/Video -> VLC )
- Click Tools
- Click Preferences
- Click the button at the bottom to show “All” settings
- Drop down the “Video” selection on the left
- Click Output modules
- On the right, drop down the menu where it says “default” and select “X11 video output”
Totem:
Either open a terminal (Applications -> Accessories -> Terminal ) or press alt+f2 and type
gstreamer-properties
Then, in the dialog that pops up, click the Video tab. Then drop down the “Plugin” menu under “Default Output” and select “X Window System ( No Xv )”
Exit the prompt by clicking Ok
Now try to play your videos again in either VLC or Totem. If requested, I can write one for MPlayer as well as some other video players.
Sphere: Related Content

