ezjail 是一个用来创建、管理jail虚拟机的工具,通过使用nullfs以只读方式为虚拟机提供公共的基本系统部件。这样的做法有至少有三个好处:
安装ezjail当然是port。不管老鸟、菜鸟都知道
ezjail配置文件位于/usr/local/etc/ezjail.conf,这是一个自解释文件。
# ezjail.conf - Example file, see ezjail.conf(5) # # Note: If you alter some of those variables AFTER creating your first # jail, you may have to adapt /etc/fstab.* and EZJAIL_PREFIX/etc/ezjail/* by # hand # Location of jail root directories # # Note: If you have spread your jails to multiple locations, use softlinks # to collect them in this directory # 保存虚拟机为路径,缺省为/usr/jails,如果打算保存到其他目录,照下面的样子修改。 ezjail_jaildir=/opt/jails # Location of the tiny skeleton jail template # 建立虚拟机基本系统时模板路径,一般无需改变。 # ezjail_jailtemplate=${ezjail_jaildir}/newjail # Location of the huge base jail # 虚拟机基本系统路径,一般无需改变。 # ezjail_jailbase=${ezjail_jaildir}/basejail # Location of your copy of FreeBSD's source tree # 源代码路径,一般无需改变。 # ezjail_sourcetree=/usr/src # In case you want to provide a copy of ports tree in base jail, set this to # a cvsroot near you # Port系统的CVS根设置,一般不必要设置,我们用portsnap # ezjail_portscvsroot=freebsdanoncvs@anoncvs.FreeBSD.org:/home/ncvs # This is where the install sub command defaults to fetch its packages from # FreeBSD的FTP服务器。为神马不是ftp.cn.FreeBSD.org? # 世界上最远的距离是神马?你懂的。好吧,我承认,我很杯具地用了联通线路。 ezjail_ftphost=ftp.tw.freebsd.org # This is the command that is being executed by the console subcommand # ezjail_default_execute="/usr/bin/login -f root" # This is the flavour used by default when setting up a new jail # 这个是用来为虚拟机提供一个缺省的配置集,下面会进一步解释。Tips:我姓钱。不知道算不算亮点。 ezjail_default_flavour="chian" # This is the default location where ezjail archives its jails to # ezjail_archivedir="${ezjail_jaildir}/ezjail_archives" # base jail will provide a soft link from /usr/bin/perl to /usr/local/bin/perl # to accomodate all scripts using '#!/usr/bin/perl'... # ezjail_uglyperlhack="YES" # Default options for newly created jails # # Note: Be VERY careful about disabling ezjail_mount_enable. Mounting # basejail via nullfs depends on this. You will have to find other # ways to provide your jail with essential system files # 作者说要VERY小心,如果禁用ezjail_mount_enable的话。 # 以nullfs载入虚拟机基本系统是这个参数控制的,除非你另外给虚拟机提供基本系统,否则不应该禁用这个选项。 # devfs一般来说也不应该禁用。procfs和fdescfs一般来说可以禁用。 # ezjail_mount_enable="YES" # ezjail_devfs_enable="YES" # ezjail_devfs_ruleset="devfsrules_jail" ezjail_procfs_enable="NO" ezjail_fdescfs_enable="NO" # 下面这几行用于在ZFS建立虚拟机。只能在古董机器上玩FreeBSD的屌丝们,直接无视吧! # Setting this to YES will start to manage the basejail and newjail in ZFS # ezjail_use_zfs="YES" # Setting this to YES will manage ALL new jails in their own zfs # ezjail_use_zfs_for_jails="YES" # The name of the ZFS ezjail should create jails on, it will be mounted at the ezjail_jaildir # ezjail_jailzfs="tank/ezjail" # ADVANCED, be very careful! # ezjail_zfs_properties="-o compression=lzjb -o atime=off" # ezjail_zfs_jail_properties="-o dedup=on"
先看看${ezjail_jaildir}/flavours目录里都有神马?
# find /usr/jails/flavours /usr/jails/flavours/ /usr/jails/flavours/example /usr/jails/flavours/example/etc /usr/jails/flavours/example/etc/rc.d /usr/jails/flavours/example/etc/rc.d/ezjail.flavour.example /usr/jails/flavours/example/etc/rc.conf /usr/jails/flavours/example/etc/periodic.conf /usr/jails/flavours/example/etc/make.conf /usr/jails/flavours/example/usr /usr/jails/flavours/example/usr/local /usr/jails/flavours/example/usr/local/etc /usr/jails/flavours/example/usr/local/etc/sudoers /usr/jails/flavours/chian /usr/jails/flavours/chian/etc /usr/jails/flavours/chian/etc/make.conf /usr/jails/flavours/chian/etc/rc.conf /usr/jails/flavours/chian/etc/csh.cshrc /usr/jails/flavours/chian/etc/resolv.conf /usr/jails/flavours/chian/root /usr/jails/flavours/chian/root/.cshrc
看不懂?……不懂,……懂。你赢了,我很负责任地告诉你:“看……手……册……去……去……去!”
CPUTYPE?=core2 MASTER_SITE_OVERRIDE = \ ftp://ftp.tw.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/ \ http://mirrors.ustc.edu.cn/freebsd/ports/distfiles/${DIST_SUBDIR}/ # 显摆一下下 VIDEO_DRIVER=intel WITH_NEW_XORG=yes WITH_KMS=yes WITH_LCD_FILTERING=yes WITHOUT_DOCS=yes # 上面不说了,都是一些常规的设置。 # 如果需要在Jail虚拟机中使用port安装,下面这几行一定要设置。 # 对于Jail虚拟机来说,port树是只读的。 WRKDIRPREFIX= /var/ports DISTDIR= /var/ports/distfiles PACKAGES= /var/ports/packages INDEXDIR= /var/ports
defaultrouter="192.168.1.1" # ML定时嘛?那要CRON干神马? cron_enable="NO" # 介个嘛,保留吧,不然一个后台程序都没有的话,Jail虚拟机启动之后连尸首都不会有。 # -ss,就不要syslogd在网路上接客了,自家搞算鸟。 syslogd_flags="-ss" # 杀了sendmail,这个是必须的,不过某些精神病可定会有一大堆理由告诉你,要刀下留人。 sendmail_enable="NONE"
可以设置多个偏好,在ezjail.conf指定一个默认偏好设置。也可以在建立Jail虚拟机的时候使用-f参数指定。
现在开始基本系统的安装。网上很多教程都告诉你,安装Jail,要编译源代码,我很负责任地告诉你,你可以去骂他……不过被扁了可别怪我。
ezjail-admin install [-mMpPsS] [-h host] [-r release]
OK,安装 Jail 基本系统是不是很简单?
# ezjail-admin install -sp
抽颗烟,休息,休息一会儿。不抽烟?呃,那就喝茶。不喝茶?那就,那就,就想干嘛干嘛。ML就算鸟,时间不够滴,除非……。我邪恶了……
更新其实也不一定需要编译源代码的。
ezjail-admin update [-s sourcetree | sourceosversion] [-p] -b | -i | -P | -u | -U
现在应该开始渐入佳境,高潮就要来到了……