October 30, 2012

Windows 8 and Ubuntu 12.10 dual boot issue

I recently bought a HP Envy dv4 laptop for work. It came with Windows 8, and I wanted to install Ubuntu 12.10 Server on it. Here is the problems I ran into and how they were solved:

1. Internal CDROM install did not work correctly. First I thought it was because the CDROM was broken. Later on I found out that legacy BIOS support is not enabled in the UEFI. Once Legacy support is enabled in UEFI, installing from CDROM worked fine.

2. Ubuntu 12.10 64-bit did not detect that the system is using UEFI and installed GRUB-PC(which is for the old BIOS/MBR) instead. So after installation the system booted straight into Windows 8 with no  option to boot into Linux.

3. I downloaded the Boot Repair and ran it. It uninstalled the grub-pc and installed grub-efi but at the end it stated that error occurred and suggested that I move the Linux into the first partition. This was not an easy option for me. So the system still cannot boot into Linux.

4. What saved the day was the tool called "rEFInd" found in  This Post . The actual website is located at HERE. A great piece of software with clear instructions. So I booted into Windows 8 and followed the instruction listed under "

Installing rEFInd Manually Using Windows"


5. It worked great!! Later on I used the "bcdedit" command to set the boot manager to grubx64 directly and it worked as well.

Thanks Rod!


October 23, 2012

How to Tell if Your CPU supports Virtulization Technology on Linux


It’s quite simple: We’ll need to take a peek inside the /proc/cpuinfo file and look at the flags section for one of two values, vmx or svm.
  • vmx – (intel)
  • svm – (amd)
You can use grep to quickly see if either value exists in the file by running the following command:
egrep ‘(vmx|svm)’ /proc/cpuinfo
If your system supports VT, then you’ll see vmx or svm in the list of flags. My system has two processors, so there are two separate sections:

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm
VT technology can still be disabled in your computer’s BIOS, however, so you’ll want to check there to make sure that it hasn’t been disabled. The flags in cpuinfo simply mean that your processor supports it.


Source: http://www.howtogeek.com/howto/linux/linux-tip-how-to-tell-if-your-processor-supports-vt/

October 12, 2012

vmware and virtualbox usb device in use not able to attach to VM

If you have a USB device that cannot be detached from the HOST and attach to your VM, one possible reason is because you are using USB 3.0 port the device. Change to a USB 2.0 port should help in that case. This was my case with Windows 7 running on Thinkpad T530.

September 19, 2012

Resolve IP Fragmentation, MTU, MSS, and PMTUD Issues with GRE and IPSEC


Resolve IP Fragmentation, MTU, MSS, and PMTUD Issues with GRE and IPSEC


Excerpt:

Avoiding IP Fragmentation: What TCP MSS Does and How It Works

The TCP Maximum Segment Size (MSS) defines the maximum amount of data that a host is willing to accept in a single TCP/IP datagram. This TCP/IP datagram may be fragmented at the IP layer. The MSS value is sent as a TCP header option only in TCP SYN segments. Each side of a TCP connection reports its MSS value to the other side. Contrary to popular belief, the MSS value is not negotiated between hosts. The sending host is required to limit the size of data in a single TCP segment to a value less than or equal to the MSS reported by the receiving host.
Originally, MSS meant how big a buffer (greater than or equal to 65496K) was allocated on a receiving station to be able to store the TCP data contained within a single IP datagram. MSS was the maximum segment (chunk) of data that the TCP receiver was willing to accept. This TCP segment could be as large as 64K (the maximum IP datagram size) and it could be fragmented at the IP layer in order to be transmitted across the network to the receiving host. The receiving host would reassemble the IP datagram before it handed the complete TCP segment to the TCP layer.

September 18, 2012

vboxheadless does not listen on VRDE port

vboxheadless in virtualbox is really good, but it does not report error messages very well. If you see it running but does not listen on the VRDE port, there is a chance that you have the following issue:

This supposes that your host is Linux.

Your host may have loaded the linux KVM modules, which conflicts the VirtualBox.  Do a "lsmod" to see whether you have the following modules installed:


 kvm_intel
 kvm

If you do, "rmmod" them. To make it permanent, put them in /etc/modprobe.d/blacklist.conf


September 14, 2012

debug udev rules

To debug your udev rules, just run udevd as:

udevd --debug

Keep in mind that some udevd cannot detect changes in rule files so make sure you restart udevd after rule changes.

Qt embedded Linux usb keyboard auto detect

Qt in embedded Linux can detect the plug/unplug of an USB Mouse and enable it when USB mouse is plugged in. For USB keyboard, it does not support such capability.

To solve this problem, I have to resort to qt plugin. The following links will provide all the necessary material to write and deploy a plugin.

The plugin is a dynamic library that qt app looks for when it starts. In this case, the "customized qt keyboard driver" is located at qt-binary-directory/kbddrivers/libhotplugkbplugin.so. Before start the app, set the key board environment variable:


