Category Archives: Linux / Unix

luks crypt partition resize

윈도우랑 리눅스랑 듀얼부팅하다가 윈도우를 전혀 안써서 지워버리기로했다. (사실 ssd 용량이 딸려서…)
백업은 필수라지만 귀찮고 귀찮고 귀찮아서 백업을 하지않고 진행(다행히도 날리진 않았다)
다음은 resize 절차이다 ( 확장할때 사용한 명령어들, 축소는 음… 글쎄…)

본인의 경우는 root directory는 luks가 적용이 되어있지 않아 그냥 부팅한 후 /home 을 umount 하여 진행하였다.

sudo gparted 로 윈도우 파티션 정리 밑 swap 축소
sudo cryptsetup luksClose crypt-vol 로 luks close 해줌
sudo parted 의 resizepart 명령어로 crypt-vol의 크기를 재지정해줌 gparted에선 아직 지원을 안하는듯..
sudo cryptsetup luksOpen crypt-vol
sudo cryptsetup resize crypt-vol
sudo e2fsck -f /dev/mapper/crypt-vol
sudo resize2fs /dev/mapper/crypt-vol

하고 mount 해주면 됨
나야뭐 다 날리면 인생 새출발할 각오로 백업을 안했는데 모든 파티션 작업에는 백업은 필수

생각보다 어렵진 않았다. live usb 이딴거 필요없었다.

Linux Loop Device

losetup 으로 루프디바이스를 설정하면 파티션들이 보여야되는데 보이지 않는 문제 발견

http://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device#673257

loop module max_part config
This is a decent method before 16.04.
loop is a kernel module, built into the kernel in Ubuntu 14.04.
If you configure it right, Linux automatically splits up the devices for you.
If you configure it right, Linux automatically splits up the devices for you.

cat /sys/module/loop/parameters/max_part

says how many partitions loop devices can generate.
It is 0 by default on Ubuntu 14.04 which is why no auto-splitting happens.
To change it, we can either add:

options loop max_part=31

to a file in /etc/modprobe, or:

GRUB_CMDLINE_LINUX="loop.max_part=31"

to /etc/default/grub and then sudo update-grub.
How to set a module parameter is also covered at: How to add kernel module parameters?
After a reboot, when you do:

sudo losetup -f --show my.img

it mounts the image to a /dev/loopX device, and automatically mounts the partitions to /dev/loopXpY devices.

의 해결책은 조금 귀찮으므로
https://lwn.net/Articles/274113/
에서 제시한  “modprobe loop max_part=63” 를 사용,

root@debian:~/z# ls /dev/loop0p*
/dev/loop0p1 /dev/loop0p2 /dev/loop0p3 /dev/loop0p4 /dev/loop0p5 /dev/loop0p6 /dev/loop0p7

잘된다

Vmware 12.5.0 on debian 8.6

최근 커널을 4.8.11로 바꾸고 vmware를 사용하려니 gcc 6.2.1버전이상을 찾는다…
아시다시피 Debian은 패키지 업데이트에 굉장히 보수적이어서 gcc 6.x버전은 아직 dev라인에 있다.

https://packages.debian.org/sid/amd64/gcc-6/download

뭐 대충 sid에서 패키지 받아서 /tmp에 풀었는데 별문제 없이 실행된다.
vmware modconfig도 path만 잡아주니 별 문제없이 슝슝 잘됨.

Stopping VMware services:
   VMware Authentication Daemon                                        done
   VM communication interface socket family                            done
   Virtual machine communication interface                             done
   Virtual machine monitor                                             done
   Blocking file system                                                done
modprobe: FATAL: Module vmnet not found.
make: Entering directory '/tmp/modconfig-QudNpU/vmmon-only'
Using kernel build system.
/usr/bin/make -C /lib/modules/4.8.11/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \
  MODULEBUILDDIR= modules
make[1]: Entering directory '/usr/src/linux-headers-4.8.11'
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/linux/driver.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/linux/hostif.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/apic.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/linux/driverLog.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/memtrack.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/hashFunc.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/vmx86.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/cpuid.o
/tmp/modconfig-QudNpU/vmmon-only/linux/driver.c:1283:1: warning: always_inline function might not be inlinable [-Wattributes]
 LinuxDriverSyncReadTSCs(uint64 *delta) // OUT: TSC max - TSC min
 ^
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/task.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/comport.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/common/phystrack.o
  CC [M]  /tmp/modconfig-QudNpU/vmmon-only/vmcore/moduleloop.o
  LD [M]  /tmp/modconfig-QudNpU/vmmon-only/vmmon.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /tmp/modconfig-QudNpU/vmmon-only/vmmon.mod.o
  LD [M]  /tmp/modconfig-QudNpU/vmmon-only/vmmon.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.8.11'
