2013년 10월 10일 목요일

glibc downgrade

rpm -Uvh --nodeps --oldpackage /home/glibc-2.12-1.107.el6.x86_64.rpm
rpm -Uvh --nodeps --oldpackage /home/glibc-common-2.12-1.107.el6.x86_64.rpm
rpm -Uvh --nodeps --oldpackage /home/glibc-devel-2.12-1.107.el6.x86_64.rpm
rpm -Uvh --nodeps --oldpackage /home/glibc-headers-2.12-1.107.el6.x86_64.rpm

glibc를 변경할 시 시스템이 불능이 될 수 있으니 패키지 명령어로 하는게 좋음.

2013년 10월 3일 목요일

오래된 커널 삭제

1. 설치된 커널 정보 가져오기
  RedHat : rpm -q kernel > list.txt
  Debain : dpkg --get-selections | grep linux-image | cut -f1 > list.txt

2. list.txt를 수정하여 삭제할 커널만 남겨 놓고 저장한다.

3. 제거
  RedHat : cat list.txt | xargs yum erase
  Debain : cat list.txt | xargs apt-get purge


기본적으로 커널은 5개 버전을 보관한다. 2개로 변경하는 방법
yum install yum-utils
package-cleanup --oldkernels --count=2

또는
/etc/yum.conf
  installonly_limit=2
로 변경

Centos 6.4 에서 gcc 4.8.1 source compile 하기

이용하는 시스템에 관리자 권한이 없다면 소스를 컴파일해서 사용해야 한다.
CentOS에 있는 g++은 C++11을 지원하는 버전이 아니라서 자신의 홈디렉토리에 컴파일해서 사용한다.


iconv-1.14 install
./configure --prefix=$HOME/opt/libiconv-1.14
make -j 12 && make install


gmp-5.1.3 install
./configure --prefix=$HOME/opt/gmp-5.1.3
make -j 12 && make install


ppl-0.12 install
./configure --prefix=$HOME/opt/ppl-0.12 --with-gmp=$HOME/opt/gmp-5.1.3
make -j 12 && make install


cloog-0.16.1 install
./configure --prefix=$HOME/opt/cloog-0.16.1 --with-gmp-prefix=$HOME/opt/gmp-5.1.3


mpfr-3.1.2 install
./configure --prefix=$HOME/opt/mpfr-3.1.2 --with-gmp=$HOME/opt/gmp-5.1.3
make -j 12 && make install


mpc-1.0.1 install
./configure --prefix=$HOME/opt/mpc-1.0.1 --with-mpfr=$HOME/opt/mpfr-3.1.2 --with-gmp=$HOME/opt/gmp-5.1.3
make -j 12 && make install


bash 경우
~/.bashrc
 export ICONV=/home/hkim/opt/libiconv-1.14
export CLOOG=/home/hkim/opt/cloog-0.16.1
export GMP=/home/hkim/opt/gmp-5.1.3
export MPC=/home/hkim/opt/mpc-1.0.1
export MPFR=/home/hkim/opt/mpfr-3.1.2
export PPL=/home/hkim/opt/ppl-0.12
export LD_LIBRARY_PATH=$ICONV/lib:$CLOOG/lib:$GMP/lib:$MPC/lib:$MPFR/lib:$PPL/lib:$LD_LIBRARY_PATH
export PATH=$CLOOG/bin:$PPL/bin:$ICONV/bin:$PATH

또는 csh 경우
~/.cshrc
setenv CLOOG /home/hkim/opt/cloog-0.16.1
setenv ICONV /home/hkim/opt/libiconv-1.14
setenv GMP /home/hkim/opt/gmp-5.1.3
setenv MPC /home/hkim/opt/mpc-1.0.1
setenv MPFR /home/hkim/opt/mpfr-3.1.2
setenv PPL /home/hkim/opt/ppl-0.12
setenv LD_LIBRARY_PATH ${CLOOG}/lib:${GMP}/lib:${MPC}/lib:${MPFR}/lib:${PPL}/lib:${ICONV}/lib:$LD_LIBRARY_PATH

