2013年11月9日星期六

Install eclipse in linux

sudo apt-get install eclipse eclipse-jdt eclipse-pde eclipse-platform eclipse-rcp eclipse-cdt g++


Support C/C++: eclipse-cdt g++

2013年11月1日星期五

Download Java SDK for ubuntu

For Oracle-JDK,
 
Step1)
Remove the OpenJDK
sudo apt-get purge openjdk*
 
Step2)
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
 
Step3)
Step3a) For JAVA8, sudo apt-get install oracle-java8-installer
Step3b) For JAVA7, sudo apt-get install oracle-java7-installer
Step3c) For JAVA6, sudo apt-get install oracle-java6-installer   
 
__________________________________________________________________________
For Open-JDK, 
 
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install openjdk-6-jdk
 
 
openjdk-6-jdk 
openjdk-7-jdk

2013年10月30日星期三

Resize VirtualBox disk size

Suppose we are using Windows as the Host

Step 1) List hard disk drive
Open the command prompt and enter:
cd "C:\Program Files\Oracle\VirtualBox\"
vboxmanage list hdds

you will see something like this:
UUID: 5ebf0266-4e9e-4b7e-b9f6-6d67514919c3
Parent UUID: base
Format: VDI
Location: /VBOX/Windows XP/Windows XP.vdi
State: inaccessible
Type: normal
Usage: Windows XP (x86) (UUID: c90339ab-edb1-4b30-890b-ea7153b6cf4b)

Step 2) Determine the file is ended with VDI or VMDK extension.
If it is VDI, goto step 3a.
If it is VMDK, goto step 3b.

Step 3a) Resize the disk using UUID <- Recommended

Using the above as an example:
50000 = 50GB

VBoxManage modifyhd 5ebf0266-4e9e-4b7e-b9f6-6d67514919c3 --resize 50000

Step 3b) Resize the disk size by selecting UUID <- Recommended

Using the above as an example:
50000 = 50GB

VBoxManage clonehd 5ebf0266-4e9e-4b7e-b9f6-6d67514919c3 "c:\temp\clone.vdi" --format VDI
VBoxManage modifyhd "c:\temp\clone.vdi" --resize 50000
VBoxManage clonehd "c:\temp\clone.vdi" "NEW_HARK_DISK_DEST" --format VMDK

Attach the re-sized disk in VirtualBox.


Step 4)
Use GParted to expand the partition.

After verify the disk is working properly,
the original disk and also the "c:\temp\clone.vdi" one can be deleted safely.

2013年8月22日星期四

Encounter "UUID is duplicate" message after moving the VirtualBox image file

C:\Program Files\Oracle\VirtualBox> VBoxManage internalcommands sethduuid "E:\VirtualBox VMs\centos\centos.vdi"


2013年8月19日星期一

GRUB2 general configuration

grub-mkconfig, default is output to stdout

Valid keys are in the /etc/default/grub

--------------------------------------------------------

Manually add the menu entry)

1) Adding extra custom menu entries to the end of the list can be done by editing /etc/grub.d/40_custom
Alternatively, in/etc/grub.d folder, create the file XX_whichos where XX is the number. It is used to indicate the ordering of the menuitem.

2) After the file is edited, make it executable.
sudo chmod +x /etc/grub.d/XX_whichos

3) Execute "update-grub2" command

The updated grub.cfg will be placed at /boot/grub/ folder

=====================================================
For traditional partition,

Windows 7 entry (first harddisk, 2nd primary partition)

menuentry ‘Windows 7′ {
set root=’(hd0,msdos2)’
chainloader +1
}

=====================================================
For EFI,

menuentry "Windows 7" {
insmod part_gpt
insmod fat
insmod search_fs_uuid
insmod chain
search --fs-uuid --no-floppy --set=root 080F-E6DA
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi
}

UUID can be obtained from blkid

=====================================================


2013年8月18日星期日

ncat usage


quota from "http://nmap.org/ncat/guide/ncat-usage.html":


Main usage:

Ncat always operates in one of two basic modes: connect mode and listen mode. In connect mode, Ncat initiates a connection (or sends UDP data) to a service that is listening somewhere. For those familiar with socket programming, connect mode is like using the connect function. In listen mode, Ncat waits for an incoming connection (or data receipt), like using the bind and listen functions. You can think of connect mode as client mode and listen mode as server mode.

Connect mode:
ncat <host> [<port>]

Listen mode:
ncat -l [<host>] [<port>]

In listen mode, <host> controls the address on which Ncat listens; if you omit it, Ncat will bind to all local interfaces (INADDR_ANY). If the port number is omitted, Ncat uses its default port 31337.Typically only privileged (root) users may bind to a port number lower than 1024. A listening TCP server normally accepts only one connection and will exit after the client disconnects. Combined with the --keep-open option, Ncat accepts multiple concurrent connections up to the connection limit. With --keep-open (or -k for short), the server receives everything sent by any of its clients, and anything the server sends is sent to all of them. A UDP server will communicate with only one client (the first one to send it data), because in UDP there is no list of “connected” clients.

Ncat can use TCP, UDP, SCTP, SSL, IPv4, IPv6, and various combinations of these. TCP over IPv4 is the default.

-------------------------------------------------------------------------

File transfer using ncat:

input file on host1
output file on host2

Transfer a file, receiver listens
host2$ ncat -l > outputfile
host1$ ncat --send-only host2 < inputfile

Transfer a file, sender listens
host1$ ncat -l --send-only < inputfile
host2$ ncat host1 > outputfile


Transfer a bundle of files

host2$ ncat -l | tar xzv
host1$ tar czv <files> | ncat --send-only host2


---------------------------------------------------------------------------


Example. Running a command with --sh-exec
ncat -l --sh-exec "echo `pwd`"

Example. Ncat as mail client

$ ncat -C mail.example.com 25
220 mail.example.com ESMTP
HELO client.example.com
250 mail.example.com Hello client.example.com
MAIL FROM:a@example.com
250 OK
RCPT TO:b@example.com
250 Accepted
DATA
354 Enter message, ending with "." on a line by itself
From: a@example.com
To: b@example.com
Subject: Greetings from Ncat

Hello. This short message is being sent by Ncat.
.
250 OK
QUIT
221 mail.example.com closing connection

2013年8月16日星期五

Compress / Extract Files using tar Command

tar.bz2 file:
Compress:
tar -jcvf archive_name.tar.bz2 directory_to_compress

Extract:
tar -jxvf archive_name.tar.bz2
tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

------------------------------------------------------------------------

tar.gz file:
Compress:
:tar -cvzf archive_name.tar.gz directory_to_compress/

Extract:
tar -zxvf archive_name.tar.gz
tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

------------------------------------------------------------------------

tar file:
Compress:
tar -cvf archive_name.tar directory_to_compress
Extract:
tar -xvf archive_name.tar
tar -xvf archive_name.tar -C /tmp/extract_here/

------------------------------------------------------------------------

tar.xz file:
Compress:
tar -cvJf archive_name.tar.xz
Extract:
tar -xvJf archive_name.tar.xz
tar -xvJf archive_name.tar.xz -C /tmp/extract_here/

2013年8月15日星期四

Setup COM port in VirtualBox (Host: XUbuntu, Guest: Windows XP)

In VirtualBox Setting,
Port Number: COM1
IRQ: 4
I/O Port: 0x3F8
Port Mode: Host Device
Port/File Path: /dev/ttyS0

If encounter read/write permission error,
add the current Linux account to:
'dialout' Group

In xubuntu, System Administrator > 'Edit Group...' , add current user to the 'dialup' group

Check serial port in Linux:
dmesg | grep tty
If the screen shows out ttyS0, it means COM1

FYI,
as previous 'dialout' group account stated,
ls -l /dev/ttyS0 can view the COM1 permission group.

Executing background task while running SSH

nohup ./whatever > /dev/null 2>&1 &

Enable / Lock root account in Linux

Lock root account in Linux:
sudo passwd -l root

Enable root account in Linux:
sudo passwd root