export QWS_KEYBOARD="HotPlugKb"

The plugin is based on the simplestyle plugin below structure-wise and based on the qt internal linuxInput driver function-wise.


http://doc.qt.nokia.com/4.7-snapshot/qkbddriverplugin.html
http://qt-project.org/doc/qt-5.0/deployment-plugins.html
http://doc.qt.nokia.com/4.7-snapshot/plugins-howto.html
http://doc.qt.nokia.com/4.7-snapshot/tools-styleplugin.html
http://doc.qt.nokia.com/4.7-snapshot/qt-embedded-charinput.html

Debugging Plugins

export QT_DEBUG_PLUGINS='2'

September 7, 2012

Makefile and autoconf/automake gcc version check

Makefile:

GCC_VERSION_GE_45 := $(shell g++ -dumpversion | gawk '{print $$1>=4.5?"1":"0"}')
ifeq ($(GCC_VERSION_GE_45),1)
    AM_CXXFLAGS +=-Wunreachable-code
endif

Note the use of double $ sign inside gawk script.


In Autoconf/Automake:
1. Add the following line to configure.ac
  AM_CONDITIONAL(GCC_GE_45, test `g++ -dumpversion | gawk '{print $1>=4.5?"1":"0"}'` = 1)

2. Add the following line to Makefile.am
  include $(top_srcdir)/common.mk

3. Add the following lines to common.mk
if GCC_GE_45
    AM_CXXFLAGS +=-Wunreachable-code
endif

September 6, 2012

buffer overflow example and gcc flags

If you want to try some buffer overflow examples online, make sure you compile your C code with the gcc flag:

     -mno-accumulate-outgoing-args 

otherwise your assembly code may look different than the assembly code on the book. Read more at this Stackoverflow post

August 30, 2012

hg serve multiple projects


1. Create a file under the parent directory of the multiple project hg directories
Example:
#> cat webconf
[collections]
repos/ = .

[web]
allow_push = *
push_ssl = false


2.  hg serve --web-conf ./webconf -d

debian add key


sudo gpg --keyserver subkeys.pgp.net --recv-keys 55BE302B
sudo gpg -a --export 55BE302B | sudo apt-key add -

August 29, 2012

vim man page skip command line

In vim, when you want to get the man page of the word under the cursor, you can just type shift-k or "K". However, for some functions, there is a "command line" tool with the same time, so you will get the man page for that command line instead of the function you are looking for.

For example, if you hit "K" on "unlink", you will get the bash unlink man page instead of the system call unlink(). To solve this problem, put the following line in your .bashrc:

    export MANSECT=3,2,1,4,5,6,7,8,9

This tells man to search section 3 first, then section 2, then section 1, etc., thus solved the problem of section 1 coming up before section 2 or 3.

While on this topic, you can also add the following line to your .bashrc file to make your man page have colors. Make sure you installed the program "most" on your computer.


    export MANPAGER="/usr/bin/most -s"

Or you can use the default "less" program and add the following lines to .bashrc to make "less" colorful:


man() {
 env \
  LESS_TERMCAP_mb=$(printf "\e[1;31m") \
  LESS_TERMCAP_md=$(printf "\e[1;31m") \
  LESS_TERMCAP_me=$(printf "\e[0m") \
  LESS_TERMCAP_se=$(printf "\e[0m") \
  LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  LESS_TERMCAP_ue=$(printf "\e[0m") \
  LESS_TERMCAP_us=$(printf "\e[1;32m") \
   man "$@"
}

August 23, 2012

Flags to enable thorough and verbose g++ warnings


Flags to enable thorough and verbose g++ warnings


-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror-Wno-unused


A good base setup for C is:
-std=c99 -pedantic -Wall -Wextra -Wwrite-strings -Werror
and for C++
-ansi -pedantic -Wall -Wextra -Weffc++

My C++ version:

-g -O -Wall -Wextra -Weffc++ -pedantic -Wformat=2 \
 -Waggregate-return -Wcast-align \
 -Wcast-qual   -Wconversion \
 -Wdisabled-optimization  -Wfloat-equal   \
 -Winit-self  -Winline \
 -Winvalid-pch   -Wunsafe-loop-optimizations  -Wmissing-braces \
 -Wmissing-format-attribute   \
 -Wmissing-include-dirs \
 -Wpacked  -Wpadded -Wpointer-arith \
 -Wredundant-decls -Wshadow  -Wstack-protector \
 -Wswitch-default  -Wswitch-enum \
 -Wunknown-pragmas  -Wunreachable-code -Wunused \
 -Wvariadic-macros  -Wwrite-strings \
 -Wlogical-op -Wsign-conversion  \
 -Wstrict-overflow=5 -Wundef

August 2, 2012

Windows 7 change alt-tab preview deplay


Open Registry Editor and create the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AltTab.

In that key, create the following DWORD value: LivePreview_ms and set it to the delay (in milliseconds) of the first live preview.

Restart Explorer to see the changes.

