namespace(mount)
2025. 3. 20. 15:35ㆍ리눅스/실무 초밀착 리눅스
명령어 unshare를 통해 namespace를 생성해보자.
unshare는 기존 프로세스에서 분리된 새 네임스페이스를 생성하는 역할을 한다.
이걸 활용하면 특정 리소스(네트워크, 파일 시스템, PID, 유저 등)를 기존 시스템과 독립적으로 실행할 수 있다.
# 새로운 mount namespace 생성
root@k8s-master:~# echo $$
7031
root@k8s-master:~# unshare -m /bin/bash
root@k8s-master:~# echo $$
7622
# tmpfs 마운트
root@k8s-master:~# mount -t tmpfs tmpfs /mnt
root@k8s-master:~# mount | grep /mnt
tmpfs on /mnt type tmpfs (rw,relatime,inode64)
# 테스트 파일 생성
root@k8s-master:~# echo "Hello" > /mnt/hello.txt
root@k8s-master:~# cat /mnt/hello.txt
Hello
# Terminal을 새로 열어서 테스트 파일 내용 확인
root@k8s-master:~# nsenter -t 7622 -a
root@k8s-master:/# cat /mnt/hello.txt
Hello
'리눅스 > 실무 초밀착 리눅스' 카테고리의 다른 글
cgroup(pid 제한) (0) | 2025.03.05 |
---|---|
cgroup(cpu 제한) (0) | 2025.03.05 |