Category Archives: Linux / Unix

간단 NAT Masquerade 설정

eth0 = 인터넷 연결된 것 (connected to the internet)
eth1 = 인터넷 연결할 것 (to connect)

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

 

vmware-modconfig on linux kernel 4.6 or above

최근 커널버전을 업데이트후 vmware 실행시 modconfig가 잘안되서 찾아봄
아래는 해당 에러로그

/usr/src/linux-headers-4.6.0-0.bpo.1-common/arch/x86/include/asm/current.h:17:17: warning: passing argument 2 of ‘get_user_pages’ makes integer from pointer without a cast
 #define current get_current()
                 ^
/tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.c:1165:37: note: in expansion of macro ‘current’
    retval = get_user_pages(current, current->mm, (unsigned long)uvAddr,
                                     ^
In file included from /tmp/modconfig-XSGuvk/vmmon-only/./include/compat_page.h:23:0,
                 from /tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.c:32:
/usr/src/linux-headers-4.6.0-0.bpo.1-common/include/linux/mm.h:1288:6: note: expected ‘long unsigned int’ but argument is of type ‘struct mm_struct *’
 long get_user_pages(unsigned long start, unsigned long nr_pages,
      ^
/tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.c:1165:13: error: too many arguments to function ‘get_user_pages’
    retval = get_user_pages(current, current->mm, (unsigned long)uvAddr,
             ^
In file included from /tmp/modconfig-XSGuvk/vmmon-only/./include/compat_page.h:23:0,
                 from /tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.c:32:
/usr/src/linux-headers-4.6.0-0.bpo.1-common/include/linux/mm.h:1288:6: note: declared here
 long get_user_pages(unsigned long start, unsigned long nr_pages,
      ^
/usr/src/linux-headers-4.6.0-0.bpo.1-common/scripts/Makefile.build:296: recipe for target '/tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.o' failed
make[4]: *** [/tmp/modconfig-XSGuvk/vmmon-only/linux/hostif.o] Error 1

Virtual machine monitor랑 Virtual ethernet모듈이 컴파일중 오류나는것으로 확인
찾아보니 kernel 4.6이후부터 호출 인자가 좀 바꼈나봄
/usr/lib/vmware/modules/source여기에 커널모듈 소스들이 존재함
가서 tar로 vmmon이랑 vmnet을 잘 풀고 ..

diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c
--- a/vmmon-only/linux/hostif.c
+++ b/vmmon-only/linux/hostif.c
@@ -1162,8 +1162,13 @@
int retval;

down_read(&current->mm->mmap_sem);
- retval = get_user_pages(current, current->mm, (unsigned long)uvAddr,
- numPages, 0, 0, ppages, NULL);
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
+ retval = get_user_pages((unsigned long)uvAddr,
+ numPages, 0, 0, ppages, NULL);
+ #else
+ retval = get_user_pages(current, current->mm, (unsigned long)uvAddr,
+ numPages, 0, 0, ppages, NULL);
+ #endif
up_read(&current->mm->mmap_sem);
return retval != numPages;
diff --git a/vmnet-only/userif.c b/vmnet-only/userif.c
--- a/vmnet-only/userif.c	2016-04-22 19:19:36.852205070 -0700
+++ b/vmnet-only/userif.c	2016-04-22 19:21:26.317845433 -0700
@@ -113,8 +113,12 @@
int retval;
down_read(&current->mm->mmap_sem);
- retval = get_user_pages(current, current->mm, addr,
-	1, 1, 0, &page, NULL);
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
+ retval = get_user_pages(addr, 1, 1, 0, &page, NULL);
+ #else
+ retval = get_user_pages(current, current->mm, addr,
+ 1, 1, 0, &page, NULL);
+ #endif
up_read(&current->mm->mmap_sem);
if (retval != 1) {

를 적용시켜주고 다시 잘 묶은뒤
vmware-modconfig –console –install-all
뙇!

Starting VMware services:
   Virtual machine monitor                                             done
   Virtual machine communication interface                             done
   VM communication interface socket family                            done
   Blocking file system                                                done
   Virtual ethernet                                                    done
   VMware Authentication Daemon                                        done
   Shared Memory Available                                             done

잘된다

KERNEL – 4.6-rc1 Released – OK with Latest VMware, Breaks NVIDIA – and a Possible Fix..

커널 모듈만 컴파일 하는 방법

Ways to compile kernel modules

커널 소스 디렉터리에서 아래 커맨드 진행 ( ecryptfs만 컴파일 하는경우)

make oldconfig
cp ../linux-headers-4.0.0-kali1-amd64/Module.symvers ./

make prepare
make modules_prepare
make SUBDIRS=fs/ecryptfs/ modules

또는 모듈디렉터리로 이동 후

make -C /usr/src/[linux-header~] /build M=$(PWD) modules

알면 쉽고 모르면 어렵다…

 

linux 디스크 입출력 속도 확인 캐시 드랍

dd if=something of=somewhere bs=4K/1M/2M/4M count=testsize oflag=dsync

 

  • To free pagecache:
    # echo 1 > /proc/sys/vm/drop_caches
    
  • To free dentries and inodes:
    # echo 2 > /proc/sys/vm/drop_caches
    
  • To free pagecache, dentries and inodes:
    # echo 3 > /proc/sys/vm/drop_caches

     

 

 

http://unix.stackexchange.com/questions/87908/how-do-you-empty-the-buffers-and-cache-on-a-linux-system

https://romanrm.net/dd-benchmark

https://www.thomas-krenn.com/en/wiki/Linux_I/O_Performance_Tests_using_dd