chroot to install packages

Chris Angelico rosuav at gmail.com
Thu Nov 14 04:32:29 EST 2013


On Thu, Nov 14, 2013 at 8:29 PM, Himanshu Garg <hgarg.india at gmail.com> wrote:
> I have written a script
>
> os.chroot("/lxc/test_container/rootfs")
> subprocess.call(["apt-key", "add", "/root/package.key"])
> subprocess.call(["apt-get", "update"])
>
> os._exit(0)
>
> Now, this script is working properly, entering the chroot jail and adding the apt key, but when the "apt-get update" command runs, it starts but throws me an error:
> "E: Unable to change to (unreachable)/lxc/test_container/ - chdir (2: No such file or directory)"

I'm not certain, but this might be due to chrooting without changing
directory. Unless os.chroot() does it for you, you'll want to
os.chdir("/") immediately afterwards. In any case, it's worth a try.

ChrisA



More information about the Python-list mailing list