set path=($CLOOG/bin $PPL/bin $ICONV/bin $path .)



gcc-4.8.1 install
./configure --prefix=$HOME/opt/gcc-4.8.1 --disable-cloog-version-check --enable-cloog-backend=isl --enable-gold --enable-languages=c,c++ --enable-lto --enable-libssp --with-ppl=$HOME/opt/ppl-0.12 --with-mpfr=$HOME/opt/mpfr-3.1.2 --with-mpc=$HOME/opt/mpc-1.0.1 --with-gmp=$HOME/opt/gmp-5.1.3 --with-cloog=$HOME/opt/cloog-0.16.1 --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib
make -j 12 && make install


bash 경우
~/.bashrc
export GCC=/home/hkim/opt/gcc-4.8.1
export LD_LIBRARY_PATH=$GCC/lib64:$PPL/lib:$LD_LIBRARY_PATH
export PATH=$GCC/bin:$PATH

또는 csh 경우
~/.cshrc
setenv GCC /home/hkim/opt/gcc-4.8.1
setenv LD_LIBRARY_PATH ${GCC}/lib64:$LD_LIBRARY_PATH
set path=($GCC/bin $path .)

2013년 9월 26일 목요일

Xen Server에서 Ubuntu 설치시 "Unable to access a required file in the specified repository" 에러 해결

에러 내용
Sep 26, 2013 3:22:14 PM Error: Starting VM 'Ubuntu Precise Pangolin 12.04 (64-bit)' - The bootloader for this VM returned an error -- did the VM installation succeed?  INVALID_SOURCE
Unable to access a required file in the specified repository: http://archive.ubunut.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz.



이런식으로 나오는걸
xe vm-list 로 설치하고자 하는 vm의 uuid를 얻어 온 뒤 boot 옵션들은 수정하여 재시작 한다

xe vm-param-set uuid=13005686-4547-599f-9e59-148982868d68 HVM-boot-policy="BIOS order"
xe vm-param-set uuid=13005686-4547-599f-9e59-148982868d68 HVM-boot-params:order=cd

2013년 9월 8일 일요일

Fedora18에서 크로스 컴파일을 이용한 RaspberryPI(RPI) 실행 파일 만들기 및 원격 디버깅 방법

상황은 이랬다.
pc에서 작성한 코드를 rpi에서 실행 시켜볼 일이 생겼는데 rpi에서 컴파일을 하니 pc보다 20여배는 느렸다. 코드를 저장하고 컴파일을 하던 습관이 rpi에서 작업하는 상당한 시간을 차지하여 크로스 컴파일을 구축하게 되었다.

크로스 컴파일을 사용하면 pc와 같은 고성능 시스템에서 빠르게 컴파일하여 target 시스템(지금은 RPI)에서 실행 시킬 수가 있다.
RPI에서 IDE를 사용하여 코딩을하고 싶으나 하드웨어 지원이 미약하여 무리가 따른다. 따라서 pc에서 IDE와 크로스 컴파일러를 이용하여 실행파일을 제작 원격(RPI)에서 실행 및 디버깅할 수 있는 방법을 적어본다.

참조 : http://akanto.wordpress.com/2012/09/25/cross-compiling-kernel-for-raspberry-pi-on-fedora-17-part-1/

나는 페도라18를 사용하는데 참조했던 사이트는 이전 버전이라서 그런가 디버그 세팅할 때 문제가 생겼었다.

일단 자세히 정리는 못하고 기억나는데로 정리하자.

