limit jail disk space

Jone Jas jas_arlerr at
Tue Jul 12 12:12:33 GMT 2005

Thanks for your reply. I googled and found this method but I just 
did not have a try.
As for the code-hacking method I mentioned, anyone with any idea
is appreciated!

Dominic Marks <dom at> дµÀ£º
On Tuesday 12 July 2005 10:50, Jone Jas wrote:
> Hi hackers,
> As far as I know, there is no limit of the disk space that a jail
> can use. As for the Linux VServer(similar to jail), its dlimit does
> such thing for the "security context". I read the dlimit code and
> find that it achieves that by limiting the number of inodes and data
> blocks the vserver can get. The hooks are inserted in the functions
> such as ext2_new_inode, ext2_free_inode, ext2_new_block and
> ext2_free_block. My question is if we can do such thing to the jail.
> If so, where should we insert the hooks? It seems that the FreeBSD
> inode/block allocation/free functions are not so explicit as Linux.
> There are serveral places, I'm not sure which are the correct ones:
> for inodes: ffs_valloc, ffs_vfree
> for blocks: ffs_alloc, ffs_freeblk,
> or ufs_balloc_ufs1/2
> Any reply or hints is appreciated!
> Regards!

One method which does not require hacking any code:

# dd if=/dev/zero of=jail.file bs=1k count=1m
1048576+0 records in
1048576+0 records out
1073741824 bytes transferred in 23.940393 secs (44850635 bytes/sec)

# ls -lh jail.file 
-rw-r--r-- 1 dom dom 1.0G Jul 12 11:08 jail.file

# mdconfig -a -t vnode -f jail.file 

# newfs -U /dev/md0 
/dev/md0: 1024.0MB (2097152 sectors) block size 16384, fragment size 
using 6 cylinder groups of 183.44MB, 11740 blks, 23488 inodes.
with soft updates
super-block backups (for fsck -b #) at:
160, 375840, 751520, 1127200, 1502880, 1878560

# mount /dev/md0 /mnt

# df -ih
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/md0 989M 4.0K 910M 0% 2 140924 0% /mnt

Now just install your jail into /mnt and it will be confined to the
size of disc you create. Expect slightly reduced disc performance using
this technique.

> Jas
> ---------------------------------
> ÑÅ»¢Ãâ·ÑGÓÊÏ䣭ÖйúµÚÒ»¾øÎÞÀ¬»øÓʼþɧÈų¬´óÓÊÏä
> _______________________________________________
> freebsd-hackers at mailing list
> To unsubscribe, send any mail to
> "freebsd-hackers-unsubscribe at"

Dominic Marks


More information about the freebsd-hackers mailing list