lxc에서 chroot를 사용하여 개발하려고 합니다. lxc 컨테이너 구성에서 "nested" 옵션을 활성화하고 chroot가 일반 Linux 시스템에 있는 것처럼 설치된 proc 및 devpts를 chroot에 바인딩했습니다.
불행하게도 chroot에서 ptys가 필요한 항목(예: "script" 명령)을 사용하려고 하면 다음과 같은 오류가 발생합니다.
root@manualdev:~# chroot /chroots/jessie-staging/
root@manualdev:/# script
script: openpty failed: No such file or directory
Terminated
root@manualdev:/#
시스템 메시지:
- 호스트 커널은 4.4.0-79-generic입니다.
- 호스트 배포판은 Ubuntu xenial입니다.
- 호스트 아키텍처는 arm64입니다.
- 컨테이너 배포판은 Debian Stretch입니다.
- 컨테이너 및 chroot 아키텍처는 armhf입니다.
- Chroot 배포판은 Raspbian입니다(jessie, Stretch 및 Buster로 테스트됨).
답변1
이 문제에 대한 해결책(교육받은 추측에 의해 발견됨)은 chroot에서 다음 명령을 실행하는 것입니다.
rm /dev/ptmx
ln -s /dev/pts/ptmx /dev/ptmx
100% 확신할 수는 없지만 이것이 필요한 이유는 lxc가 /dev/pts에 "다중 인스턴스 모드"를 사용하기 때문이라고 생각합니다. 문서에 따르면https://github.com/torvalds/linux/blob/v4.4/Documentation/filesystems/devpts.txt
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y이고 'newinstance' 옵션이 지정된 경우 마운트는 다중 인스턴스 모드에 있는 것으로 간주되며 devpts fs의 새 인스턴스가 생성됩니다. 이 인스턴스에서 생성된 모든 pty는 다른 devpt 인스턴스의 pty와 독립적입니다. 단일 인스턴스 모드에서와 마찬가지로 /dev/pts/ptmx 노드도 존재합니다. 다중 인스턴스 모드를 효과적으로 사용하려면 기호 링크나 바인드 마운트를 사용하여 /dev/ptmx의 열기를 "/dev/pts/ptmx"로 리디렉션해야 합니다.
이 파일의 업데이트된 버전을 보면 최신 커널에는 이 기능이 필요하지 않은 것 같습니다.
답변2
의사 터미널을 관리하는 devpts 파일 시스템을 설치해야 합니다.
마법 명령은 다음과 같습니다.
(루트로) # mount -t devpts devpts /dev/pts
다음은 의사 터미널 시스템이 제대로 작동하는지 확인하는 세션입니다.
root@e7440:/me/media/20230104a# mount |grep pts # Check, yup no devpts mounted
root@e7440:/me/media/20230104a# ls -lai /dev/pt* # /dev/ptmx exists, but /dev/pts is empty
233300 crw-rw-rw- 1 root root 5, 2 Jan 4 23:07 /dev/ptmx
/dev/pts:
total 8
237675 drwxr-xr-x 2 root root 4096 Jan 4 23:04 .
229757 drwxr-xr-x 4 root root 4096 Jan 3 14:31 ..
root@e7440:/me/media/20230104a# mount -t devpts devpts /dev/pts
root@e7440:/me/media/20230104a# mount |grep pts
devpts on /dev/pts type devpts (rw)
root@e7440:/me/media/20230104a# # Let's test the pty system using the script command.
root@e7440:/me/media/20230104a# # the script command will log the shell to its_alive.txt
root@e7440:/me/media/20230104a# script its_alive.txt
Script started, file is its_alive.txt
root@e7440:/me/media/20230104a# ls -lai /dev/pt* # Now after the mount, things have changed!
233300 crw-rw-rw- 1 root root 5, 2 Jan 4 23:08 /dev/ptmx
/dev/pts:
total 4
1 drwxr-xr-x 2 root root 0 Jan 4 23:08 .
229757 drwxr-xr-x 4 root root 4096 Jan 3 14:31 ..
3 crw------- 1 root root 136, 0 Jan 4 23:08 0
2 c--------- 1 root root 5, 2 Jan 4 23:08 ptmx
root@e7440:/me/media/20230104a# # Note the 0 entry! That's the pty we are using to log this with the script command!
root@e7440:/me/media/20230104a# # Also note it is using inode 3 on the devpts file system instance
root@e7440:/me/media/20230104a# # And that it is a 'c' a character device node.
root@e7440:/me/media/20230104a# mount |grep pts
devpts on /dev/pts type devpts (rw)
root@e7440:/me/media/20230104a# umount /dev/pts # Let's go back to no ptys, but wait ...
umount: /dev/pts: target is busy
(In some cases useful info about processes that
use the device is found by lsof(8) or fuser(1).)
root@e7440:/me/media/20230104a# # Naughty! We're using a pty, so we can't get rid of ptys
root@e7440:/me/media/20230104a# exit # We are leaving the script session so its_alive.txt will get closed.
exit
Script done, file is its_alive.txt
root@e7440:/me/media/20230104a# #### Now we can get rid of ptys entirely as no ptys are in use
root@e7440:/me/media/20230104a# ls -lai /dev/pt*
233300 crw-rw-rw- 1 root root 5, 2 Jan 4 23:09 /dev/ptmx
/dev/pts:
total 4
1 drwxr-xr-x 2 root root 0 Jan 4 23:08 .
229757 drwxr-xr-x 4 root root 4096 Jan 3 14:31 ..
2 c--------- 1 root root 5, 2 Jan 4 23:08 ptmx
root@e7440:/me/media/20230104a# ### See no 0 entry (but the /dev/pts/ptmx is there because devpts is mounted)
root@e7440:/me/media/20230104a# mount |grep pts
devpts on /dev/pts type devpts (rw)
root@e7440:/me/media/20230104a# umount /dev/pts
root@e7440:/me/media/20230104a# mount |grep pts
root@e7440:/me/media/20230104a# ls -lai /dev/pt*
233300 crw-rw-rw- 1 root root 5, 2 Jan 4 23:09 /dev/ptmx
/dev/pts:
total 8
237675 drwxr-xr-x 2 root root 4096 Jan 4 23:04 .
229757 drwxr-xr-x 4 root root 4096 Jan 3 14:31 ..
root@e7440:/me/media/20230104a# # Let's see that our session log exists
root@e7440:/me/media/20230104a# ls -l its*
-rwxr-xr-x 1 root root 1025 Jan 4 23:09 its_alive.txt
root@e7440:/me/media/20230104a# # Let's see the session log contents
root@e7440:/me/media/20230104a# grep -n "^" its_alive.txt #Line numbers, please!
1:Script started on Wed Jan 4 23:08:47 2023
2:root@e7440:/me/media/20230104a# ls -lai /dev/pt*
3:233300 crw-rw-rw- 1 root root 5, 2 Jan 4 23:08 /dev/ptmx
4:
5:/dev/pts:
6:total 4
7: 1 drwxr-xr-x 2 root root 0 Jan 4 23:08 .
8:229757 drwxr-xr-x 4 root root 4096 Jan 3 14:31 ..
9: 3 crw------- 1 root root 136, 0 Jan 4 23:08 0
10: 2 c--------- 1 root root 5, 2 Jan 4 23:08 ptmx
11:root@e7440:/me/media/20230104a# # Note the 0 entry! That's the pty we are using to log this with the script command!
12:root@e7440:/me/media/20230104a# mount |grep pts
13:devpts on /dev/pts type devpts (rw)
14:root@e7440:/me/media/20230104a# umount /dev/pts
15:umount: /dev/pts: target is busy
16: (In some cases useful info about processes that
17: use the device is found by lsof(8) or fuser(1).)
18:root@e7440:/me/media/20230104a# # Naughty! We're using a pty
19:root@e7440:/me/media/20230104a# exit
20:exit
21:
22:Script done on Wed Jan 4 23:09:46 2023
root@e7440:/me/media/20230104a# # Yup, life is good!
원천:
- https://www.cyberciti.biz/faq/linux-mount-devpts/#:~:text=mount%20-t%20devpts%20devpts%20/dev/pts
- https://en.wikipedia.org/wiki/Devpts
- https://web.archive.org/web/20230105042607/http://faculty.cooper.edu/lent/random/GNU_screen_command.html
- 논문: 가상 터미널 서비스, 1987, Christopher Lent, Cooper Alliance for the Advancement of Science and the Arts: Albert Nerken School of Engineering