Sage Notebook - chroot - ubuntu/debian

by Andrew Calcutt last modified 2011-07-05T13:25:07+00:00
Install guide to create a sage server on ubuntu 9.10 or Debian 6.0

Reference Docs (Most of the commands came from the pages below) (Guide to install sage from source) (Guide to chroot sage) (another guide on setting up sage in chroot. Also includes scripts to start sage silently) (support thread with steps taken for chrooting sage) (Guide to create a basic chroot in ubuntu) (Guide on debootstrap, used by cage chroot instructions) (Basic schroot.conf info)

Set up sage chroot environment

1.)Make sure you have all the sage source requirements

apt-get install build-essential gfortran
apt-get install texlive xpdf evince      # Note: The sage site says to also install xdvi here, but ubuntu did not find it and I didn't install it.
apt-get install tk8.5-dev    # or the latest version available
apt-get install dvipng

2.) Install the chroot requirements

apt-get install dchroot debootstrap

3.) Create Sage chroot directory. I used /sage_chroot/

mkdir /sage_chroot

4.) create sage chroot user

adduser sageserver

5.) open /etc/schroot/schroot.conf and add the following.

description=Sage Server

6.) Create basic chroot files with debootstrap

#Ubuntu 9.10
debootstrap --variant=minbase --arch i386 karmic /sage_chroot/

#Debian 6
debootstrap --variant=minbase --arch i386 squeeze /sage_chroot/

7.)Set up networking and package sources in the chroot environment

cp /etc/resolv.conf /sage_chroot/etc/resolv.conf
cp /etc/apt/sources.list /sage_chroot/etc/apt/

8.) Configure chroot environment

chroot /sage_chroot/
apt-get update
#add sageserver user that will run sage
useradd sageserver
*modify chroot /etc/passwd so sageserver user UID matches normal /etc/passwd
#Set up authbind so sage can bind to port 443
apt-get install authbind
touch /etc/authbind/byport/443
chmod 500 /etc/authbind/byport/443
chown sageserver /etc/authbind/byport/443
#Install ImageMagick for sage animate()
apt-get --no-install-recommends install imagemagick

#whats below was commented out because it is not needed
#apt-get --no-install-recommends install wget debconf devscripts gnupg vim  #For package-building
#apt-get update  #clean the gpg error message
#apt-get install locales dialog  #If you don't talk en_US
#locale-gen en_GB.UTF-8  # or your preferred locale
#tzselect; TZ='Continent/Country'; export TZ  #Configure and use our local time instead of UTC; save in .profile

9.)Copy server home directory to chroot directory

cp -rpvf /home/sageserver /sage_chroot/home/
rm -rf /home/sageserver/*

10.) edit /etc/fstab and add the following

/tmp  /sage_chroot/tmp    none    bind  0  0
/dev  /sage_chroot/dev    none    bind  0  0
/sage_chroot/home/sageserver /home/sageserver none bind  0  0
proc-chroot /sage_chroot/proc proc defaults  0  0
devpts-chroot /sage_chroot/dev/pts devpts defaults  0  0

11.) run

mount -a

12.) edit /etc/dchroot.conf. add the following (this may be a new file)

sage /sage_chroot/

13.) Now get SAGE and install it to the desired subdirectory of /sage_chroot

cd ~
cd /sage_chroot
tar xvf ~/sage-x.y.z.tar
mv sage-x.y.z/ sage/
cd sage
make clean

14.) Set chroot permissions and make necessary changes

#remove write permissions from user group and other groups
chmod og-w -R /sage_chroot/*

#Fix /dev/null errors
rm /sage_chroot/dev/null
mknod -m 666 /sage_chroot/dev/null c 1 3

#fix /sage_chroot/tmp permission
chmod 1777 /sage_chroot/tmp

#create sage files (sage will not have permission to write them later. make sure to replace /sage with the sage directroy in your chroot environment)
echo > /sage_chroot/sage/local/lib/sage-flags.txt
echo /sage > /sage_chroot/sage/local/lib/sage-current-location.txt

#give sageserver user rights to the .sage folder (this should not be needed.)
chown -R sageserver:sageserver /home/sageserver/.sage

#Fix dependency error
cp /usr/lib/ /sage_chroot/lib/

15.) Switch to your chroor environment and test sage

chroot /sage_chroot/
su - sageserver

*If all went well you should be at the sage prompt with no errors


Set sage server to run at statup with init.d

So, Sage chroot is already set up. Now we need to create the init script and sage scripts to start sage in the background

#Copy the sage init files into their proper folders. The following files are added

#Add sageserver to default runtime
update-rc.d sageserver defaults

Document Actions