# mount -t overlay overlay -o lowerdir=/home/me,upperdir=/giant_disk/steam/overlay,workdir=/giant_disk/steam/working /giant_disk/steam/main #!/usr/bin/python3 import ctypes import ctypes.util import os import unshare libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p) def mount(source: bytes, target: bytes, fs: bytes=b'', flags: int=0, options: bytes=b''): ret = libc.mount(source, target, fs, flags, options) if ret < 0: errno = ctypes.get_errno() errstr = os.strerror(errno) raise OSError(errno, f"Error mounting {source} ({fs}) on {target} with options '{options}' and flags {flags}: {errstr}") uid = os.getuid() gid = os.getgid() wd = os.getcwd() os.chdir('/') unshare.unshare(unshare.CLONE_NEWNS|unshare.CLONE_NEWUSER) mount(b'/giant_disk/steam/main', b'/home/me', b'', 4096) with open('/proc/self/setgroups', 'wb') as f: f.write(b'deny') with open('/proc/self/uid_map', 'wb') as f: f.write(f'{uid} {uid} 1\n'.encode('ascii')) with open('/proc/self/gid_map', 'wb') as f: f.write(f'{gid} {gid} 1\n'.encode('ascii')) os.chdir(wd) os.execv('/bin/bash', ['/bin/bash']) # You run steam from this bash shell