Other Aero-peek related registry entries that I've found on the net are:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced

    DesktopLivePreviewHoverTime
    ThumbnailLivePreviewHoverTime
    ExtendedUIHoverTime

These control the delay of other components of Aero-peek.

Give regular user right to start/stop service in Windows 7


  1. Download and install SubInACL.exe
  2. run "C:\Program Files\Windows Resource Kits\Tools\subinacl" /service Spooler /grant=<username>=TO
SubInACL works on Windows 7.
The T grant parameter is for start service access and the O parameter is stop service access.
Now <username> can:
  • run sc stop Spooler and sc start Spooler
  • run net stop "Print Spooler" and net start "Print Spooler"
  • use the Restart button on the Print Spooler item in services.msc
Source: http://superuser.com/questions/419194/is-there-a-way-to-allow-standard-users-to-restart-stop-start-the-print-spooler

Update: The single subinacl.exe download seems to be not available anymore. Try download the windows 2003 resource toolkit at

Windows Server 2003 Resource Kit Tools

July 27, 2012

How to Resolve “mount error(12): Cannot allocate memory” on a Windows Share


From: http://jlcoady.net/windows/how-to-resolve-mount-error12-cannot-allocate-memory-windows-share

If you mount a Windows 7 share using Samba/CIFS you may run into “mount error(12): Cannot allocate memory” if you are using very large files on the Windows machine. Looks like in certain situations Windows needs to be told to run as a file server and to expect large files. You can read more details at Large Files are locking up Windows 7 32 bit and 64 bit, but the solution is to make two registry edits and then restart a service:
  1. Set “HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache” to “1″.
  2. Set “HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size” to “3″.
  3. Restart the “server” service.
Once you have done that you should be able to mount the share using a command like “sudo mount -a” or just reboot the Linux machine.

July 18, 2012

__USE_GNU (use GNU specific feature)


Directly define __USE_GNU is wrong, __USE_GNU is glibc internal macro that shouldn't be ever defined by apps.
The way to select GNU feature set in glibc headers is to define _GNU_SOURCE, either before including first include header in the source .c/.C file, or by defining it on the command line (-D_GNU_SOURCE).

July 16, 2012

VirtualBox USB from the command line

Credit: http://richardhorwood.com/108/virtualbox-usb-from-the-command-line/

How to add a USB device using vboxmanage


  1. Ensure you actually have USB support for your target VM:
    # VBoxManage showvminfo "somevm" | grep USB
    USB:             enabled
  2. If it’s not set to “enabled” you’ll have to add USB support to your VM.  You’ll need to power off the VM to do this:

    # VBoxManage modifyvm "somevm" --usb on --usbehci on
  3. To attach a device that’s plugged into the same system as your VM (in my case, a Sony USB memory stick), grab its UID as follows:
    # VBoxManage list usbhost
    Sun VirtualBox Command Line Management Interface Version 3.1.4
    (C) 2005-2010 Sun Microsystems, Inc.
    All rights reserved.
    
    Host USB Devices:
    [...]
    UUID:               2a2c7255-3b90-448e-aa7a-b1c5710ddd79
    VendorId:           0x054c (054C)
    ProductId:          0x0243 (0243)
    Revision:           1.0 (0100)
    Manufacturer:       Sony
    Product:            Storage Media
    SerialNumber:       6A08102832911
    Address:            0x54c:0x243:256:/pci@0,0/pci108e,5347@2,1
    Current State:      Busy
    
  4. Create a usb filter which will tell VirtualBox to provide the USB device to your virtual machine when it’s detected as plugged in on the host:
    # VBoxManage usbfilter add 0 --target "somevm" --name usbstick \
                   --vendorid 054C --productid 0243
  5. Go ahead and power on your Virtual Machine.  You’ll notice that the USB device (if it’s currently plugged in) immediately becomes unavailable on the host.  You can confirm that it’s attached and that you didn’t make a typo with the vendor and/or product IDs:
    # VBoxManage showvminfo "somevm"
    [...]
    Currently Attached USB Devices:
    
    UUID:               582313d4-1d51-41ea-a053-ba5ac552d2e5
    VendorId:           0x054c (054C)
    ProductId:          0x0243 (0243)
    Revision:           1.0 (0100)
    Manufacturer:       Sony
    Product:            Storage Media
    SerialNumber:       6A08102832911
    Address:            0x54c:0x243:256:/pci@0,0/pci108e,5347@2,1
That’s it.  You can mount and unmount this device now inside your VM.

July 13, 2012

Import certificate and key into java key store using keytool

If you have the certificate and key in pkcs12 format you can directly import it into an existing java key store:

keytool -importkeystore -srckeystore server.p12 -srcstoretype pkcs12 -destkeystore server.jks -deststoretype jks

If you have it in PEM you can convert it to pkcs12 first:
cat server_key.pem server_cert.pem server_cacert.pem > server.pem
openssl pkcs12 -export -out server.p12 -in server.pem