chrootメモ

os.chrootの動作メモ。
chrootを実行できる権限で実行する。

test.py

import os

def main():
    print os.path.abspath(__file__)
    os.chroot(os.path.dirname(os.path.abspath(__file__)))
    print os.path.abspath(__file__)

if __name__ == '__main__':
    main()

実行結果

$ sudo python test.py
/home/tokibito/test.py
/test.py