chroot jail -- unable to mount image file

83 views
Skip to first unread message

Neal Holtz

unread,
Mar 22, 2008, 11:18:46 AM3/22/08
to sage-support, nho...@cee.carleton.ca
Hi,

I'm trying to build a chroot jail (on Ubunti feisty) using the
instructions in: http://www.sagemath.org/doc/html/inst/node10.html

I've created the image file and made a file system to here:

mke2fs -j sage_chroot.image

and no noticable errors

But I can't mount it. I've tried the following in /etc/fstab

/files/sage_chroot.image /sage_chroot ext3 bind 0 0

and several permuations, and I always get

"mount: Not a directory"

Due to space limitations, I'm not creating the image file on the
root partition, but on a mounted partition (which happens to be
a reiser fs). Here is the particulars of the most recent trial:

root@stub:/files# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
...
/dev/sda3 reiserfs 99375008 63940492 35434516 65% /files
...
root@stub:/files# ls -l
total 10009793
...
drwxr-xr-x 2 root root 48 2008-03-22 10:40 sage_chroot
-rw-r--r-- 1 root root 10240000000 2008-03-22 10:35
sage_chroot.image
...
root@stub:/files# mount -t ext3 --bind sage_chroot.image sage_chroot
mount: Not a directory

Grateful for any help.
Thanks
neal

Neal Holtz

unread,
Mar 22, 2008, 11:31:23 AM3/22/08
to sage-support
Well, talking to myself here, I was able to mount it using this
incantation:

root@stub:/files# mount -t ext3 -o loop sage_chroot.image sage_chroot
root@stub:/files/sage_chroot# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
...
/dev/sda3 reiserfs 99375008 63940492 35434516 65% /files
...
/files/sage_chroot.image
ext3 9842848 153192 9189656 2% /files/
sage_chroot

But that is quite different than the instructions, so I'm a little
curious...
but I think I'll just proceed ...

Crissy Ruffo

unread,
Mar 23, 2008, 8:44:39 PM3/23/08
to sage-support
Hey Neal,

I tried setting up a chroot jail (jail for short) this week. I run
Ubuntu gutsy (7.10), and had a similar problem. The only way to get
the file system mounted was to use loop instead of bind (or use
both). Also:
* I didn't have much luck with the third command up from the bottom,
chmod og-w -R /path to sage jail . Did this twice, and locked myself
out of everything on the system, not just the jail. Not sure why
(very careful typing the second time:) Third time around, I didn't use
it. Then, the rest below
* couldn't log into the jail as anything other than root
* when in the jail, switched user from root
* dchroot command depreciated, used schroot.
* couldn't run SAGE as anything other than root.
* couldn't get notebook to start in jail.

I was keeping a log of my particular install, but I never did get it
working! If you have better luck let me know! I've got a project
(over) due and the prof. wants to run the code on my machine; right
now, it's wide open :{

Crissy Ruffo

Neal Holtz

unread,
Mar 23, 2008, 10:05:32 PM3/23/08
to sage-support
Hi,

I actually did get it working on feisty yesterday, and have been using
it
quite a bit since and haven't noticed any major problems. I also kept
a rough log as I was going along. I'll attach it, but I apologize
that
I won't have any time to edit it for a couple of days. Its pretty
rough now
and has one or two false starts, and I wouldn't be surprised if I've
forgotten
to log one or two things, but here it is:

Installing sage chroot on stub, April 22, 2008:
==============================================

from http://www.sagemath.org/doc/html/inst/node10.html

cd /files
dd if=/dev/zero of=/sage_chroot.image bs=1024 count=10000000
mke2fs -j sage_chroot.image

sudo vim /etc/fstab
/sage_chroot.image /sage_chroot ext3 bind 0 0
sudo mount -a

didn't work ("mount: Not a directory"). instead do:

cd /files
mkdir sage_chroot
mount -t ext3 -o loop sage_chroot.image sage_chroot

adduser sageserver

Now from https://wiki.ubuntu.com/DebootstrapChroot

Getting and installing debootstrap

wget http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_1.0.7~feisty1_all.deb
dpkg --install debootstrap_1.0.7~feisty1_all.deb

Installing and configuring schroot

sudo apt-get install schroot
sudo mkdir /files/sage_chroot/sage1
sudo editor /etc/schroot/schroot.conf

[sage]
description=Sage Server
location=/files/sage_chroot/sage1
priority=3
users=sageserver
groups=sageserver
root-groups=root

Setting up your chroot with debootstrap

debootstrap --variant=buildd --arch i386 feisty /files/sage_chroot/
sage1 http://archive.ubuntu.com/ubuntu/

cp /etc/resolv.conf /files/sage_chroot/sage1/etc/resolv.conf
cp /etc/apt/sources.list /files/sage_chroot/sage1/etc/apt/
## did not do sed -i s/dapper/breezy/g ...
chroot /files/sage_chroot/sage1
apt-get update
apt-get install wget debconf devscripts gnupg nano #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
export TZ=America/Toronto in .profile
exit

If you dont want the locale warnings in your chroot add export
LANG=C to your ~/.bashrc

