Easing console use with the mouse and shortcuts

Often times those who spend most of their time in a gui fail to see the benefit of having a mouse in Linux available at the console. What good does a mouse do in the console they question having used DOS extensively at some point in their life.

Well the mouse in a linux console can do a wide variety of things, typically the significant and most useful is the same that the mouse provides in the windowing interface– cut and paste.

On most distributions it’s a good choice to use the package manager to install GPM because it can cause conflicts with the X servers control of the mouse and the package manager typically takes care of these conflicts by terminating GPM before starting x and restarting it when x stops.

On Debian (and apt-based distributions) you can install GPM by doing the following command:

aptitude install gpm mdetect

On most redhat (or rpm based distributions based off Redhat) you can install GPM by doing the following command:

yum install gpm

In never versions of the kernel there is some experimental mode to make mice ‘just work’ but it’s a bit flaky at this point and typically you’re far better off with GPM.

If you’re stuck working extensively with the local console and screen you will find this tool to be indispensable especially as you get into the advanced options of remapping the effect of each key on the mouse.

Since this post is a bit light on indepth information, lets show you how to make a command in bash that will untar/unzip/unrar all the common formats you deal with. To ensure it works you do need bzip2, gzip, tar, unrar, uncompress, and unzip on your system and after seeing how it works you’ll easily be able to add additional compression types to deal with or remove the ones you don’t.

extract () {
  if [ -f $1 ] ; then
      case $1 in
          *.tar.bz2)   tar xfvj $1    ;;
          *.tbz2)      tar xfvj $1    ;;
          *.bz2)       bzip2 -d $1    ;;
          *.tar.gz)    tar xfvz $1    ;;
          *.tgz)       tar xfvz $1    ;;
          *.gz)        gzip -d $1     ;;
          *.tar)       tar xfv $1     ;;
          *.Z)         uncompress $1  ;;
          *.rar)       unrar x $1     ;;
          *.zip)       unzip $1       ;;
          *)           echo "'$1': unknown file compression" ;;
      echo "'$1' is not understood, install the correct interpreter and update your .bashrc"

To use it–

extract file.ext

It will save you remembering the syntax for a dozen commands you don’t frequently need (although some you probably know already.)

Pantek Managed Services

Converting a physical Linux machine to an ESX image (P2V ) using Converter Standalone

This procedure is specific to converting physical Linux machines to ESX Infrastructure virtual machines.

It may not work reliably with certain versions of Linux source machines.

See note* regarding Debian source, or any source running only lilo.

