fakeroot.at

Automatic chroot wrapper Deutsch English

» Home » Projects » autochroot2009-05-03 22:09:44

autochroot is a Perl script that simplifies the process of entering a chroot jail in Linux.

Features

  • Automatically mounts /proc, /dev, and /sys
  • Copies /etc/resolv.conf to allow domain name resolving within the jail
  • Generates a modified mounting table (/etc/mtab) to allow scripts like grub-install to work
  • When invoked without parameters, it automatically looks for partitions containing linux installations and lets you choose one of them interactively.
  • As target parameter you can use a device node (e.g. /dev/sda1) or any directory where a linux is installed.
  • After logging out of the chroot-jail, all previosly mounted filesystems are unmounted and temporary resources will be deleted
  • Works great in Live-CD environments (e.g. to reinstall GRUB)

Installation (as root)

  • Download the script:
    wget http://projects.fakeroot.at/autochroot/autochroot -O /usr/sbin/autochroot
  • make the script executable:
    chmod +x /usr/sbin/autochroot
  • run the script
    autochroot
    and follow the instructions on the screen.

or in one line:

wget http://projects.fakeroot.at/autochroot/autochroot -O /usr/sbin/autochroot && chmod +x /usr/sbin/autochroot && autochroot

How it works

When invoking autochroot without parameters, the program will be executed as described below:

  • create a temporary directory via mktemp to mount file systems at
  • look for Linux partitions (ext-formatted) using 'fdisk -l'
  • search /bin/bash on the partitions (temporarly mount them if necessary)
  • get OS information for the current partition if a /bin/bash is present
  • unmount temporarly mounted partitions
  • show a distribution list and wait for user input
  • mount the distribution if necessary
  • mount /dev, /proc and /sys within the jail
  • copy /etc/resolv.conf and a modified /etc/mtab into the jail
  • chroot to the selected distribution
  • unmount partitions, release all resources and delete the temporary directory

License

This script is published under the terms of the GNU GPL v2 license.

Known Limitations

  • It's not possible to chroot into a 64-bit system from a 32-bit kernel.
  • Currently only ext-partitions are recognized automatically. If you want other stuff to be supported, contact me.
    However, it's still possible to use autochroot non-interactively in that case.

Bugs

  • autochroot automatically detects if you want to chroot into the root partition of the currently running OS. However, if you execute it from within a jail it won't prevent you from chrooting into your live system and will mess up your /etc/mtab.
    So, DON'T USE autochroot FROM WITHIN A CHROOT JAIL!

Contact

If you've found a bug, want a specific feature in autochroot or anything else, feel free to contact me at
autochroot at this domain name.

Valid XHTML 1.0