Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

Using MNT_DETACH (lazy unmount) on bind-mounted pseudo-filesystems like /dev/pts leaves the host in a broken state where PTY allocation fails (sudo: unable to allocate pty: No such device).

Changes

  • Unmount strategy: Try normal umount2(flags=0) first, fall back to MNT_DETACH only on EBUSY
  • Error handling: Cache raw_os_error() results to avoid redundant calls, properly distinguish EINVAL/ENOENT/EBUSY

Before:

let ret = unsafe { libc::umount2(target_cstr.as_ptr(), libc::MNT_DETACH) };

After:

// Try normal unmount first (safer for pseudo-filesystems like /dev/pts)
let ret = unsafe { libc::umount2(target_cstr.as_ptr(), 0) };
if ret == 0 { return Ok(()); }

let err_code = Error::last_os_error().raw_os_error();

// Fall back to lazy unmount only if busy
if err_code == Some(libc::EBUSY) {
    let ret = unsafe { libc::umount2(target_cstr.as_ptr(), libc::MNT_DETACH) };
    // ... handle errors ...
}

This prevents host filesystem corruption while maintaining backward compatibility for busy mounts.

Original prompt

使用docker导出乌班图 然后用这个BINARY="/root/rk8s/project/target/debug/examples/overlayfs_example"

sudo "$BINARY"
--mountpoint /root/merged
--upperdir /root/upper
--lowerdir /root/ubuntu-rootfs
--bind "proc:/proc"
--bind "sys:/sys"
--bind "dev:/dev"
--bind "dev/pts:/dev/pts"
--bind "etc/resolv.conf:/etc/resolv.conf"
--privileged接下来再开一个窗口 chroot ~/merged/ /bin/bash在里面进行apt update等操作都正常 但是ctrl+c退出overlayfs之后 再次运行(或者别的复杂操作)我宿主机就sudo: unable to allocate pty: No such device 只有运行mount -t devpts devpts /dev/pts才能解决 修复一下


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix PTY allocation issue after exiting overlayfs Fix bind mount unmount breaking host /dev/pts Dec 4, 2025
Copilot AI requested a review from LangQi99 December 4, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants