viernes, 30 de agosto de 2013

GlusterFS 3.2.x On Ubuntu 12.04 with ext4 encrypted with dmcrypt

Follow are my history steps, these steps were created from :



Only difference is that I used ext4 instead of xfs.

Configure every gluster server with follow steps:

# losetup /dev/loop1 storage_space2
# cryptsetup luksFormat /dev/loop1
# cryptsetup isLuks /dev/loop1 && echo success
# cryptsetup luksDump /dev/loop1
# dmsetup info bricks
# mkfs.ext4 /dev/mapper/bricks
# mkdir /bricks
# mount /dev/mapper/bricks /bricks/
# vi /etc/crypttab
# vi /etc/fstab
# mount -a
# mount -l
# blkid -o full

Create at only once server the gluster volume:

# gluster vol create dmvolume replica 2
# volume group info
# gluster volume  info
# echo "Hola" > /bricks/File1
# cat /bricks/File1
# gluster volume set dmvolume auth.allow
# gluster volume stop dmvolume
# gluster volume start dmvolume

Now go to yor gluster client and mount gluster volume:

# mkdir /mnt/dm
# mount -t glusterfs gluster1:/dmvolume /mnt/dm
# mount -l
# ls /mnt/dm
# vi /mnt/dm/File_to_break
# cat /mnt/dm/File_to_break

Go back to your Server and list the created file

  # ls /bricks/dmvolume
  # cat /bricks/dmvolume/File_to_break

P.S. Have you seen your country round flag?

martes, 27 de agosto de 2013

Configure VM IP Address on Ubuntu 12.04

Step by step

1.- Go to virtual box,  select your vm and go to settings-> network
2.- Then on the attached to: select Brifged adapter
3.- Go to advanced and click on update button of Mac Address
4.- Start the VM
5.- remove the file /etc/udev/rules.d/70-persistebt-net.rules
6. Edit your /etc/network/interfaces, change "dhcp" to "static" like:
auto eth0
iface eth0 inet static

7.- do a #/etc/init.d/networking restart and see ifconfig
8.- If not gettin the ip ... reboot
9.- Check ifconfig, you should have an IP now

If not then do
10.- # sudo dhclient eth0

There you go, you have an IP

P.S. Did you know every pirate had its own flag?

jueves, 22 de agosto de 2013

Debugging a kernel module using gdb

These are some steps to find a simple bug because a NULL pointer.

0. gdb should be installed
# yum install gdb

1. add '-g -O' options (without quotes) at the EXTRA_CFLAGS variable of your Makefile file. This will add symbols to your created .ko module file

EXTRA_CFLAGS += -O2 -Wall -Wno-unused -fno-strict-aliasing -Werror -g -O

2. Make the module

3. execute:
agonzalez@kozlex:~/bugs/b/zncrypt/src/module/zncrypt$ gdb ./zncryptfs.ko
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
Reading symbols from /home/agonzalez/bugs/b/zncrypt/src/module/zncrypt/zncryptfs.ko...done.
There you are, symbols were read

4. Other option once you are in gdb shell, add symbols from 0x0:

(gdb) add-symbol-file zncryptfs.ko 0x0
add symbol table from file "zncryptfs.ko" at
    .text_addr = 0x0
(y or n) y
Reading symbols from /home/agonzalez/bugs/b/zncrypt/src/module/zncrypt/zncryptfs.ko...done.

5. Your symbols are loaded, you can dissassemble your culprit function, in my case zncrypt_remove_inode().

(gdb) disassemble zncrypt_remove_inode
Dump of assembler code for function zncrypt_remove_inode:
   0x00000000000008d5 <+0>:    push   %rbp
   0x00000000000008d6 <+1>:    mov    %rsp,%rbp
   0x00000000000008d9 <+4>:    callq  0x8de <zncrypt_remove_inode+9>
   0x00000000000008de <+9>:    mov    (%rdi),%rax
   0x00000000000008e1 <+12>:    mov    0x10(%rdi),%rdx
   0x00000000000008e5 <+16>:    mov    0xc0(%rdx),%rdx
   0x00000000000008ec <+23>:    mov    %rdx,0x20(%rax)
   0x00000000000008f0 <+27>:    mov    (%rdi),%rax
   0x00000000000008f3 <+30>:    mov    0x8(%rdi),%rdx
   0x00000000000008f7 <+34>:    mov    0xd0(%rdx),%rdx
   0x00000000000008fe <+41>:    mov    %rdx,0x130(%rax)
   0x0000000000000905 <+48>:    mov    0x18(%rdi),%rdx
   0x0000000000000909 <+52>:    mov    0x20(%rdi),%rax
   0x000000000000090d <+56>:    mov    %rax,0x8(%rdx)
   0x0000000000000911 <+60>:    mov    %rdx,(%rax)
   0x0000000000000914 <+63>:    movl   $0x100100,0x18(%rdi)
   0x000000000000091b <+70>:    movl   $0xdead0000,0x1c(%rdi)
   0x0000000000000922 <+77>:    movl   $0x200200,0x20(%rdi)
   0x0000000000000929 <+84>:    movl   $0xdead0000,0x24(%rdi)
   0x0000000000000930 <+91>:    callq  0x935 <zncrypt_remove_inode+96>
   0x0000000000000935 <+96>:    pop    %rbp
   0x0000000000000936 <+97>:    retq  
End of assembler dump.

5. Check the offset of your stack trace. In my case I had an Oops and the stack trace shows:

