How to compile the linux kernel

Download a kernel source from kernel.org and let’s suppose that it is extracted in the directory ~/linux-x.yy.zz

Sometimes it can be a good idea to start with a current kernel configuration. You can get this configuration from the text file /boot/config-xx.yy.zz or a compressed version from /proc/config.gz. Copy the text file into ~/linux-x.yy.zz/.config.

Now you can start configuring the new kernel by executing inside the dir ~/linux-x.yy.zz/:

make menuconfig

Then compile the kernel, the modules and the image:

make
make bzImage

If everything it’s ok the new kernel will be in ~/linux-x.yy.zz/arch/x86/boot/bzImage. Copy this file to the boot directory in the desired machine:

cp ~/linux-x.yy.zz/arch/x86/boot/bzImage /boot/vmlinuz-x.yy.z

Now you have to compile and install the modules:

make modules 
make modules_install

This will copy all the firmware and modules to /lib/firmware and /lib/modules/x.yy.z. If you want to change the directory you can do it by defining the INSTALL_MOD_PATH environment variable.

After install all the modules you have to go to /boot directory, create the initramfs and update the grub.

update-initramfs -c -k x.yy.zz
update-grub

How to create virtualbox by commandline

First create the virtual machine called myVirtualHost and register it:

VBoxManage createvm --name myVirtualHost --register

Then create a hard disk of 10Gbytes:

VBoxManage createhd --filename myhdd1.vdi -size 10240

This will create the file ~/.VirtualBox/HardDisks/myhdd1.vdi

Add an ide controller and the hard disk:

VBoxManage storagectl myVirtualHost --name "IDE Controller" --add ide
VBoxManage modifyvm myVirtualHost --hda .VirtualBox/HardDisks/myhdd1.vdi

You can add more disks with these commands:

VBoxManage modifyvm myVirtualHost --hdb .VirtualBox/HardDisks/myhdd2.vdi
VBoxManage storageattach myVirtualHost --storagectl "IDE Controller" --device 1 --port 0 --type hdd --medium .VirtualBox/HardDisks/myhdd3.vdi 

Now I will give this machine 512Mbytes of RAM:

VBoxManage modifyvm myVirtualHost --memory 512 --acpi on

You have different network options. If you want to give your virtual machine its own IP addpress you have to use the bridged mode:

VBoxManage modifyvm myVirtualHost --nic1 bridged

If you want to use the same IP address than your host machine you can use NAT. In this case you can configure NAT port forwarding to access to some services, for example with these lines you can access the SSH service of our virtual machine by connecting to the port 2222 from your host.

VBoxManage modifyvm myVirtualHost --nic1 nat
VBoxManage modifyvm myVirtualHost --natpf1 "guestssh,tcp,,2222,,22"

To launch the virtual machine and leave it in background you can use one of the following lines:

nohup VBoxHeadless -s myVirtualHost --vnc --vncpass mys3cr3t &
nohup VBoxHeadless -s myVirtualHost --vrde off &

The first one will enable VNC and also terminal server.
The second one will disable both, VNC and terminal server.

R packages

Part of this post is extracted from R-admin and R manual.

A package is loaded from a library by the function library(). Thus a library is a directory containing installed packages; the main library is R_HOME/library, but others can be used, for example by setting the environment variable R_LIBS or using the R function .libPaths():

> .libPaths()
[1] "/home/jose/R/x86_64-redhat-linux-gnu-library/3.1"
[2] "/usr/lib64/R/library"                            
[3] "/usr/share/R/library"

The set of packages loaded on startup is by default:

> getOption("defaultPackages")
[1] "datasets"  "utils"     "grDevices" "graphics"  "stats"     "methods" 

To install a new package write:

> install.packages("PackageName", repos = "http://repository_url", dependencies = TRUE)

install.packages can install a source package from a local .tar.gz file by setting argument repos to NULL: this will be selected automatically if the name given is a single .tar.gz file.

install.packages can look in several repositories, specified as a character vector by the argument repos: these can include a CRAN mirror, Bioconductor, Omegahat, R-forge, rforge.net, local archives, local files, …). Function setRepositories() can select amongst those repositories that the R installation is aware of.
The available packates ready to install are shown by calling available.packages().