크로스 툴 체인은 http://www.crosstool-ng.org 에서 1.17.0 버전을 다운 받았다.
최신 버전은 1.18.0 인데 root 권한으로 실행 할 수 없다는 오류를 내밷으면서 컴파일이 되지 않았다. 설치를 할 때 sudo로 하지 말고 root로 바꿔서 진행 할 것.

  1. 우선 pc에서 필요한 라이브러리를 설치한다.
    #yum install -y bison flex gperf libtool texinfo gcc gcc-c++ gmp-devel ncurses ncurses-devel expat expat-devel python python-devel
  2. crosstool-ng-1.17.0 버전을 다운받아 설치한다.
    #cd /opt
    #wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.17.0.tar.bz2
    #tar -jxvf crosstool-ng-1.17.0.tar.bz2
    #cd crosstool-ng-1.17.0/
    #./configure --prefix=/opt/crosstool-ng-1.17.0/
    #make && make install
    #cp ct-ng.comp /etc/bash_completion.d/

    이렇게 설치가 끝나면 ct-ng를 PATH에 등록해야 한다.
    PATH=$PATH:/opt/crosstool-ng-1.17.0/bin
  3. 이제 RPI용 컴파일러를 설치해야 한다.
    #mkdir /opt/crosstool-ng-1.17.0-config
    #cd /opt/crosstool-ng-1.17.0-config
    #ct-ng menuconfig
    이후 RPI에 맞게 컴파일러 옵션들을 설정해 줘야 한다.

    Paths and misc options
    >> Enable “Try features marked as EXPERIMENTAL”
    >> Set the “Prefix directory” from “${HOME}/x-tools/${CT_TARGET}” to “/opt/crosstool-ng-1.17.0-tools/${CT_TARGET}”

    Toolchain options
    >> Tuple’s version string is set to “rpi”.

    Target options
    >> Be sure that the “Target Architecture” is set to “arm”
    >> Be sure that “Little Endian” and “32bit” are selected
    >> Be sure that “Floating point” is set to “hardware (FPU)”
    >> Be sure that “Use EABI” is selected

    Operating system
    >> Set “Target OS” to Linux

    C compiler
    >> Enable “Show Linaro versions”
    >> Enable “C++” in order to have C++ compiler
    >> Disable “Link libstdc++ statically into gcc binary”
    >> Disable “GRAPHITE loop optimisations”

    Debug facilities
    >> Enable “gdb”
    >>>> Cross-gdb extra config "--with-expat"
    >> Enable “ltrace”
    >> Enable “duma”
    >> Enable “dmalloc”
    >> Keep “strace” on disable since it does not seem to build with crosstool-ng 1.17.0
  4. 환경설정이 끝났으면 컴파일을 시작한다.
    #ct-ng build 4
    4개의 core를 이용하여 병렬 컴파일을 한다. 대략 30분 정도 걸린다(i5이용).
  5. 컴파일이 끝나면 생성된 실행파일 경로를 PATH에 등록한다.
    PATH=$PATH:/opt/crostool-ng-1.17.0-tools/arm-rpi-linux-gnueabi/bin
  6. 이제 RPI용 컴파일러를 설치하였다. 이제 eclipse를 이용하여 RPI용 실행 파일을 만들고 RPI에서 실행 시켜보자.

    file > new > c++ project

       

    "Cross compiler prefix : arm-rpi-linux-gnueabi-",
    "Cross compiler path : /opt/crosstool-ng-1.17.0-tools/arm-rpi-linux-gnueabi/bin"
    으로 입력한다.

  7. Run > Run Configurations > C/C++ Remote Application
    Main > New 를 눌러 RPI에 접속할 수 있는 정보를 설정하고 "Run"을 실행시키면 원격에서 실행된 결과를 eclipse에서 볼 수 있다.






    하단 빨간 사각형은 RPI에서 실행되는 경로와 실행파일 명을 기록해야 한다.
    ex) /home/hkskyp/Projects/helloworld
  8. 이제 원격 디버깅을 해보자.
    우선 gdbserver를 RPI에 복사애햐 한다.
    #scp /opt/crosstool-ng-1.17.0-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/debug-root/usr/bin/gdbserver root@192.168.0.2:/usr/local/bin/

    이제 eclipse에서
    Run > Debug Configurations > C/C++ Remote Application
    "GDB debugger : /opt/crosstool-ng-1.17.0-tools/arm-rpi-linux-gnueabi/bin/arm-rpi-linux-gnueabi-gdb"
    디버거 역시 RPI용 GDB를 선택해 주어야 한다.

2013년 8월 26일 월요일

install mpich2 on Fedora18 or Pidora which is RaspberryPi OS.

#yum install mpich2 mpich2-devel

#firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -s 192.168.1.0/24 -p all -j ACCEPT
#firewall-cmd --direct --add-rule ipv4 filter INPUT 9 -s 0.0.0.0/0 -p all -j DROP

2013년 5월 24일 금요일

matlab에서 multi-format cvs 읽기


fp = fopen('data.csv');
allData = textscan(fp, '%s %f','delimiter',',','headerlines',1);
fclose(fp);


문자열
allData{1}{1}

숫자
allData{1}(1)



para_range

int q = N/ntask;
int r = N%ntask;
int start   = rank*q + min(rank, r);
int end     = (rank+1)*q + min(rank+1, r);

N = 14 이고 ntask 4이면
P1 : 0-4(4)
P2 : 4-8(4)
P3 : 8-11(3)
P4 : 11-14(3)

으로 start-end이 균등하게 할당 됨

2013년 5월 9일 목요일

fontlink

dejavu 폰트를 쓰다가 한글이 깨지길래 찾아봤더니 fontlink라는 기능이 있더라.


그래서 나눔고딕코딩 폰트랑 연결하였음.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]

다중 문자열 값

이름 : DejaVu Sans Mono

데이터

NanumGothicCoding.ttf,NanumGothicCoding

2013년 5월 6일 월요일

read csv file in bash


#!/bin/bash

INPUT=$1 or file name
OLDIFS=$IFS
IFS=,

while read col1 col2 col3 col4 col5 col6
do
        echo $col4
done < $INPUT

IFS=$OLDIFS

$col6의 경우 마지막 열 까지 읽음

2013년 4월 5일 금요일

aligned stl vector

reference1 : https://gist.github.com/donny-dont/1471329
reference2 : http://blogs.msdn.com/b/vcblog/archive/2008/08/28/the-mallocator.aspx



#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>

/**
 * Allocator for aligned data.
 *
 * Modified from the Mallocator from Stephan T. Lavavej.
 * <http://blogs.msdn.com/b/vcblog/archive/2008/08/28/the-mallocator.aspx>
 */
template <typename T, std::size_t Alignment>
class aligned_allocator
{
public:

// The following will be the same for virtually all allocators.
typedef T * pointer;
typedef const T * const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
typedef std::size_t size_type;
typedef ptrdiff_t difference_type;

T * address(T& r) const
{
return &r;
}

const T * address(const T& s) const
{
return &s;
}

std::size_t max_size() const
{
// The following has been carefully written to be independent of
// the definition of size_t and to avoid signed/unsigned warnings.
return (static_cast<std::size_t>(0) - static_cast<std::size_t>(1)) / sizeof(T);
}


// The following must be the same for all allocators.
template <typename U>
struct rebind
{
typedef aligned_allocator<U, Alignment> other;
} ;

bool operator!=(const aligned_allocator& other) const
{
return !(*this == other);
}

void construct(T * const p, const T& t) const
{
void * const pv = static_cast<void *>(p);

new (pv) T(t);
}

void destroy(T * const p) const
{
p->~T();
}

// Returns true if and only if storage allocated from *this
// can be deallocated from other, and vice versa.
// Always returns true for stateless allocators.
bool operator==(const aligned_allocator& other) const
{
return true;
}


// Default constructor, copy constructor, rebinding constructor, and destructor.
// Empty for stateless allocators.
aligned_allocator() { }

aligned_allocator(const aligned_allocator&) { }

template <typename U> aligned_allocator(const aligned_allocator<U, Alignment>&) { }

~aligned_allocator() { }


// The following will be different for each allocator.
T * allocate(const std::size_t n) const
{
// The return value of allocate(0) is unspecified.
// Mallocator returns NULL in order to avoid depending
// on malloc(0)'s implementation-defined behavior
// (the implementation can define malloc(0) to return NULL,
// in which case the bad_alloc check below would fire).
// All allocators can return NULL in this case.
if (n == 0) {
return NULL;
}

// All allocators should contain an integer overflow check.
// The Standardization Committee recommends that std::length_error
// be thrown in the case of integer overflow.
if (n > max_size())
{
throw std::length_error("aligned_allocator<T>::allocate() - Integer overflow.");
}

// Mallocator wraps malloc().
void * const pv = _mm_malloc(n * sizeof(T), Alignment);

// Allocators should throw std::bad_alloc in the case of memory allocation failure.
if (pv == NULL)
{
throw std::bad_alloc();
}

return static_cast<T *>(pv);
}

void deallocate(T * const p, const std::size_t n) const
{
_mm_free(p);
}


// The following will be the same for all allocators that ignore hints.
template <typename U>
T * allocate(const std::size_t n, const U * /* const hint */) const
{
return allocate(n);
}


// Allocators are not required to be assignable, so
// all allocators should have a private unimplemented
// assignment operator. Note that this will trigger the
// off-by-default (enabled under /Wall) warning C4626
// "assignment operator could not be generated because a
// base class assignment operator is inaccessible" within
// the STL headers, but that warning is useless.
private:
aligned_allocator& operator=(const aligned_allocator&);
};

