|
 
|
1#
发表于 2005-9-19 10:09
| 只看该作者
Painless FreeBSD System Updating
Introduction
One of the greatest advantages that *BSD has over other Unix variants is the cvsup/make world process. Unlike most Linux distributions it isn't necessary to wait months for a new version to be released for you to upgrade your system. The cvsup/make world process allows you to update your system at any time. I'm going to show you how to make the process as painless as possible.
Installing CVSup
The first thing we need to do is install the cvsup port; to do so run the following as root:
# cd /usr/ports/net/cvsup-without-gui
# make install cleanWhile we're at it we're also going to install the fastest_cvsup port. This step is optional but it could ultimately make the process more efficient.
# cd /usr/ports/sysutils/fastest_cvsup
# make install cleanChoosing a cvsup server
Next we want to find the fastest cvsup server to retrieve source files from. I'm in the U.S. so I'm going to limit the search to cvsup servers in my country. Here is the output:
# fastest_cvsup -c us
>> Querying servers in countries: us
--> Connecting to cvsup1.freebsd.org [198.104.69.57]...
- server replied: OK 17 0 SNAP_16_1e CVSup server ready
- time taken: 65.72 ms
--> Connecting to cvsup2.freebsd.org [130.94.149.166]...
- server replied: OK 17 0 SNAP_16_1h CVSup server ready
- time taken: 97.60 ms
--> Connecting to cvsup3.freebsd.org [18.24.10.20]...
- server replied: OK 17 0 SNAP_16_1e CVSup server ready
- time taken: 103.64 ms
--> Connecting to cvsup4.freebsd.org [204.152.184.73]...
- server replied: OK 17 0 SNAP_16_1f CVSup server ready
- time taken: 28.44 ms
--> Connecting to cvsup5.freebsd.org [198.182.76.34]...
- server replied: OK 17 0 SNAP_16_1f CVSup server ready
- time taken: 44.37 ms
--> Connecting to cvsup6.freebsd.org [66.109.10.22]...
- server replied: OK 17 0 SNAP_16_1f CVSup server ready
- time taken: 71.33 ms
--> Connecting to cvsup7.freebsd.org [129.250.31.140]...
- server replied: OK 17 0 SNAP_16_1g CVSup server ready
- time taken: 3108.32 ms
--> Connecting to cvsup8.freebsd.org [129.250.31.140]...
- server replied: OK 17 0 SNAP_16_1g CVSup server ready
- time taken: 76.29 ms
--> Connecting to cvsup9.freebsd.org [209.181.243.21]...
- server replied: OK 17 0 SNAP_16_1e CVSup server ready
- time taken: 84.56 ms
--> Connecting to cvsup10.freebsd.org [216.136.204.25]...
- server replied: OK 17 0 SNAP_16_1e CVSup server ready
- time taken: 103.65 ms
--> Connecting to cvsup11.freebsd.org [63.87.62.77]...
- server replied: OK 17 0 SNAP_16_1h CVSup server ready
- time taken: 88.22 ms
--> Connecting to cvsup12.freebsd.org [128.46.156.46]...
- server replied: OK 17 0 SNAP_16_1g CVSup server ready
- time taken: 87.71 ms
--> Connecting to cvsup13.freebsd.org [63.251.223.166]...
- server replied: OK 17 0 SNAP_16_1f CVSup server ready
- time taken: 39.23 ms
--> Connecting to cvsup14.freebsd.org [208.185.175.214]...
* error: Timeout
--> Connecting to cvsup15.freebsd.org [131.193.178.106]...
* error: Timeout
--> Connecting to cvsup16.freebsd.org [128.143.108.35]...
- server replied: OK 17 0 SNAP_16_1f CVSup server ready
- time taken: 3082.32 ms
--> Connecting to cvsup17.freebsd.org [216.136.204.25]...
- server replied: OK 17 0 SNAP_16_1e CVSup server ready
- time taken: 119.61 ms
>> Speed Daemons:
- 1st: cvsup4.freebsd.org
- 2nd: cvsup13.freebsd.org
- 3rd: cvsup5.freebsd.orgThe fastest cvsup server for me is clearly cvsup4.freebsd.org. Make a note of the fastest server to your location because we'll be using that in just a bit.
I'm going to assume that you already have a customized kernel configuration file. If you don't then consult the FreeBSD Handbook for the steps. My main workstation is a dual 1.8GHz Xeon (I686_CPU) box with 1GB RAM, all SCSI storage, an Intel (fxp) NIC, an SBLive! (pcm) soundcard and an Epson USB scanner. You can find my kernel configuration file here.
Configuring make.conf
Next we'll want to edit make.conf to store some values that the updating process will use. You will find make.conf in /etc/defaults/, however you never want to edit files in this directory. Copy the file to /etc/make.conf and edit that copy instead. Doing this will ensure that in the off chance that you blow something up you can return your system to normal simply by typing rm /etc/make.conf. That will allow your system to once again use use the default values in /etc/defaults/make.conf. Our step here is:
# cp /etc/defaults/make.conf /etc/
# vim /etc/make.confThis file has many parameters that you may want to make use of, however we're only going to cover the ones directly related to the task we're covering now. Here is the section of the file that we're concerned with now:
# CVSup update flags. Edit SUPFILE settings to reflect whichever distribution
# file(s) you use on your site (see /usr/share/examples/cvsup/README for more
# information on CVSup and these files). To use, do "make update" in /usr/src.
#
#SUP_UPDATE= yes
#
#SUP= /usr/local/bin/cvsup
#SUPFLAGS= -g -L 2
#SUPHOST= cvsup.uk.FreeBSD.org
#SUPFILE= /usr/share/examples/cvsup/stable-supfile
#PORTSSUPFILE= /usr/share/examples/cvsup/ports-supfile
#DOCSUPFILE= /usr/share/examples/cvsup/doc-supfileThis section holds the parameters that the cvsup process will use whenever we update the system. Uncomment each of these lines so they'll be acted upon by the system. Change the SUPHOST= entry to reflect the cvsup server that the previous fastest_cvsup command reported to be the fastest. I follow the FreeBSD-stable track so the stable-supfile is the one I want to use. You may choose to follow the security track, in which case you'll need to change the default release tag in the supfile. The DOCSUPFILE= entry is for maintaining a local copy of the FreeBSD documentation and completely optional. After editing, here is how the section looks for my system:
SUP_UPDATE= yes
#
SUP= /usr/local/bin/cvsup
SUPFLAGS= -g -L 2
SUPHOST= cvsup4.FreeBSD.org
SUPFILE= /usr/share/examples/cvsup/stable-supfile
PORTSSUPFILE= /usr/share/examples/cvsup/ports-supfile
#DOCSUPFILE= /usr/share/examples/cvsup/doc-supfile
KERNCONF=KERNELNAMEThe last entry is to make rebuilding the kernel easier. You should replace KERNELNAME with whatever name you have given your kernel configuration file, which should be located in /usr/src/sys/i386/conf/.
Performing the Upgrade
At this point everything is in place for near automatic updating of your FreeBSD system. To begin the actual upgrade process simply change to the /usr/src directory and type make update. The cvsup process will connect to your chosen cvsup server and retrieve the most recent source code. If all goes as planned you should see the following output:
daemon# cd /usr/src
daemon# make update
--------------------------------------------------------------
>>> Running /usr/local/bin/cvsup
--------------------------------------------------------------
Parsing supfile "/usr/share/examples/cvsup/stable-supfile"
Connecting to cvsup4.FreeBSD.org
Connected to cvsup4.FreeBSD.org
Server software version: SNAP_16_1f
Negotiating file attribute support
Exchanging collection information
Establishing multiplexed-mode data connection
Running
Updating collection src-all/cvs
.....abbreviated output........The length of time this takes will vary depending on your Internet connection speed and how often the process is run. Once this has completed you can begin the task of rebuilding the system. The various targets for the 'make' process can be found in the Makefile in the /usr/src directory. Many people choose to run make buildworld followed by make installworld. The buildworld target rebuilds the entire base operating systems (not including installed ports) while the installworld target actually installs everything built by buildworld. I prefer the make world target, which combines the two steps into one. This step takes about 25 minutes on my Xeon system and a couple of hours on my Celeron 400MHz mail/dns/nfs server. Take a peek at the screen every now and then to make sure the process hasn't resulted in any errors.
After you're sure the make process has completed successfully you're ready to build a new kernel. To do this simply type make kernel in the same /usr/src directory. The system will build a new kernel using the configuration file you named in the KERNCONF=KERNELNAME entry in /etc/make.conf.
After a new kernel is built we're ready for the final step (whew!), which is running mergemaster. With the mergemaster command the system to prompt you with a choice to overwrite certain system configuration which may (or may not) need to be updated. Pay extremely close attention to this step! You WILL be asked if you want overwrite important files like /etc/passwd and for most sane people the answer will be a resounding NO. I usually let the process overwrite files which I'm positive I've never edited myself and the rest I like to check out first. Once you make it through mergemaster you're ready to reboot into a fresh, piping hot batch of FreeBSD goodness. Now, doing all that doesn't seem so automated, does it? Well, here's the good part. I simply make an alias for my shell (tcsh) as follows:
alias rebuild 'cd /usr/src && make update && make world && make kernel && mergemaster'Now in the future all I need to do is su to the root user and type rebuild in an xterm or virtual terminal. In 30-35 minutes I return to the window, carefully answer the mergemaster prompts then I'm all set to reboot into the latest and greatest build of FreeBSD! The entire process is so simple that I don't even bother applying individual patches anymore. I figure typing rebuild is a lot faster than reading the patch documentation and executing the steps.
Conclusion
The cvsup process is, in my mind, the greatest advantage BSD systems have over Linux or other *nix for that matter. Combined with the ports system and it's over 9,000 software programs, you practically can eat your cake and have it too!
Additional Resources
make.conf(5) man page
mergemaster(8) man page
/usr/src/README
/usr/src/Makefile
- Steve
Steve Wingate is a reformed MCSE & CCNA who is currently underemployed at Epson America in Long Beach, CA. In his spare time he lifts weights, bicycles, chats on IRC and counts glazed donuts in his sleep. |
|