Converting a physical host using VMware Converter Standalone requires a server to run VMware Converter Server on. The converter server can be the ESX server, or another server, even the source. Depending on the source and destination locations, it might make the most sense to install converter server onto the source Linux machine, as this seems to be the fastest method when the source and destination are on the same subnet. Installing the Converter Standalone package on ESXi is a problem as by default there is no command line to work from. The following assumes the ESX server, and the steps begin at the server command line, after logging in as vmware, then su –

  • Download the latest Linux version of Converter Standalone from the VMware Web site.
    • The Linux installer file name is currently VMware-converter-4.0.1-xxxxxx.tar.gz, where xxxxxx is the build number.
  • Unpack the tar.gz file
    • tar -xvf VMware-converter-4.0.1-xxxxxx.tar.gz
  • In terminal, navigate to the unpacked directory:
    • cd vmware-converter-distrib
  • Run the installation executable file:
    • ./vmware-install.pl
  • Get past the Licensing
    • To view the VMware’s patent list, press Enter.
    • To view the End User License Agreement, press Enter.
    • To accept the license agreement, scroll down the document, type “yes” and press Enter.
  • Do you want to install Converter Standalone Client? yes
  • Do you want to install Converter Standalone Server? yes
  • In which directory do you want to install the executable files? /usr/local/bin
  • In which directory do you want to install the VMware vCenter Converter Standalone library files? /usr/local/lib/vmware-vcenter-converter-standalone
  • The path “/usr/local/lib/vmware-vcenter-converter-standalone” does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? yes
  • What is the directory that contains the init directories (rc0.d/ to rc6.d/)? /etc/rc.d
  • What is the directory that contains the init scripts? /etc/rc.d/init.d
  • Do you want to enable remote access in Converter Standalone Server? yes
  • What port do you want the HTTP proxy to use? 88
  • What port do you want the HTTPS proxy to use? 488
  • In which directory do you want to install the theme icons? /usr/share/icons
  • The path “/usr/share/icons” does not exist currently. T his program is going to create it, including needed parent directories. Is this what you want? yes
  • What directory contains your desktop menu entry files? These files have a .desktop file extension. /usr/share/applications
  • Please wait while copying VMware vCenter Converter Standalone files…
  • Converter Standalone Server script is located at /etc/init.d/ directory by default. To start, stop or restart Converter Standalone Server, type
    /etc/init.d/vmware-server start/stop/restart.
  • NOTE: To uninstall
  • Start the server
    /etc/init.d/vmware-server start
  • Modify firewall config (This applies to ESX, which has a rest rictive firewall. ESXi has no firewall. If you installed converter server on the source, the only connection that will apply is incoming on port 88 and 488 from the converter client to the converter server, and outgoing from the converter server to 80/443 on the destination ESX/ESXi.
    • Must allow outgoing ssh from converter server to t he source
    • Incoming to http and https port on converter server that was used in the initia l install
    • Outgoing from converter server to port 80/443 on the destination (ESX) (same machine in this instance)
    • esxcfg-firewall -e sshClient
    • esxcfg-firewall -o 88,tcp,in,ConverterServer
    • esxcfg-firewall -o 488,tcp,in,ConverterServerSSL
    • esxcfg-firewall -o 443,tcp,out,HTTPS
    • esxcfg-firewall -o 80,tcp,out,HTTPS
  • In the client
    • Download the converter for windows, and install. This will be run as a client only, contacting the converter server installed above.
    • In the menu, under Administration, connect to another server.
    • Enter the IP address or host name of the Converter Server
      • IP Address / Name:
        • convert.server.ip.address:488 (or port chosen above during server installation)
        • username: root
        • password: xxxxxxxx
    • click on convert machine
    • type in ip address, username, and password
    • click next (will take some time)
    • Destination section
      • Type server IP
      • Click next
      • select a level in the inventory to place the guest image
      • name the guest host
      • select the datastore
      • next (will take some time to verify the destination)
      • edit options
        • under data to copy
          • select the source volumes desired (all are selected by default).
          • to grow a disk, select the dropdown under ‘target size’, and choose to enter the size in GB.
          • If it is desired to shrink a disk, any size can be chosen, as long as it is at least as large as the source used space.
        • under networks
          • select how many nics to connect, and where they connect to, and whether they should be connected at power on (1,vm network, no)
        • under advanced options
          • select whether it is desired to power on the target or power off the source (no), and also if it is desired to configure the new vmware guest (since the source is still running at this point it would be recommended to not power on the destination, or to select to not connect network interfaces at power on)
        • under helper vm network
          • enter an IP address,subnet,gateway,and DNS server separate from the address of the destination or source (an address we set aside to use for temporary images perhaps) This should be in the same subnet as the destination server.
            • 192.168.X.254
            • 192.168.X.X
            • 192.168.X.X
        • It was discovered that there is a bug in vmware that causes a guest with more than one CPU to hang at ‘starting udev’… The only workaround I was able to determine was to either configure the destination image as only using one cpu, or add udevtimeout=30 to the kernel boot line in /boot/grub/menu.lst. I would recommend configuring the destination image with only one CPU
        • This should do it for setup, now click next. If there are no errors, it should begin.
        • Once it is finished, the created image could be powered on or configured further. The danger of course would be in turning on the interfaces, if they were to take over the ip of the source that was cloned.
  • In VSphere client
    • Before starting the image, right-click the guest, edit settings, options, boot delay, and set to 10000ms. This gives enough time to see the grub menu if needed.
    • Select VMware tools/Synchronize guest time with host
    • Once the image is booted
      chkconfig --del ntpd
    • right click guest, select guest/install vmware tools
  • Back on the server image
    • mkdir /mnt/cdrom
    • mount /dev/hda /mnt/cdrom
    • cd /mnt/cdrom
    • If it is rpm based machine
      • rpm -ivvh VMwareTools-4.0.0-171294.i386.rpm
      • after it is completed, run
    • For source install
      • mkdir /root/vmwaretools
      • tar -zxvvf VMwareTools-4.0.0-171294.i386.tgz -C /root/vmwaretools
      • cd /root/vmwaretools/vmware-tools-ditrib
      • ./vmware-install.pl
      • answer questions
    • On the vmware guest, it may be necessary to remove any mac address references from the network configuration. As the new image will use a different mac address. This should be done in the appropriate /etc/network/interfaces or /etc/sysconfig/network-scripts files.
  • Power on guest
      • source root password must not contain a backslash character
      • source cannot contain both ide and scsi disks
      • source should be time synced to the dest before conversion
      • source cannot contain software raid volumes
      • lilo bootloader sources must have grub installed
        • The procedure to install grub on a debian server, temporarily or permanently to allow this process to work is as follows
          • apt-get install grub
          • mkdir /boot/grub
          • update-grub
          • install-grub
          • Lilo can be reinstalled later by running the lilo command

GNU Screen

The concept of GNU screen is simple. It allows you to have multiple terminals open in a single session that can persist through sessions, disconnects, and logouts.

GNU Screen solves a lot of problems commonly encountered by professionals, having trouble staying connected to a system with a bad link? Screen your session and just reattach and never lose the work you’ve already done.

Want to continue work from home that you started at work? Screen your session, disconnect when you are finished at work, and reattach when you get home and continue where you left off.

Additionally GNU screen can let someone else watch, and interact, with your screen while you perform work for them making it a great tool for training new administrators.

GNU Screen works on most Unix, Linux, and even MacOS X, so it’s a versatile tool that is available almost anywhere you might find yourself working. Lets get started using screen…

Verify GNU screen is installed and if not install it however your distribution suggests.

To use screen type: screen

Depending on the exact default options on your system this may display an information page about screen that you need to use a key press to dismiss or this may simple appear to do nothing except bring you back to the prompt.

To see if your screen is running you can type: screen -list

This will return a display of all running screens you have access to and will look like this:

server:~# screen
server:~# screen -list
There is a screen on:
26512.pts-0.core (10/16/2009 02:54:42 PM) (Attached)
1 Socket in /var/run/screen/S-root.

The two most relevant pieces of information are the process ID (26512 in this case) and the status of the screen (Attached) in this case. What this means is you are currently interacting with this screen session. Lets start a simple process in the screen to demonstrate what it can do. Type the following:

for i in `seq 1 17280`; do echo $i; sleep 5; done

Normally, if you sat and watched this extremely entertaining count from 1 to 17280 it would take approximately 24 hours… but as exciting as it may be, you have other things to do and need the count to finish for you, so what can you do? Since we’re running in a screen we can detach from the screen session.

Press CTRL-a d and you will be sitting back at the prompt.

If you issue a screen -list now you will see the following output:

server:~# screen -list
There is a screen on:
26512.pts-0.core (10/16/2009 02:54:41 PM) (Detached)
1 Socket in /var/run/screen/S-root.
server:~# screen

The “detached” status means the screen is still running and the time is still going forward just like you were watching that exciting count, but you are free to do other things. You can start another screen session too just in case you find yourself needing to leave your current project and come back to that at a later date. So type screen again. Just for demonstration sake, go ahead and hit CTRL-a d to detach this idle screen also.

Normally if you type screen -r and only have a single screen running you will automatically reattach to the running screen. Which is pretty convenient. However if you have multiple screens running screen needs to know which screen you want to attach to so lets take a look at the how to do that first lets list our screens.

server:~# screen -list
There are screens on:
27296.pts-0.core (10/16/2009 03:11:12 PM) (Detached)
26512.pts-0.core (10/16/2009 02:54:42 PM) (Detached)
2 Sockets in /var/run/screen/S-root.

The start time on the screens tell us which is which and since it’s been a while lets check on our exciting count… In my case we would type:

server:~# screen -r 26512

and what you’ll see is a screen full of numbers… the count has been progressing without us and its showing just like we had never left the terminal in the first place. Detach the screen by pressing CTRL-a d.

That brings us to an issue with screen… who can possibly remember what and when they started each screen process and for what reason. Well screen lets you name its sessions!

If you’re starting a new session and know what you want to use it for you can simply start screen like this:

server# screen -S mail

which would give our screen session the name of ‘mail’, however, often as not it’s more useful to name a screen that is already in use. Lets give our count session a name:

server:~# screen -r
There are several suitable screens on:
27620.mail (10/16/2009 03:18:02 PM) (Detached)
27296.pts-0.core (10/16/2009 03:11:12 PM) (Detached)
26512.pts-0.core (10/16/2009 02:54:42 PM) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
server:~# screen -r 26512

The count of the numbers displays on the screen and i press: CTRL-a :sessionname count and then I detach my screen again via CTRL-a d.

Now when I perform my list of screens I see the following:

server:~# screen -list
There are screens on:
27620.mail (10/16/2009 03:18:02 PM) (Detached)
27296.pts-0.core (10/16/2009 03:11:12 PM) (Detached)
26512.count (10/16/2009 02:54:42 PM) (Detached)
3 Sockets in /var/run/screen/S-root.

If I wanted to resume count or mail it would be as simple as typing screen -r count or screen -r mail.

The way you kill a screen is simple, attach to it, and type: exit or press CTRL-d on most versions of Linux and Bash. If necessary you can also kill it by executing a screen -k PID

If as root you wanted another person logged in as root to review something in your attached screen session they could do so by typing: screen -x and they would see what you were seeing and could type into your session. This is sometimes useful when showing someone an error you don’t want to repeat or having them give you assistance when you’re stuck but need training on the particulars of the item in question.

I have only barely touched on the most basic of screens functions, it can open multiple windows inside itself (think tabs in a browser), it can be attached locally or remotely, it can run alternate shells, it can log its session, and many, many, many more things. GNU Screen is one of the most versatile tools in *nix for administration and general use.

There is a lot more to screen than the basic usage I’ve covered and you can discover a lot of additional short cuts and functionality by reading the screen man page (man screen). Use it before long compiles, use it before system updates, use it before anything that might cause major issues if you are disconnected midway through and GNU screen will quickly become a tool you can’t live without!