• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

[GUIDE] Making a VPS (Jail)

Nimsical

Hi, I'm Nima
I spent a noticeable amount of time researching on how to make a VPS (Virtual Private Server) on my FreeBSD machine, and after 3 hours of endless reading I finally got into doing it and it took me 30 minutes! So I decided to write a guide for it on my site, I've put a copy here for you.

If you want to add a guide for another distro, just mail me the html code or bbcode (mail: nima@mformature.net)
Here's a copy of my guide from Halfmoon.ws
[fieldset="FreeBSD"]
1. Configuring your running daemons
You need to make sure that none of your daemons are listening to *:* for that you have to first run:

Shell Command:
Code:
sockstat | grep *:
You will get a list of daemons that are listening on all the ports, or at least on all of your ip addresses.

You're going to have to edit all those daemons' configuration files and restart them before starting your jail (VPS)
Moving on.


2. Creating World
You have to install a 'world' (a copy of FreeBSD) into your jail directory.
But first, you're gonna need to create your jail directory.
I'm gonna create a JAILDIR variable so I can use it through this guide, too. For easier input.

Shell Command:
Code:
#Setup environment variable for future use
setenv NEWJAIL /full/path/to/jail/dir

#create directory
mkdir -p $NEWJAIL

# Now you have to enter your FreeBSD's /usr/src distrobution
# directory, it has all the files needed to create a 'world' copy # of your system.
cd /usr/src

# Now make a world into our jail's directory:
make world DESTDIR=$NEWJAIL

# Change directory to /usr/src/etc
cd etc/
# Make a copy of all the configuration files into your new jail
make distribution DESTDIR=$NEWJAIL
It takes a while for FreeBSD to build a 'world' and install it into the directory, so get some coffee while it's running.

Can't make world?
However, if you got an error when you executed that last line about how it doesn't know how to create world. It means that you don't have the files on your system, but no biggie you can get them off your FreeBSD CD, or from one of FreeBSD's servers.

The best way to do this is using sysinstall ([ 5 it's /stand/sysinstall, [ 6 it's /usr/sbin/sysinstall), it provides you with an easy menu. You can choose whether or not you want to download the files or copy the off your FreeBSD CD but either way here's what you need to get:
In the menu:
Code:
Goto Configure.
Choose: Distributions
Check "src" (ALL)
Then install.

3. Setting up your Jail devices
If you're on FreeBSD 5.x/6.x/7.x then you can use this command to mount the devices for your jail:
Code:
mount -t devfs devfs $NEWJAIL/dev
If you're on FreeBSD 4.x then you can use this snippet:
Code:
cd $NEWJAIL/dev
sh
MAKEDEV jail
You also need to create a null kernel before you start it off:
Code:
cd $NEWJAIL
ln -sf /dev/null kernel

4. Starting your Jail
Now there are different ways of starting your jail.
But either way, I highly recommend you copy the `sysinstall' binary to your jail's sbin directory:

Code:
cp `which sysinstall` $NEWJAIL/usr/sbin/
You can use sysinstall to configure your jail system, whether it's setting your root password or installing necessary software, it's easy to use and really helpful at times.

Here I've explained two ways to run your jail (I like the first one better, it's easier to kill/start it)

1. Putting your jail in your rc.conf
Before you do this, you need to name your jail. Here I'm gonna use "code" as the name for my jail example:

Add these lines to your rc.conf: (located at /etc/rc.conf)
Code:
jail_enable="YES"   # Set to NO to disable starting of any jails
jail_list="code"     # Space separated list of names of jails

# define code:
jail_code_rootdir="/disk1/code"     # jail's root directory (same as $NEWJAIL's value)
jail_code_hostname="code.halfmoon.ws"  # jail's hostname
jail_code_ip="208.43.107.151"           # jail's IP address
# Note that I have no idea how this part is done in 4.x
jail_code_devfs_enable="YES"          # mount devfs in the jail
jail_code_devfs_ruleset="code_ruleset" # devfs ruleset to apply to jail
After you do that, all you really have to do to start or kill your jail is this:
Code:
/etc/rc.d/jail start code # To start your jail
/etc/rc.d/jail stop code  # To kill/stop your jail
Although, stopping a jail (completely) isn't really easy.
One of the best ways is to use the rc.shutdown script that's inside the jail's /etc directory. Please note that this has to be done from within the jail itself.

2. Using the jail command
This is a more old fashioned way of running your jail, it also needs you to do some extra mounts for the proc:
Code:
mount -t procfs proc $NEWJAIL/proc #mount proc
# jail command's syntax: jail [jail dir] [hostname] [ip] ["command to be run"]
jail $NEWJAIL jail.hostname.com xxx.xxx.xxx.xxx /bin/sh /etc/rc
Note that the ip has to be usable ip that your machine has access to and no daemon is listening on, or there will be complications.


5. Configuring your Jail
To list the current running jails on your system, you can run this command:

Code:
jls
To execute a command for a specific jail you have to copy it's JID from `jls's output and run jexec.
Now, for an easier way to configure things you can run a /bin/sh copy and run any commands that you want:

Code:
jexec [jid from jls] /bin/sh
Or maybe you just want to install some packages, and/or change some settings with your sysinstall copy:

Code:
jexec [jid from jls] /usr/sbin/sysinstall
From here on, you can do whatever you want with your jail.
However, please understand that there is no possible way to fully kill a jail. Although, I can give you some pointers on how to do it:
  • You can run a /bin/sh shell and kill all the pids in `ps auux'[/li]
  • You can run your jail's /etc/rc.shutdown file.[/li]
  • You can use /etc/rc.d/jail stop [jail name], but this one doesn't really work all the time.[/li]
All done, and only in 5 steps!
Have fun with your newly setup VPS.
[/fieldset]
 

Cryox

Bro.
this is kind of a stupid question i think, but what would making a VPS help accomplish exactly? i know that for some people it would help, but how and what does it do?
 

RoBz

sucker
I guess if you wanted to share your machine with a few others.

Thanks for the guide.
o/

EDIT:

20:13 <@Nimsical> RoBz, I lol at your response to my thread
20:15 <@Nimsical> RoBz, a VPS has much, much more abilities and advantages

Yeaaaah
 

Nimsical

Hi, I'm Nima
Top