The command installed.packages finds details of all packages installed. The return value is a matrix with one row per package, row names the package names and column names (currently) “Package”, “LibPath”, “Version”, “Priority”, “Depends”, “Imports”, “LinkingTo”, “Suggests”, “Enhances”, “OS_type”, “License” and “Built”. To see only the name of the installed packages write:

> rownames(installed.packages())

To remove an installed package use the command remove.packages:

> remove.packages("MBCluster.Seq")

To load a package use the command library:

> library("MBCluster.Seq")

The attached packages and extra info can be asked by sessionInfo() command.

source causes R to accept its input from the named file or URL or connection. Input is read and ‘parse’d from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment.

Manage/kill sessions in Oracle

A connection is a network link connection to the database. A connection can have 0, one or many sessions, but the normal situation is only one session per connection.
The tasks in a session are executed by processes. But a process does not have to be dedicated to a specific session.

If you want to see the current active sessions, select the v$session table:
Continue reading

Minimum HTTP server with netcat

Problem

Sometimes you need to have a simple HTTP server. You want to check connectivity from other machine or whatever sinister reason you can have.

Solution

We are going to create a simple HTTP server at port 8000.
You can use the netcat command:

nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)"

Then you can go to a web browser and write load the url at the port 8000

http://localhost:8000

But this works just for one connection, after that connection you must execute again the nc command, so to accept more connections you must add a while loop:

while [ 1 ];do nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)"'; done

May be you want to display a simple html file (with no images, ajax or any other HTML element that launchs more HTTP requests) like this one:

<!DOCTYPE html>
<html>
<body>
<h1>Example</h1>
This is a simple<br/>
webserver running with
<b>nc</b>
</body>
</html>

Let’s suppose that you have your html saved in a file called index.html, then you can show it in your netcat server as follows:

while [ 1 ];do nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n";cat index.html'; done

If you are not able to connect to your netcat server may be you have activated iptables, take a look writing as root:

iptables -L

If you want to remove the iptables that can be blocking this requests write the following commands as root:

iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT

Sharing Internet connection from your Linux

I want to share my Interent connection from my linux to another equipment.

First you have to enable NAT in your linux,
as root you must type:

# iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Then, logged as root, you have to enable IP forwarding.
There are two ways:

# sysctl -w net.ipv4.ip_forward=1

or

# echo 1 > /proc/sys/net/ipv4/ip_forward

Now you have to configure in your other device the IP of your linux as default gateway.

And that’s all folks!

If you have problems with iptables and you want to remove all the rules write:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Record screencast in Linux from command line

To record what appears on the screen or in an application you can use the program recordmydesktop 

To record the whole screen use:

$ recordmydesktop -o screencast.ogv

By default it uses a low frame rate and recods audio, If you want to use a higher frame rate without audio:

$ recordmydesktop --no-soundo --fps 24 -o screencast.ogv

Probably you want to record a window application, not the whole screen. To do that you fist need to know the Window id which can be obtained with the xwininfo command:

$ xwininfo 

xwininfo: Please select the window about which you
          would like information by clicking the
          mouse in that window.

xwininfo: Window id: 0x1a00003 "5554:intel17"

  Absolute upper-left X:  1467
  Absolute upper-left Y:  122
  Relative upper-left X:  1
  Relative upper-left Y:  32
  Width: 712
  Height: 800
  Depth: 24
  Visual: 0x22
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x1a00010 (not installed)
  Bit Gravity State: ForgetGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +1467+122  -781+122  -781-128  +1467-128
  -geometry 712x800+1466+90

In this case we are trying to record from the Android emulator. I know that for this purpose, if your android emulator version is 4.4 or higher, you can use the following commands over command-line:

$ adb shell screenrecord /sdcard/demo.mp4
$ adb pull /sdcard/demo.mp4

But in this case we are going to record from the host PC. So, if you want to record some part of the window, in our example the window has 480px and the remainder are just window decorators, write the following:

recordmydesktop --no-sound --windowid 0x1a00003 --fps 24 --width 480  -o screencast.ogv