Wednesday, December 29, 2010

How to get mpg321 working with Fedora Core 14

mpg321 is a very popular command-line mp3 player for Linux platform. I use mpg321 for mp3 audio clips playback with Granule.

Needless to say, mpg321 has been a reliable piece of a very useful software for ages and it took me by surprise when all of the sudden, it began to crash left and right under my recently installed Fedora Core 14 that I run as VirtualBox's guest OS.

At first, I naturally assumed that VirtualBox was a culprit to my woes. However, a quick test with Rhythmbox ruled out that hypothesis of mine.

To make a long story short, mpg321 relies on a cross-platform audio library, libao, to play mp3 files. Recently, some internal data structure of libao changed when its latest release was let out in the wild, and mpg321 has not been updated to reflect the change (if you are interested, is a matter of backward compatibility issue entangled with  using uninitialized memory -- learn more from Bug #580062).

The workaround is to uninstall the official mpg321 release, and then download and compile the source code yourself:
  • Uninstall official mpg321,
    sudo rpm -e mpg321
    
  • Download latest source code for mpg321 from its Source Forge download page.
  • Unpack the source code:
    tar xvfz mpg321-0.2.21-1.tar.gz  
  • Install dependency development packages:
     sudo yum -y install libmad-devel libid3tag-devel
    
  • Configure, compile, and install mpg321
    cd mpg321-0.2.21-1
    configure
    make
    sudo make install
    
  • You should have now problem now playing your mp3 files:
    mpg321 music.mp3

Monday, December 20, 2010

RedHat Linux VNC server setup with GDM

Preamble

This blog will guide you to setup your Linux headless remote desktop with VNC sessions of different screen resolutions.

VNC stands for Virtual Network Computing. Connecting to remote headless Linux server implies running a remote Linux desktop session, namely, GNOME desktop.

I had great success with TightVNC client (available for Windows, MacOS, and Linux) over a number of years.

Install Software Packages

$ sudo yum install xinetd
$ sudo yum groupinstall "GNOME Desktop Environment"
$ sudo yum install tigervnc-server

The last package installs following executables:

/usr/bin/Xvnc
/usr/bin/vncconfig
/usr/bin/vncpasswd
/usr/bin/vncserver
/usr/bin/x0vncserver


vncserver is the daemon. Each connection to a remote desktop client is served by Xvnc instance.

Configure GDM

GDM is the GNOME Display Manager -- a graphical login greeter. This configuration runs GDM in the background on a headless (no X-Server) Linux host. This kind of configuration would be useful for a data server hidden away in your basement.

In order to setup remote GDM invocation, we need to enable XDMCP protocol. XDMCP protocol stands for X Display Manager Protocol. It is used by the X servers to communicate among each other in the UNIX world.
  • Edit /etc/gdm/custom.conf
    • Within the file find [xdmcp] section and set Enable to 'true'
      • Enable=true
    • Fix the RemoteGreeter bug. Somehow, GDM cannot pick up the path to greeter. In [greeter] section add simple-greeter location:
      • [greeter]
      • RemoteGreeter=/usr/lib64/gdm/simple-greeter
    • To turn off the X Windows session, find [servers] section and comment out the following line
      • #0=Standard
Setup xinetd Service

Linux xinetd service is a secure internet service daemon -- a sort of a service gateway to your Linux server. You bind a specific service to a specific port number (address) and when connection request comes in, xinetd starts that service on your behalf.

In our case, a VNC client (TightVNC) knows how to communicate with VNC server over XDMCP protocol. All we need for TightVNC to work is to add port number binding to the VNC server instantiation via xinted. Each binding offers a remote desktop service with different screen resolution.
  • Under /etc/xinted.d/ directory, create vnc1920 file:
service vnc1920
{
 disable     = no
 socket_type = stream
 protocol    = tcp
 group       = tty
 wait        = no
 user        = nobody
 server      = /usr/bin/Xvnc
 server_args = -inetd -broadcast -query localhost -geometry 1920x1200 -depth 16 -once -fp unix/:7100 -securitytypes=none
}
  • Note here that the color depth can be set to 8, 16, 24, and 32 bits. You might want to create different service entries with different color depths to learn which one is best for you.
  • Create similar service files for other screen resolutions
 vnc1024 for 1024x768       
 vnc1280 for 1280x1024     
 vnc1680 for 1680x1050     
    • Edit /etc/services file and bind service files you have created above with the port numbers
    vnc1024 5900/tcp
    vnc1280 5901/tcp
    vnc1680 5902/tcp
    vnc1920 5903/tcp

    The port number resolution is HOST-IP:0 for 5900, HOST-IP:1 for 5901 and so on.

    Restart xinetd service
    • sudo /sbin/service xinetd restart
    Start Remote Desktop Session

    From your desktop, start TightVNC client and try to connect to HOST-IP:0 or HOST-IP:1.

    Sometimes, you would need to restart your server in order for all services to bounce nicely.

    End Remote Desktop Session

    One thing to remember is to never end your GNOME remote desktop session with Actions->Log out. Instead, close the session down by clicking on [x] windows adornment button in the left top corner.

    References

    Other VNC tutorials you might find useful:

    Monday, November 15, 2010

    How to hide VirtualBox menu and status bars

    VirtualBox machine window is adorned with menu bar at the top and status bar at the bottom. You can hide both to save on valuable disk space.

    For Windows XP Desktop (Host):
    • If not already, add VirtualBox executable path to your %PATH% environment variable in Windows:
      • Bring System Properties dialog with My Computer->Properties->Advanced
      • Click on Environment Variables
      • Edit Path system variable and add C:\Program Files\Oracle\VirtualBox path. 

    • Under Windows:
      • From Start button, run 'cmd' command to open command shell.
      • To modify global configuration settings of the VirtualBox, type in the command:

    C:\> VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar

    When you restart next time your Guest Virtual Machine, you should get optimized view.

    To bring back the menu popup, press the Host key and Home key. My Host key is mapped to Right Ctrl, so the combination would be {Right Ctrl}-{Home}.

    Thursday, November 11, 2010

    Configure VirtualBox Host-to-Guest ssh port forwarding with NAT

    My Host OS : WindowsXP
    My Guest OS: is Linux Fedora Core.

    By default, VirtualBox sets up new Guest with NAT (Network Address Translation) configuration.

    NAT configuration forms a private network between Host and the Guest. The Host takes a role of a router that maps the incoming/outgoing traffic of a NAT Guest transparently.

    The annoying fact, however, is that this private network is not visible even from the Host machine. With default settings I cannot ssh or sftp from WindowsXP Host to Linux Guest. None of the network services such as Apache web server, or ssh daemon, or my own services that I might want to run on the Guest are visible to the outside world, including the Host itself.

    This is a major inconvenience that defeats the purpose of running various virtual Guests in a first place.

    To overcome this obstacle, we need to enable NAT port forwarding.

    Essentially, with port forwarding, we ask NAT engine to route external traffic that arrives on a certain port of a Host to a different port on Guest.

    The ssh daemon that runs on my Linux Guest listens for incoming connection requests on port 22. We are going ask NAT to route external traffic that arrives on port 2222 to the Guest's 22.

    The preparation steps:
    • Shut down Linux Guest
    • Exit VirtualBox application
    • Add VirtualBox path to %PATH% variable:
      • Bring System Properties dialog with My Computer->Properties->Advanced
      • Click on Environment Variables
      • Edit Path system variable and add C:\Program Files\Oracle\VirtualBox path.
    To setup port forwarding: 

     c:\> VBoxManage modifyvm "salmon" --natpf1 "guestssh,tcp,,2222,,22"

    Where:
    • 'tcp' is mandatory protocol type (could be 'udp' as well)
    • 'guestssh' is a description name that can be used to identify and remove the port forwarding
    • The first skipped generic parameter between commas of "tcp,,2222" is external interface IP. By default, all traffic that might arrive on port 2222 of every network interface (localhost, LAN, WiFi, etc.) is routed to port 22 of the Guest. However, you can be more restrictive, and say allow only local traffic from 127.0.0.1 to be routed to the Guest.
    • The second skipped generic parameter between commas of "2222,,22" is used to specify static IP address of the Guest if it is assigned one by VirtualBox in favor of dynamically-assigned DHCP address.
    To remove port forwarding:

    c:> VBoxManage modifyvm "salmon" --natpf1 delete "guestssh"

    To test the connection:
    • Boot the Guest OS.
    • Login in to Linux and make sure the sshd daemon is running.
    • On Windows XP desktop,
      • Start WinSCP free scp/sftp client.
      • Connect to IP: 127.0.0.1 Port: 2222
    You should be able to login now into your Guest and transfer files.

    Source: VirtualBox Manual  

    Tuesday, November 9, 2010

    FedoraCore VirtualBox Guest setup

    How to setup FedoraCore Guest in VirtualBox inWindowXP host.
    • Download VirtualBox installer from Oracle web site and install Oracle VM VirtualBox.
    • Launch Oracle VM VirtualBox.
    • Change the default Folder location for HardDisk and Machine:
      • Go to File->Preferences->General
      • Change location of Default Hard Drive Folder.
        • c:\MyStuff\VirtualBox\HardDisks
      • Change location of Default Machine Folder.
        • c:\MyStuff\VirtualBox\Machines
    • Create new virtual machine:

      • Click on New icon.
      • On Welcome screen, click Next.
      • On VM Name and OS Type screen, enter
        • Name: salmon
        • OS Type:
          • Operating System: Linux
          • Version: Fedora
        • Click Next
      • On Memory screen, 
        • set the Base Memory Size to 1024 MB.
        • Click Next
      • On Virtual Hard Drive screen
        • Check Boot Hard Drive
        • Select Create new hard disk
        • Click Next
      •  On Hard Disk Storage Type screen
        • Select Dynamically allocated
        • Click Next
      • On Virtual Disk Location and Size screen
        • Make sure the location of salmon is under c:\MyStuff\VirtualBox\HardDisks
        • Set the initial size to 32 GB (10GB is the bare minimum).
        • Click Next
      • On Summary screen
        • Click Finish
    • Adjust Virtual Machine salmon settings
      • Click on Setting icon
      • In salmon - Settings screen 
        • Select System/Motherboard tab 
          • Under Boot Order section
            • Uncheck Floppy entry
          • Under Extended Features
            • Leave Enable IO APCI unchecked
        • Select System/Acceleration tab 
          • Make sure 
          • VT-x/AMD-V is enabled
          • Nested Pages is enabled

        • Select Display/Video tab
          • Enable 3D Acceleration
        • Select Display/Storage tab
          •  Under Storage Tree in IDE Controller, select Empty CD icon.
          • To install directly from physical Fedora i386 DVD, you need to connect a physical host device (such as DVD drive) to your virtual machine. For that, under Attributes:


            • Click on a little DVD icon to the right of the CD/DVD Drive selection. Click on "Host Drive D:".  The IDE Controller child entry will change to 'Host Drive D:' selection.
            • Select Passthrough option. 

        • Select Audio tab.

          • Check 'Enable Audio' box
          • Select 'Windows DirectSound' audio driver
          • Select 'ICH AC97' audio controller
    • Insert Fedora Core DVD disk in DVD drive.
    • Click on the Start button to begin installation
      • Set Hostname to your Host machine name (with full domain name)
      • Choose Customize now option and select
        • Choose GNOME Desktop Development
        • Under Applications select
          • Authoring and Publishing
          • Editors
          • Graphics Internet
          • Graphics
          • Office/Productivity
          • Sound and Video
          • Text-based Internet (for wget)
        • Under Development select
          • Development Libraries
          • Development Tools
          • Fedora Packager
          • GNOME Software Development
          • Web Development
          • X Software Development
        •  Under Servers select
          • MySQL Database
          • Network Servers
          • Printing Support
          • Server Configuration Tools
          • Web Server
          • Windows File Server
        • Under Base System in addition to defaults, select
          • Administration Tools
          • System Tools
        • Under Languages
          • add Russian Support
      • Continue with installation (grab a sandwich or something...). This will take a while.
    • Reboot after installation is complete and
      • Create user account
      • Setup Network Time Protocol server
      • Enable sudo access for your login account:
        • $ su -
        • Password: {your superuser password}
        • # /usr/sbin/visudo
        • {edit /etc/sudoers file and add} 
          • {username}  ALL=(ALL) ALL


    • Install Guess Additions
      • Guest Additions add very useful functionality:
        • X server driver with higher screen resolution
        • Seamless cut-n-past between Host and Guest OSes
        • Mouse driver that integrates host and virtual desktop spac
            To install Guest Additions:
      • Install development tools to be able to compile kernel drivers:
        • # yum groupinstall "Development Tools"
      • Check if running guest VM window has its menu bar at the top shown. If not, shutdown the VM machine and re-enable it for the guest.
      • In the Oracle VM VirtualBox menu, click on Devices->Install Guest Additions 
      •  
      • In the Guest Virtual Machine (VM), GNOME desktop will detect new media inserted, VBOXADDITIONS_3.2.10_66523.
      • Click Cancel to dismiss the dialog.
      • Open terminal with Applications->System Tools->Terminal

      • $ cd /media/VBOXADDITIONS_3.2.10_66523
      • $ sudo sh ./VBoxLinuxAdditions-amd64.run
      • When Guest Additions installation is complete, right click on CD icon on the desktop and Eject it.
      • Release the cursor and in the Oracle VM VirtualBox menu, click on Devices->CD/DVD Devices click on 'Host Drive D:' to unmount GuestAdditions.iso image.
      • In the Virtual Machine, edit /etc/X11/xorg.conf to add screen resolutions that matches your primary desktop/laptop screen.
        $ sudo vi /etc/X11/xorg.conf
        
        Section"Screen"
        SubSection "Display"
        Modes "1900x1200" "1280x1024" "1024x768" "800x600"
        Depth 24
        EndSection
        ...
        EndSection
        
      • Reboot the Virtual Machine. Now you should have the resizable desktop with fullscreen mode available as well. 
    • From you account in the VM, 
      • Disable Firewall.
      • Set SELinux mode to Permissive.
    • To setup USB pass-through support,
      • In the Linux guest VM, Create 'usb' group and add yourself as a user to that group.
      •  Shut down guest VM
      • In the VirtualBox window manager, select the virtual machine and open its Settings dialog.
      • Under USB settings,
        • Enable USB Controller
        • Enable USB 2.0 (EHCI) Controller
        • Add a USB Device Filter
        • Enable the filter
        • Edit filter details and set Remote to 'Any'

      • Restart the guest VM
      • When Linux desktop appears, have focus on the desktop
      • Insert the USB stick.
      • First time around, Windows XP would detect a new hardware profile. Go on with driver installation to install VirtualBox USB driver.
      • In the guest VM, under Devices tab, select the USB stick.
      • The USB device should appear on your Linux desktop as icon.

      • NOTE: For a while, I was getting this error from VirtualBox's guest VM:
        USB device SanDisk USB U3 Cruzer with 
        UUID [some id] is busy with a previous request. 
        Please try again later.
        
        Result code: E_INVALIDARG (0x80070057)
        Component:   HostUSBDevice
        Interface:   IHostUSBDevice {some id}
        Callee:      IConsole {some id} 
        In my case the error was ultimately resolved by creating the "usb" group under guest VM as outlined above. For further information, please, refer to VirtualBox bug #3033 (USB device not available to Guest)

    Strip leading path with GNU tar

    Sometimes, when I untar an archive file, I need to strip leading path from the archived files. For example, if my archive is stored on a DVD disk the following command would unpack it to my home directory and strip the leading path name:

    shell> cd $HOME
    shell> tar --extract --file /mount/Backups/home-bkp-11082010.tar.gz --strip-components=1 

    Essentially, if my original backup had a  file vlg/foobar.txt, the vlg/ part of the path would be stripped out.

    This comes very handy if the backup file was created with something like:

    shell> cd /home
    shell> sudo tar xvfz home-bkp-11082010.tar.gz vlg