int main()
{
typedef std::vector<__m128, aligned_allocator<__m128, sizeof(__m128)> > aligned_vector;
aligned_vector lhs;
aligned_vector rhs;

float a = 1.0f;
float b = 2.0f;
float c = 3.0f;
float d = 4.0f;

float e = 5.0f;
float f = 6.0f;
float g = 7.0f;
float h = 8.0f;

for (std::size_t i = 0; i < 1000; ++i)
{
lhs.push_back(_mm_set_ps(a, b, c, d));
rhs.push_back(_mm_set_ps(e, f, g, h));

a += 1.0f; b += 1.0f; c += 1.0f; d += 1.0f;
e += 1.0f; f += 1.0f; g += 1.0f; h += 1.0f;
}

__m128 mul = _mm_mul_ps(lhs[10], rhs[10]);
}


2013년 3월 27일 수요일

crypt in python


cat savepw.py

import crypt
import sys

print sys.argv[1]
print crypt.crypt(sys.argv[1])
-------------------------------------


use in bash

savepw=($(python savepw.py 'password'))
echo "save password : " $savepw




2013년 3월 8일 금요일

QIcon 배포 문제

QT에서 아이콘 경로를 지정할 때 QIcon(":/images/icon.png") ); 식으로 사용하는데, 문제는 개발PC에서는 아이콘이 정상적으로 출력되는데 테스트PC에서는 아이콘이 출력되지 않았다.

해결방법은

실행파일과 같은 경로에 plugins\imageformats\qico4.dll 이 있어야 아이콘이 정상적으로 출력된다.
(예전에도 qt에 mysql를 넣었을 때 배포판 버전에서 mysql이 실행안되는 문제가 생겼서 plugins 폴더 만든적이 있었는데 QIcon 클래스가 qtcore에 포함된게 아니라 플러그인으로 빼놓았군)
qico4.dll은 qt 인스톨(컴파일된) 경로에 있음.

2013년 1월 17일 목요일

sysprep

출처 : http://blogs.technet.com/b/koalra/archive/2013/01/17/windows-vhd-vhdx.aspx

 이 SID에 대한 재설정(Reset)이 필요하다는 것인데요. 이 경우에 사용되었던 도구가 일전의 Sysinternal의 NewSID(지금은 제공되지 않고, 그리고 공식적인 기술 지원도 불가), 그리고 공식적인 도구인 Windows내 포함된 Sysprep입니다.

 image 

해당 Sysprep을 실행하면, 체크 박스로 있는 일반화(Generalize)가 중요합니다. 이렇게 일반화된 이미지의 경우, 최초 부팅시, SID에 대한 리셋, 그리고 하드웨어에 대한 검색, 컴퓨터에 대한 구성등을 재구성해줌으로, 유니크한 형태로 구성을 해주게 됩니다. 이에 Windows 이미지를 생성 후, Sysprep을 통해, 반드시 해당 이미지를 초기화시키는 작업이 필요합니다. (보통 컴퓨터를 구매하셨을 때, 최초에 Windows가 부팅되고, 제품 키나 컴퓨터 이름등을 묻는 단계가 바로 Sysprep된 이미지를 켰을 때의 형태입니다.)