Aug 22 12:06:59 kozlex kernel: [ 464.774484] BUG: unable to handle kernel NULL pointer dereference at (null)
Aug 22 12:06:59 kozlex kernel: [ 464.799669] <ffffffffa04ee9b9>zncrypt_remove_inode+0x39/0x40 zncryptfs

6. You can see from 4 that the start address for zncrypt_remove_inode is 0x00000000000008d5, then add the offset of your stacktrace zncrypt_remove_inode+0x39 (see 5)

7. Do the addition of  0x8d5 + 0x39  = 0x90e

8. Then do follow command with the culprit address:

(gdb) list * 0x90e
0x90e is in zncrypt_remove_inode (include/linux/list.h:88).
83     * This is only for internal list manipulation where we know
84     * the prev/next entries already!
85     */
86    static inline void __list_del(struct list_head * prev, struct list_head * next)
87    {
88        next->prev = prev;
89        prev->next = next;
90    }
92    /**

9. There you go... Line 88 is where the NULL pointer fails...

10. Figure out where is you error by dissassembling previous functions and do what you know to do.

P.S. The first flag of the world is...

miércoles, 14 de agosto de 2013

Transfer files from/to android using ubuntu

Some easy steps..

Your ubuntu and android should be connected to the same wifi.

1. Install FTP Server App on your android smarthphone
2. Intall Filezilla on ubuntu
3. Start your FTP server at your smartphone. This gives you IP, user, password, port.
4. Conntec from FileZilla to you FTP server

You can transfer now whatever ypu need on any direcition.

P.S. There is a micro flag

martes, 13 de agosto de 2013

Configure a VM IP Address on redhat or centos

First go to virtual Box, your VM ->Settings -> Network ->Advanced

Display the Advance options and click the refresh button for Mac Address, then click OK

Now start the VM and login.

Remove from  HWADDR line from /etc/sysconfig/network-scripts/ifcfg-eth0

You should remove something like:

HWADDRR ="08:00:27:B2:F8L58"

Change eth0 by eth1 from ifcfg-eth0


Then add


Now restart network:

#sudo /etc/init.d/network restart

ifconfig will show you now your new IP address

P.S. most common flag colors are...

Accessing a virtual Box VM using telnet and serial port

alright alright alright, I am updating with steps that do the same and might can be easier to follow:
On behalf of my dear friend Sergio Pena.

There are some critical kernel panics that may freeze your system leaving you without a clue about what happened.
These kernel panics display a partially kernel stack trace on your system console, but not enough to do a complete debug of the error.
In order to get the complete kernel stack trace, we can get those kernel messages through the Linux serial port.

Let's follow these steps to configure your Linux system and a VirtualBox machine to get those kernel messages. 

Step 1: Configure the Linux Boot (Grub) to send kernel messages to the Serial Port

Edit the /boot/grub/menu.lst file, and add the following two lines before hiddenmenu config options:
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
Scroll down and find out kernel line and append the following config options:
console=tty0 console=ttyS0,9600
At the end, your menu.lst should looks like this:
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
title CentOS (2.6.32-358.11.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-358.11.1.el6.x86_64 ro root=/dev/mapper/vg_centos63-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos63/lv_swap rd_LVM_LV=vg_centos63/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM console=tty0 console=ttyS0,9600
 initrd /initramfs-2.6.32-358.11.1.el6.x86_64.img

Now reboot your system.
Every kernel message will be sent to the serial port after boot.

Step 2: Configure VirtualBox to connect to Linux over a Serial Port

The next part is to enable the serial port on the virtual machine running on VirtualBox.
Open the settings for the machine on Virtualbox. Go to "Serial Ports". In the Port 1 tab enable the "Enable Serial Port" option. Use the following settings:
Port Number : COM1
Port Mode : Host Pipe
Create Pipe (Enabled)
Port/File Path : /tmp/vserial

Click on the OK button.
Now start the target machine. 

Step 3: Use 'socat' & 'telnet' commands to connect to Linux through the Serial Port

Now it is time to connect to your Linux serial port in order to catch those kernel messages.
We'll use the socat command to convert a Unix socket to a TCP port, and then connect to the serial port through telnet. 
Install the 'socat' utility package.
apt-get install socat
Then, in a terminal session, execute the following socat command to convert the Unix socket stream to a TCP port stream.
socat UNIX-CONNECT:/tmp/vserial TCP-LISTEN:7000
If everything goes fine, the socat command will be stuck. So, open another terminal session to execute your telnet command.
telnet localhost 7000
If the connection is successful, then you'll see an output like this:
Connected to localhost.
Escape character is '^]'.
That's it. You can start now seeing any kernel message that appears after your telnet session.



This is an easy way to connect to a VM by telnet using the serial port

For example, I have a  Centos 6.2 VM installed with Virtual Box.

Instead of using ssh because you would loose connection on a kernel panic

You can use telnet to see the stack trace.

Once the VM is started - Go to your local host and in a terminal type:

# socat UNIX-CONNECT:/tmp/centos62 TCP-LISTEN:7000

Notice that /tmp/centos62 is my VM (virtual Box) virtual serial port

Open a new terminal and type:

$ telnet localhost 7000

You will be asked for login/password; go ahead and start navigating on your VM

Do all operations you want over telnet or ssh and if a kernel oops happen then it will be shown on your local terminal where 'telnet localhost 7000' was issued. You will see the entire stack trace instead just part of it.


P.S. Which is the prettiest flag?