[nycbug-talk] nullfs, jails and quotas

Isaac Levy ike
Mon Jan 16 19:48:58 EST 2006


Hi All,

On Jan 15, 2006, at 3:35 PM, pete wright wrote:

>> Ok- I  have a solid solution for you- File-backed memory filesystems
>> (disk images, if you grok apple livin').
>>
>> I put a recipe in my lecture at Shmoo here, I'll post it to this list
>> if anyone requests it.  But better, it's a simple direct application
>> of the following howto:
>>
>> http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/disks-
>> virtual.html
>>
>> My thought is you could have 1 disk image with the ports tree on it,
>> and mount it readonly in the jails, over and over...  You could even
>> mount it read/write on one jail, and update it from that one jail...
>>
>> Why do I reccommend this? mdconfig(8) is VERY heavily supported, and
>> it's base is used in the 'new' mechanisms to mount things like devfs
>> and procfs (new as of 5.x branch...).
>>
>> Hope that helps you solve that problem?
>>
>
> I'd love to see the notes man.  i've been playing with memory file
> systems lately (mounting /tmp as a memfs partition for nagios to use
> as scratch space for example) and would to test this out on some
> jailing stuff.
>
> thanks!
> -pete

Dru grabbed me at ShmooCon to ask me to post the script to list here,  
so here's some stuff.  First is an anatomoical breakdown of how to  
make a blank disk image, (the handbook page is much better than what  
I write below, IMO), but at the end of this email I put a script you  
can use to simply make disk images.

Rocket-
.ike



################################################
# Dissection of how-to make the disks in 4 lines:
################################################
# writing 1gb blank file, (analagous to creating an unformatted  
harddrive)
dd if=/dev/zero of=1gb.img bs=1k count=1024k
#      dd | man dd(1) if you don't know what that is,
#      if | use /dev/zero to get null bytes to make a 'blank' disk
#      of | this is the name of the disk image, make it what you want
#      bs | block size of the disk blocks
#   count | 1024k (this would make a 1gb disk, 2048 would be 2gb,  
etc...)

# attaching the file (analagous to attaching a harddrive)...
mdconfig -a -t vnode -f 1gb.img -u 1101
#       mdconfig | utility to configure and enable memory disks
#             -a | attach
#       -t vnode | type of memory disk, vnode is file-backed
#     -f 1gb.img | the file to attach as a disk
#        -u 1101 | the device node number (what will show up in /dev)

# formating the disk...
disklabel -r -w md1101 auto
#   disklabel | man disklabel for more info
#          -r | This option allows a label to be installed on a
#               disk without kernel support for a label, such as when
#               labels are first installed on a system...
#   -w md1101 | write to disk device named foo
#        auto | extra flag to automatically format the disk

# detaching the disk (analagous to ejecting a harddrive)...
mdconfig -d -u 1101
#        -d | detach
#   -u 1101 | label number again
#
################################################

<start of handy script>
#!/bin/sh

# ike copy-paste script for making file-backed 'disk images'
#
# This script makes a handfull of blank 'disk images', in sizes
# useful for jail(8)-ing services.  Making the disks can take a very
# long time depending on disk speed, so it's handy to have these around
# pending free space availability.
#
# NOTICE: Depending on your disk space, you may need to comment out some
# of the larger disk sizes at the end of this file.  Be rational,  
please.
#
# One of these file-backed disk images can be mounted using the  
following:
#   mdconfig -a -t vnode -f diskimage.img -u 0
#   mount /dev/md0 /mnt
#
# for more information, use the man page for mdconfig(8)
#
# anatomy of what this disk does:
################################################################
# 1 Gigabyte (tiny system)
#echo 'writing 1gb blank file, (analagous to creating an unformatted  
harddrive)...'
#dd if=/dev/zero of=1gb.img bs=1k count=1024k
#echo 'attaching the file (analagous to attaching a harddrive)...'
#mdconfig -a -t vnode -f 1gb.img -u 1101
#echo 'formating the disk...'
#disklabel -r -w md1101 auto
#echo 'detaching the disk (analagous to ejecting a harddrive)...'
#mdconfig -d -u 1101
################################################################

if [ "$1" ]; then
     if [ "$2" ]; then
        filename=$2
     else
        filename=$1'gb.dmg'
     fi
     #echo $filename

     B=1024
     let fullsize=1024*$1
     fullcount=$fullsize'k'

     echo 'Writing blank '$1' gb file, (analagous to an unformatted  
harddrive)...'
     #echo '- skipping, debug ikenote'
     dd if=/dev/zero of=$filename bs=1k count=$fullcount
     echo ''

     echo 'Attaching the file (analagous to attaching a harddrive)...'
     mdconfig -a -t vnode -f $filename -u 110$1
     ls /dev | grep md110
     echo ''

     echo 'formating the disk using disklabel...'
     disklabel -r -w md110$1 auto
     ls /dev | grep md110
     echo ''

     echo 'detaching the disk (analagous to ejecting a harddrive)...'
     mdconfig -d -u 110$1
     echo ''

     echo 'Blank '$1' Gigabyte Disk Image ready for use,'
     ls -lah | grep $filename
     echo ''

else
   echo "You must specify an appropriate integer, to represent the  
size of the disk in Gigabytes."
   echo "usage: make_blank_disks.sh [int] [filename_optional]"

fi

<end of script>






More information about the talk mailing list