schroot - chroot for any users

Posted by amadeu on Tue 27 Nov 2007 at 15:06

From manpages: schroot allows the user to run a command or a login shell in a chroot environment. If no command is specified, a login shell will be started in the user current working directory inside the chroot.

I've been trying some virtual machines solutions to execute some programs 32bits in my machine. But it's take very time, start a xen VM or virtualbox. Often this solutions needs some maintain additional costs to setup a X server to run any X-based program.

My initial motivation was that wengophone wasn't in Debian lenny for amd64 until some days ago. Thus I did want to run a x-based program in a single chroot as normal user.

The schroot makes a chroot's use easy! Very easy for end users.

  1. install into your original installation:
     # aptitude install schroot 
  2. configure the /etc/schroot/schroot.conf like:
    [sid]
    description=Debian sid (unstable)
    type=directory
    location=/srv/chroot/sid
    priority=3
    users=YOUR_USER
    groups=SOME_GROUP_LIKE_users
    root-groups=YOUR_ADMIN_USER
    run-setup-scripts=true
    run-exec-scripts=true
    
  3. creating a chroot:
     # debootstrap --arch i386 sid /srv/chroot/sid http://ftp.br.debian.org/debian 
  4. installing 32bit programs in the chroot:
     # schroot -c sid -p aptitude install wengophone 
  5. to run X programs make sure that your X session accept it and execute the schroot:
    $ xhost +
    $ schroot -c sid -p wengophone
  6. there is a more safer way to run X programs like comments below and a example of wengophone_wrapper script
  7. it isn't need mount /proc on fstab or other because run-setup-scripts and run-exec-scripts take care of this, but you should look the /etc/schroot/mount-defaults to set your specific directories
Shortcuts:
  1. create a wrapper script /usr/local/bin/wengophone_wrapper:
    #!/bin/bash
    ## UPDATED after the comment #16 to reduce security risk ;-)
    # right way for export Xauthority file
    xauth extract /srv/chroot/sid$HOME/.Xauthority $DISPLAY
    # run your command
    schroot -c sid -p wengophone
    # remove the Xauthority
    rm -f /srv/chroot/sid$HOME/.Xauthority
    
  2. permissions :
     # chmod +x /usr/local/bin/wengophone_wrapper 
  3. now you could create some wengo.desktop for your users :-)
PS: maybe wengophone example it's trivial, but try it with others programs only 32bit like the non-free skype

This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2007 amadeu - please ask for permission to republish or translate.