Getting stuff(X/ssh-agent/ect,dbus,mounting removables,modprobe,err
stuff) working automagicaly

This stuff didn't seem to make sense to me, so I didn't do it.

Back to http://www.sagemath.org/doc/html/inst/node10.html

> Our solution is to simply use /sage_chroot/home/server as the home directory, mounting it to /home/server. First we copy the home directory's contents the chroot filesystem:
> $ sudo cp -rpvf /home/server /sage_chroot/home/
> $ sudo rm -rf /home/server/*
>
> And again we edit the system fstab
> $ vim /etc/fstab
>
> and add the following lines:
> /tmp /sage_chroot/tmp none bind 0 0
> /dev /sage_chroot/dev none bind 0 0
> /sage_chroot/home/server /home/server none bind 0 0
> proc-chroot /sage_chroot/proc proc defaults 0 0
> devpts-chroot /sage_chroot/dev/pts devpts defaults 0 0

This didn't make much sense either. Its not clear why
/tmp and /dev have to be shared between chrooted and
non-chrooted environsments.

Instead, I did this to ensure the /home/sageserver was the same
in both non-chroot and chroot

chroot /files/sage_chroot/sage1
apt-get install adduser
adduser sageserver
exit

use emacs, pwconv to ensure that uid and gid for sageserver
is the same in both /etc and /files/sage_chroot/sage1/etc,
then:

on non-chroot:

rm -r /home/sageserver
mkdir /home/sageserver
mount --rbind /files/sage_chroot/sage1/home/sageserver /home/
sageserver

chroot /files/sage_chroot/sage1
apt-get install octave octave-forge octave2.9 octave2.9-forge
apt-get install gap-core ssh

su - sageserver
cd ~
wget http://www.sagemath.org/dist/src/sage-2.10.4.tar
tar xf sage-2.10.4.tar
mv sage-2.10.4 sage
exit # sageserver
exit # chroot

Now drop back to build from the non-chroot env

su - sageserver
cd ~
cd sage
time make
make clean

But, I couldn't get sage to run properly, so in unchrooted /etc/fstab
I have


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

mount -a

then

su
su - sageserver
schroot -c sage

seems to work

Crissy Ruffo

unread,
Mar 23, 2008, 10:50:09 PM3/23/08
to sage-support
Rough or not, thank you very much. I'll try it out tomorrow!

Crissy

On Mar 23, 9:05 pm, Neal Holtz <nho...@docuweb.ca> wrote:
> Hi,
>
> I actually did get it working on feisty yesterday, and have been using
> it
> quite a bit since and haven't noticed any major problems. I also kept
> a rough log as I was going along. I'll attach it, but I apologize
> that
> I won't have any time to edit it for a couple of days. Its pretty
> rough now
> and has one or two false starts, and I wouldn't be surprised if I've
> forgotten
> to log one or two things, but here it is:
>
> Installing sage chroot on stub, April 22, 2008:
> ==============================================
>
> fromhttp://www.sagemath.org/doc/html/inst/node10.html
>
> cd /files
> dd if=/dev/zero of=/sage_chroot.image bs=1024 count=10000000
> mke2fs -j sage_chroot.image
>
> sudo vim /etc/fstab
> /sage_chroot.image /sage_chroot ext3 bind 0 0
> sudo mount -a
>
> didn't work ("mount: Not a directory"). instead do:
>
> cd /files
> mkdir sage_chroot
> mount -t ext3 -o loop sage_chroot.image sage_chroot
>
> adduser sageserver
>
> Now fromhttps://wiki.ubuntu.com/DebootstrapChroot
>
> Getting and installing debootstrap
>
> wgethttp://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_...
> dpkg --install debootstrap_1.0.7~feisty1_all.deb
>
> Installing and configuring schroot
>
> sudo apt-get install schroot
> sudo mkdir /files/sage_chroot/sage1
> sudo editor /etc/schroot/schroot.conf
>
> [sage]
> description=Sage Server
> location=/files/sage_chroot/sage1
> priority=3
> users=sageserver
> groups=sageserver
> root-groups=root
>
> Setting up your chroot with debootstrap
>
> debootstrap --variant=buildd --arch i386 feisty /files/sage_chroot/
> sage1http://archive.ubuntu.com/ubuntu/
>
> cp /etc/resolv.conf /files/sage_chroot/sage1/etc/resolv.conf
> cp /etc/apt/sources.list /files/sage_chroot/sage1/etc/apt/
> ## did not do sed -i s/dapper/breezy/g ...
> chroot /files/sage_chroot/sage1
> apt-get update
> apt-get install wget debconf devscripts gnupg nano #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
> export TZ=America/Toronto in .profile
> exit
>
> If you dont want the locale warnings in your chroot add export
> LANG=C to your ~/.bashrc
>
> Getting stuff(X/ssh-agent/ect,dbus,mounting removables,modprobe,err
> stuff) working automagicaly
>
> This stuff didn't seem to make sense to me, so I didn't do it.
>
> Back tohttp://www.sagemath.org/doc/html/inst/node10.html
> wgethttp://www.sagemath.org/dist/src/sage-2.10.4.tar
Reply all
Reply to author
Forward
0 new messages