/usr/bin/make -C $PWD SRCROOT=$PWD/. \
  MODULEBUILDDIR= postbuild
make[1]: Entering directory '/tmp/modconfig-QudNpU/vmmon-only'
make[1]: 'postbuild' is up to date.
make[1]: Leaving directory '/tmp/modconfig-QudNpU/vmmon-only'
cp -f vmmon.ko ./../vmmon.o
make: Leaving directory '/tmp/modconfig-QudNpU/vmmon-only'
make: Entering directory '/tmp/modconfig-QudNpU/vmnet-only'
Using kernel build system.
/usr/bin/make -C /lib/modules/4.8.11/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \
  MODULEBUILDDIR= modules
make[1]: Entering directory '/usr/src/linux-headers-4.8.11'
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/driver.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/hub.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/userif.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/netif.o
In file included from ./include/linux/pci.h:35:0,
                 from /tmp/modconfig-QudNpU/vmnet-only/compat_netdevice.h:27,
                 from /tmp/modconfig-QudNpU/vmnet-only/netif.c:43:
./include/linux/pci_ids.h:2253:0: warning: "PCI_VENDOR_ID_VMWARE" redefined
 #define PCI_VENDOR_ID_VMWARE  0x15ad
 ^
In file included from /tmp/modconfig-QudNpU/vmnet-only/net.h:38:0,
                 from /tmp/modconfig-QudNpU/vmnet-only/vnetInt.h:26,
                 from /tmp/modconfig-QudNpU/vmnet-only/netif.c:42:
/tmp/modconfig-QudNpU/vmnet-only/vm_device_version.h:56:0: note: this is the location of the previous definition
 #define PCI_VENDOR_ID_VMWARE                    0x15AD
 ^
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/bridge.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/procfs.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/smac_compat.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/smac.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/vnetEvent.o
  CC [M]  /tmp/modconfig-QudNpU/vmnet-only/vnetUserListener.o
In file included from /tmp/modconfig-QudNpU/vmnet-only/net.h:38:0,
                 from /tmp/modconfig-QudNpU/vmnet-only/vnetInt.h:26,
                 from /tmp/modconfig-QudNpU/vmnet-only/bridge.c:52:
/tmp/modconfig-QudNpU/vmnet-only/vm_device_version.h:56:0: warning: "PCI_VENDOR_ID_VMWARE" redefined
 #define PCI_VENDOR_ID_VMWARE                    0x15AD
 ^
In file included from ./include/linux/pci.h:35:0,
                 from /tmp/modconfig-QudNpU/vmnet-only/compat_netdevice.h:27,
                 from /tmp/modconfig-QudNpU/vmnet-only/bridge.c:51:
./include/linux/pci_ids.h:2253:0: note: this is the location of the previous definition
 #define PCI_VENDOR_ID_VMWARE  0x15ad
 ^
  LD [M]  /tmp/modconfig-QudNpU/vmnet-only/vmnet.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /tmp/modconfig-QudNpU/vmnet-only/vmnet.mod.o
  LD [M]  /tmp/modconfig-QudNpU/vmnet-only/vmnet.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.8.11'
/usr/bin/make -C $PWD SRCROOT=$PWD/. \
  MODULEBUILDDIR= postbuild
make[1]: Entering directory '/tmp/modconfig-QudNpU/vmnet-only'
make[1]: 'postbuild' is up to date.
make[1]: Leaving directory '/tmp/modconfig-QudNpU/vmnet-only'
cp -f vmnet.ko ./../vmnet.o
make: Leaving directory '/tmp/modconfig-QudNpU/vmnet-only'
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

별문제 없다. 구글링해보니 명쾌한 해결책이 안나와있어서 포기할까 하다가 해봤는데 쉽게 풀려서 다행이다.

간단 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

잘된다

http://rglinuxtech.com/?p=1679#comment-16518