# CONFIG_MODULE_FORCE_UNLOAD is not set # CONFIG_MODVERSIONS is not set # CONFIG_MODULE_SRCVERSION_ALL is not set # CONFIG_MODULE_SIG is not set # CONFIG_MODULE_COMPRESS is not setDownload this Kernel_build.config
10/26/2016
insmod: ERROR: could not insert module / Invalid module format
Build kernel with this config off and feel free to load new kernel module without recompiling kernel
12/13/2015
Mount QCOW2 image
QCOW_IMG=$1
NBD_DEV=/dev/nbd0
modprobe nbd
qemu-nbd -c $NBD_DEV $QCOW_IMG
#Find start byte (offset) of a partition
parted $NBD_DEV -s unit B print
#Associate that offset with a loop dev
losetup -o 525336576 -f /dev/nbd0
#Mount loop device to a directory
NBD_DEV=/dev/nbd0
modprobe nbd
qemu-nbd -c $NBD_DEV $QCOW_IMG
#Find start byte (offset) of a partition
parted $NBD_DEV -s unit B print
#Associate that offset with a loop dev
losetup -o 525336576 -f /dev/nbd0
#Mount loop device to a directory
7/13/2015
gdb: source indicator goes out of order
Problems:
If program is compiled with option "-O2", gdb might not recognize order of source lines correctly and the current statement would point to incorrect line.
Solution:
Change "-O2" to "-O0"
http://www.linuxquestions.org/questions/programming-9/gdb-doesn%27t-provide-the-correct-line-in-the-source-code-858155/
If program is compiled with option "-O2", gdb might not recognize order of source lines correctly and the current statement would point to incorrect line.
Solution:
Change "-O2" to "-O0"
http://www.linuxquestions.org/questions/programming-9/gdb-doesn%27t-provide-the-correct-line-in-the-source-code-858155/
1/30/2015
Dual boot: windows 7 & centos
menuentry "Windows 7" {
set root=(hd0,1)
chainloader +1
}
grub2-mkconfig -o /boot/grub2/grub.cfg
12/07/2014
C pointer variable
What is the difference between int* n and int *n
If int *n, that is a fallacy that there are 2 type of variables. In fact, variable is a place holder of data only, the variant is the type of data it holds.
int is data structure of 4 bytes while int* is the one of 8 bytes (for 64 bit system).
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
int main(int argc, char* argv[]){
int fd = socket(AF_INET, SOCK_DGRAM, 0);
unsigned int zero = 300;
// building address structure
struct in_addr* ipaddr = malloc(sizeof(struct in_addr));
if(ipaddr == NULL){
perror(strerror(errno));
}
zero = *((unsigned int*)ipaddr);
printf("size of struct in_addr*: %d\n", sizeof(struct in_addr*));
printf("size of int*: %d\n",sizeof(int*));
printf("%x\n",zero);
printf("ipaddr = %x",*((int*)(ipaddr)));
return 0;
}
7/30/2014
Populate a whole-root directory structure
Using yum utility, we can populate a directory structure that holds bunch of software utilities. This structure could be later used as changed root environment (jail). The following command ran on Centos 6:
$ yum install --releasever=6 --installroot=/absolute/path/to/dir <package_name>
7/27/2014
Linux software RAID-1
Recover RAID-1 from the disk that survived disaster
$ mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdc where /dev/sdc is the surviving disk
7/21/2014
Color on bash shell prompt
vim ~/.bashrc
COLOR1='\[\033[38;5;34m\]'
COLOR2='\[\033[38;5;161m\]'
BOLD='\[\033[1m\]' # Work only if "allow bold text" setting is enabled
STOP='\[\033[0m\]'
PS1="[${BOLD}${COLOR1}\u${STOP}@${BOLD}${COLOR2}\h \W${STOP}]\$ "
For more
5/09/2014
Postgresql: getting started
# service postgresql initdb
to create /var/lib/pgsql/data which contains pg_hba.conf
to create /var/lib/pgsql/data which contains pg_hba.conf
createdb
set password for postgres user
psql -h -d -u -W
5/03/2014
crond edit
Format: minute hour day month weekday /path/to/script
Cron table takes time value as time point not interval.
Use * to ignore value.
# Run script at 4:03
3 4 * * * script
Use / to specify interval
# run script every 14 minute
*/14 * * * * script
Cron table takes time value as time point not interval.
Use * to ignore value.
# Run script at 4:03
3 4 * * * script
Use / to specify interval
# run script every 14 minute
*/14 * * * * script
2/16/2014
VIM: some useful settings
set laststatus=2
set ruler
set cursorline
set hlsearch
set nowrap
set expandtab
set tabstop=4
set mouse=a
filetype plugin on
highlight CursorLine cterm=NONE ctermbg=24
set ruler
set cursorline
set hlsearch
set nowrap
set expandtab
set tabstop=4
set mouse=a
filetype plugin on
highlight CursorLine cterm=NONE ctermbg=24
2/09/2014
Bash: special redirection character
Character | Action |
|---|---|
| |
| Redirect standard output and standard error |
| Redirect standard input |
| Redirect standard output; overwrite file if it exists |
| Redirect standard output and standard error; overwrite file if it exists |
| Redirect standard output to another command (pipe) |
| Append standard output |
| Append standard output and standard error |
VIM text editor
Put permanent settings in ~/.vimrc (create one if not existed)
# enable syntax highlight
syntax on
# bottom status
set laststatus=2
set ruler
# enable syntax highlight
syntax on
# bottom status
set laststatus=2
set ruler
2/03/2014
SSHFS mount does not allow other users to access
Append the following option:
sshfs ... -o allow_other
sshfs ... -o allow_other
1/05/2014
Login via serial console in linux system
When a user want to log in linux system via physical serial port (eg ttyS0), a login program (agetty or mingetty) should have already been waiting for user input (username and password) on that port.
To make the login program ready on serial port, append the following line in /etc/inittab:
The next step is to add parameter
To make the login program ready on serial port, append the following line in /etc/inittab:
1:23:respawn:/sbin/mingetty ttyS0The next step is to add parameter
console=ttyS0 at kernel boot command in GRUB, the kernel will expose interaction on that serial port so that user can login.
12/15/2013
C++ Variable of reference
#include <stdio.h>
struct point{
int x;
int y;
};
typedef struct point Point;
int main(){
Point p1;
Point &px = p1;
p1.x = 10;
p1.y = 20;
Point p2 = p1;
px.x = 11111;
px.y = 1122;
printf("Point 1: %d %d", p1.x, p1.y);
printf("Point 2: %d %d", p2.x, p2.y);
printf("There are two distinct object: Point 1 and 2");
}
11/18/2013
psql: FATAL: Ident authentication failed for user "username" Error and Solution
"By default Postgresql uses IDENT-based authentication. All you have to
do is allow username and password based authentication for your network
or webserver. IDENT will never allow you to login via -U and -W options.
Append following to allow login via localhost only:" (from http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/)
To access database via tcp connect with username/password, comment this line:
#host all all 127.0.0.1/32 ident
To access database via tcp connect with username/password, comment this line:
#host all all 127.0.0.1/32 ident
11/14/2013
11/13/2013
Make Centos listen to ACPI signal
yum install acpid
chkconfig acpid on
When you press power-off button on chassis, an ACPI signal is generated. If OS have acpid daemon listen for that kind of signal, shutdown command will be issued instead of sudden power-off ( in case of power outage).
chkconfig acpid on
When you press power-off button on chassis, an ACPI signal is generated. If OS have acpid daemon listen for that kind of signal, shutdown command will be issued instead of sudden power-off ( in case of power outage).
11/03/2013
Centos: make on-boot startup script
This post guide how to make script that start up at boot time on CentOS.
Write a script named, e.g launchd, that follows the pattern below:
#!/bin/bash
# name of service
# chkconfig: 345 90 90
# description: describe what your script would do
start(){
# create a lock file
touch /var/lock/subsystem/launchd
# tasks to do on boot
}
stop(){
# remove the lock file
rm -f /var/lock/subsystem/launchd
# tasks to do to stop scripts
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
esac
# ------------------------------------------------------------------------------------
The line that starts with # chkconfig is required to let chkconfig utility know which levels to run this script, start and stop priority.
Put this script in /etc/init.d directory.
Run: chkconfig --add launchd so that chkconfig can recognize your script.
Run: chkconfig launchd on to enable the script at some run-levels.
If you look at other script in /etc/init.d, you will find all scripts have lock file created in start() and removed in stop().
Write a script named, e.g launchd, that follows the pattern below:
Sample script
#----------------------------------------------------------#!/bin/bash
# name of service
# chkconfig: 345 90 90
# description: describe what your script would do
start(){
# create a lock file
touch /var/lock/subsystem/launchd
# tasks to do on boot
}
stop(){
# remove the lock file
rm -f /var/lock/subsystem/launchd
# tasks to do to stop scripts
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
esac
# ------------------------------------------------------------------------------------
Elaboration
This script must implement at least start() for the system to call.The line that starts with # chkconfig is required to let chkconfig utility know which levels to run this script, start and stop priority.
Put this script in /etc/init.d directory.
Run: chkconfig --add launchd so that chkconfig can recognize your script.
Run: chkconfig launchd on to enable the script at some run-levels.
Lockfile
Lockfile lets the system know whether there has been a running instance of this script. When the system starts up your script, it checks if lock file exists or not so that it won't have to run the script again and similar for stop(). This is why the function stop() won't be called if you haven't created a lockfile earlier.If you look at other script in /etc/init.d, you will find all scripts have lock file created in start() and removed in stop().
Subscribe to:
Posts (Atom)