2013년 1월 11일 금요일

ssl web proxy

https://www.securetunnel.com/xpress

centos + nvidia + virtualgl => [VGL] ERROR: Could not open display :0.


refernece : http://stringr.blogspot.kr/2012/12/centos-nvidia-virtualgl-vgl-error-could.html
如果你的 Linux工作站只有遠端登入使用,連螢幕都沒有接,那你可能會遇到 [VGL] ERROR: Could not open display :0. 的問題。

檢查你的Xorg.0.log:

(EE) Dec 02 19:15:02 NVIDIA(0): Failed to assign any connected display devices to X screen 0
(EE) Dec 02 19:15:02 NVIDIA(0): Failing initialization of X screen 0
(II) UnloadModule: "nvidia"
(II) UnloadModule: "ramdac"
(II) UnloadModule: "wfb"
(II) UnloadModule: "fb"
(EE) Screen(s) found, but none have a usable configuration.

Fatal server error:
no screens found

如果出現上面的錯誤訊息,那表示nvidia顯卡偵測不到螢幕,所以他自己卸載了,於是你的系統中就不存在display:0,所以導致virtualgl錯誤。

 解決方法:

編輯你的xorg.conf

Section "Device"
    Identifier     "Videocard0"
    Driver         "nvidia"
    Option         "ConnectedMonitor" "CRT"
EndSection

출저 : http://blog.syszone.co.kr/3193?category=21
리눅스 시스템의 부팅 모드를 init 5 모드로 부팅을 해야할 경우, 기본적으로 콘솔에 모니터가 장착되어 있어야 한다. 하지만 서버용도로 사용할 경우 콘솔에 모니터가 연결 안되어 있는 환경도 존재
한다. 이때 원격으로 3D 관련 라이브러리를 이용하는 SW 실행 시 문제가 발생할 수 있다.


아래는 모니터를 연결하지 않고, init  5 모드로 정상 부팅 시키는 방법이다.


/etc/X11/xorg.conf 파일의 screen 설정 세션에서

   Option         "ConnectedMonitor" "CRT-0"
   Option         "UseDisplayDevice" "CRT-0"

옵션을 추가하면 된다.

실제 init 5 로 부팅할 경우 일반적인 부팅프로세스를 진행한 후, X 로딩 시 그래픽 카드가 모니터의 EDID값을 자동으로 받아와서 모니터 환경과 해상도 등을 자동으로 적용하게 된다.

이때 모니터가 장착되지 않은 환경에서는 모니터의 EDID 값 호출 단계에서 실패하여 정상적으로 X 를 시작
할수 없다.

이때 위 두 옵션을 추가하면, xorg.conf 설정 파일 자체에서 CRT-0 로 모니터가 장착되었다고 강제로
정의시켜 이런 문제를 해결할 수 있다.

아래는 전체 screen 설정 예이다.

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "0"
    Option         "metamodes" "1280x1024_60 +0+0"
    Option         "ConnectedMonitor" "CRT-0"
    Option         "UseDisplayDevice" "CRT-0"
    SubSection     "Display"
        Depth       24
  Modes       "1280x1024"
    EndSubSection
EndSection

2013년 1월 7일 월요일

리눅스 디스크 속도 테스트

쓰기
time dd if=/dev/zero of=tstfile bs=4k count=$((1024*1024/4))

읽기(캐쉬된 상태)
time dd if=tstfile of=/dev/null bs=4k count=$((1024*1024/4))
또는 hdparm -tT(캐쉬, 논캐쉬)으로 읽기 속도 측정 가능

flash action script 3.0 file path

./이미지/파일.jpg

으로 해야 함.

윈도우에서 하는데로 \\ 으로 했더니 ctrl+enter로 했을 때에는 정상 실행되나 ctrl+shift+enter로 실행되면 옳바르지 않는 경로라고 에러를 냄.
Win Projector를 이용해서 exe로 publish 한 경우에도 마찬가지로 에러가 발생 함.

"./" 은 상대경로를 의미