Convention Listings
                                                                                                                        About Us | Donate! | Contribute! | Report Problems
   
Raiden's Realm is always in need of good, community generated articles and content for our site. So if you have a Linux, Open Source or Media Freedom related article, review, tutorial, or editorial you want to contribute, by all means please submit it to admin@raiden.net. Your contributions are always appreciated and will help us out immensely. Thanks.
   
Mini HOWTO: Setting up a Home Web Server by CHROOTing BusyBox's httpd in Tiny Core Linux v2.0 (Page 1 of 1)

Written by HE PingPing
Posted on: Jun 17, 2009 at 01:16pm
Section: Tutorials
Printer Friendly Version
Legacy URL

First we need to create the user which we're going to chroot.  In this HOWTO I'll be using the user 'www' and also creating a new group of the same name:

sudo addgroup -g 80 www
sudo adduser -h /home/www -s /bin/false -G www www
(enter any password you like)
Here I've created the user 'www' (the second 'www' in adduser), made it a member of the www group ('-g www'), given it a home directory of /home/www and set its login shell to /bin/false.  By doing the latter, there is no shell availabel for anyone trying to login as user 'www'.  This is a important security feature.

While Tiny Core Linux (TCL) uses BusyBox for its command line utilities, it was not built with BusyBox's httpd server, so we must compile it from source ourselves.  All of the necessary compile tools are available from the TCL repos.  What is needed are the following:

gcc-binutils.tce
base_devs.tce
bison.tce
diffutils.tce
file.tcel
findutils.tce
flex.tce
gawk.tce
gperf.tce
grep.tce
help2man.tcel
m4.tce
make.tce
patch.tce
pkg-config.tce
sed.tce

Once we have these installed we need to download the BusyBox source code tarball, unpack it, change directory into the unpacked code and make a blank .config file:
$  wget http://www.busybox.net/downloads/busybox-1.14.1.tar.gz
$
 tar -xzf busybox-1.14.1.tar.gz
$  cd busybox-1.14.1
$  make allnoconfig

Building BusyBox is similar to building the Linux kernel in that we 'make menuconfig && make install', so first we must configure the BusyBox build:
$  make menuconfig
Here you'll be greeted with the kernel-esque type ncurses configuration menu.  Navigate to BusyBox Settings > Installation Options > BusyBox installation prefix.  You'll see that it's currently set to './_install'.  Change this to '/home/www' so that the binaries will be installed to /home/www which is going to be the top of our chrooted directory tree.  Next, get back to the main config menu page and go to Coreutils, scroll down and select 'false' (using the space bar).  Next, return to the main menu and go to Network Utilities and select httpd (again, using the space bar).  Now the selection will have expanded with a few more options.  Choose the one called 'Enable -u option (NEW)'.  You can leave everything else as it is.  Finally, exit the config saving your changes.  Now just:
$  sudo make install
You should now see /home/www has been populated with the following:

bin/busybox
bin/false
usr/sbin/httpd

the latter two of which are soft links to the first.

Next we must copy some key files to /home/www to prepare it as the chrooted environment:
$  sudo mkdir /home/www/etc /home/www/lib
$  sudo cp /etc/group  /home/www/etc/
$  sudo cp /etc/passwd  /home/www/etc/
$  sudo cp /etc/shadow  /home/www/etc/
$  sudo cp /etc/hosts  /home/www/etc/
$  sudo cp /etc/hostname  /home/www/etc/
$  sudo cp /etc/nsswitch.conf  /home/www/etc/
$  sudo cp /etc/resolv.conf  /home/www/etc/
$  sudo cp /lib/libnss_compat-2.9.so  /home/www/lib/libnss_compat.so.2
$  sudo cp /lib/libnss_dns-2.9.so  /home/www/lib/libnss_dns.so.2
$  sudo cp /lib/libnss_files-2.9.so  /home/www/lib/libnss_files.so.2
$  sudo cp /lib/libc-2.9.so  /home/www/lib/libc.so.6
$  sudo cp /lib/ld-2.9.so  /home/www/lib/ld-linux.so.2
Next, remove all lines in:

/home/www/etc/group
/home/www/etc/passwd
/home/www/etc/shadow

that don't refer to user/group 'www', ie. there should be just one line left in each file after the deletions.  Finally, make everything in /home/www owned by user 'www' and group 'www':
sudo chown -R www.www /home/www
Finally, just create/add any index.html file in /home/www and start things up:
sudo chroot /home/www /usr/sbin/httpd -u www:www
If you 'ps' you should see something like:
7543  www     /usr/sbin/httpd -u www:www
Note the process ID (7543 in my case).  To test the chroot has worked:
sudo ls -l /proc/7543/root
and you should see that /home/www is the start of the (chrooted) directory tree.
Discuss this!  ( 8 comments )

Raiden's Realm Social Bookmarking
If you have any problems with any of these links, please let us know.  Thanks.

Digg it! Slashdot It! Del.icio.us Add to StumbleUpon Add to Technorati Reddit! Add to Google Bookmarks Add to FaceBook Share Add to Twitter

Average vistor rating: 4.6 out of 5 (5 total votes)

Community Image Gallery

More Images
Submit new images to gallery

Upcoming Shows and Cons

 1.  LinuxCon 2010
 2.  OpenSource World 2010
 3.  Ohio Linux Fest 2010
 4.  Atlanta Linux Fest 2010
 5.  ESC Boston 2010
More

Announcements

This is just a reminder to everyone that we're always looking for articles for posting on our site.  So if you have a Linux, Open Source or Media related article, review, tutorial, or editorial you want to post, by all means please send it to admin@raiden.net and we'll be glad to post it.  Thanks.

Have you ever bought a PC or laptop preloaded with Linux?

Yes
No
Considering it
Other ( Please specify )

More Polls
Latest Releases
(courtesy of Distrowatch)

1. Clonezilla Live 1.2.5-38...
Released: 07/29
2. RIPLinuX 10.6
Released: 07/29
3. Mint 9-rc (Fluxbox)
Released: 07/29
4. Nexenta 3.0-rc3
Released: 07/29
5. Salix 13.0.1
Released: 07/29
6. AUSTRUMI 2.1.6
Released: 07/28

More
All original content on this site is copyright of Raiden's Realm via the Creative Commons license. All rights reserved.

Any non original content is the sole property of the respective owners.