Bajar todos los archivos de un ftp con wget
Obviamente wget es mas que un comandito para bajar los flv de xvideos.com
Obviamente wget es mas que un comandito para bajar los flv de xvideos.com
Para instalar HTOP en FreeBSD (7,8, da igual)
abrimos /etc/rc.conf y agregamos linux_enable=”YES”
vamos a : cd /usr/ports/emulators/linux_base-fc4 e instalamos
make
make install install
agregamos estas linea en /etc/fstab
linproc /compat/linux/proc linprocfs rw 0 0
ejecutamos: mount linproc
finalmente instalamos el port de htop
cd /usr/ports/sysutils/htop
make
make install
Perfecto, ya quedo instalado htop en freebsd
Si han instalado un servidor con FreeBSD 8, y han querido instalar algun port que requiere de iso8879 seguramente se han encontrado con el siguiente error
Stop in /usr/ports/textproc/iso8879.*** Error code 1
Stop in /usr/ports/textproc/docbook-410.*** Error code 1
Stop in /usr/ports/textproc/docbook.*** Error code 1
Stop in /usr/ports/textproc/docbook.*** Error code 1
Stop in /usr/ports/textproc/docbook-xsl.*** Error code 1
Stop in /usr/ports/textproc/docbook-xsl.*** Error code 1
Stop in /usr/ports/graphics/liblqr-1.*** Error code 1
Stop in /usr/ports/graphics/liblqr-1.*** Error code 1
Stop in /usr/ports/graphics/ImageMagick.*** Error code 1
Basicamente el bug esta reportado, pero aun no hay fix.
Solucion? simplemente copie el port de un FreeBSD 7, lo tire en el FreeBSD 8 e instale. No hubo ningun problema, quedo todo operativo y problema resuelto.
Util articulo que explica como convertir un FreeBSD a un PC-BSD (bue, el articulo es solo para aprender a hacerlo, ya que el flaco usa FreeBSD 7 y le deja un PC-BSD viejo, que require FreeBSD 6.3…)
http://sas-spidey01.livejournal.com/169139.html
[Articulo]
This post describes an example of how one can manually convert a FreeBSD installation into a PC-BSD one using the install disk. There are more elegant ways of doing it, such as pulling things from PC-BSDs SVN and compiling only PC-BSD specific components.
This was done purely for ‘fun’ to see if the programs would work reasonably well. Which is why FreeBSD 7.0-Release was used as a base and PC-BSD 1.5.0 as the overlay (which is based on an old build of FreeBSD 6.3). I do not recommend, endorse, or even suggest actually doing something like this beyond exploratory or playful thoughts at heart !!!
If anyone actually tries this, your on your own.
If someone actually tries this they should probably use a PC-BSD 1.5.1 disk build, the files are newer.
Installing the PC-BSD v1.5.0-v1.5.1 update will install FreeBSD 6.3 files and may break your system — note that I didn’t enable the updater for my user account during this process.
My test partition is reserved fro testing various alpha/beta/rc releases of operating systems I wish to test. So I wiped it clean and set out to install a basic working FreeBSD system.
I Installed FreeBSD 7.0-Release via CD-ROM, using the express option, auto
partitioning to save time, X-Developer dist set, and configured the system
lightly (set root pw, network services etc).
Booted the system and logged in as root, one vtty for work and one for logging my notes in vim over ssh.
Then began converting the system to a FreeBSD-PC-BSD hybrid. Since the FreeBSD auto mode for partitioning the slice only gave me a 512mb / and 512mb /tmp, I created a /usr/work directory to use.
pkg_add -r lzma && rehash # to unpack pc-bsd filesmount -t cd9690 /dev/acd0 /mnt # mount pc-bsd disk 1mkdir -m 0700 /usr/worklzma d /mnt/PCBSD.tar.lzma /usr/work/PCBSD.tar ... # lzma has fast decompression speeds but # this is a ~451mb lzma file being # unpacked into a 1.9gb tar file! tar -C / -kpf /usr/work/PCBSD.tar # extract files without overwrite cp /etc/rc.conf /etc/rc.conf.local # fix rc.conftar -C /tmp -f /usr/work/PCBSD.tar -px './etc'cp /tmp/etc/rc.conf /etc/rc.confcp /tmp/etc/devfs.conf /etc/devfs.conf # modified in pc-bsd vi /etc/ttys # start x on boot up ... # note the ttyvNum is arbitrary #ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure ttyv8 "/PCBSD/bin/pdm" xterm on secure ...X -configure && mv /root/xorg.conf.new /etc/X11/xorg.conf ## create users and groups that come with PC-BSD 1.5.0 but not FreeBSD# 7.0-Release. Numerical values for -u userid and -g groupid are taken from# viewing a unified diff of the group files.#pw groupadd -n haldaemon -g 560pw groupadd -n cups -g 193pw groupadd -n cyrus -g 60pw useradd -n haldaemon -u 560 -g 560 -L daemon -d /nonexistent \ -s /usr/sbin/nologinpw useradd -n cups -u 193 -g 193 -L daemon -d /nonexistent -s /usr/sbin/nologinpw useradd -n cyrus -u 60 -g 60 -L daemon -d /nonexistent -s /usr/sbin/nologin ## add my own user with the bash shell as a test (because it. Note that I typically set# user/group id numbers by year of birth.#pw groupadd -n Terry -g 1988pw useradd -n Terry -u 1988 -L default -m -s bash -g Terry \ -G wheel,operatorpasswd Terry ... ## now build a custom kernel merging GENERIC with /PCBSD/conf/PCBSD.i386# I find Micro GNU Emacs (mg) to be both light and effective for this task.# -- normally I would use vimdiff#pkg_add -r mg && rehash # if using mg !cat > ~/.mgauto-fill-modeset-fill-column 78global-set-key "\^x\^f" find-fileglobal-set-key "\^h" delete-backward-charset-default-mode blink^D # end of ~/.mg diff -u /usr/src/sys/i386/conf/GENERIC /PCBSD/conf/PCBSD.i386 > /tmp/kern.diffcd /usr/src/sys/i386/confmg KAI ... # kernel config attached at EOF # used GENERIC and /tmp/kern.diff to # write the file if needed. cd /usr/src # compile & install kernelmake -j12 buildkernel KERNCONF=KAI ... # roughly 10 minutes later..make -j12 installkernel KERNCONF=KAI ... umount /mnt && cdcontrol -f /dev/acd0 ejectreboot # let's rock it and roll on to KDE
On reboot, I was greeted with KDM, PC-BSDs login theme, and a clean startup of KDE (no error message popups). I was able to install and use the Firefox PBI from PBIDir
without problems. But as one can see in the screen shots, there are sound system related core dumps
I was also interested to see that there is now a ‘snd_emu10kx’ driver added in FreeBSD 7.0-Release which supports my card. So I guess I won’t have to manually compile the ‘outdated, unmaintained, etc’ audio/emu10kx port to get working sound, the manual page seems to suggest it is the same driver more or less. I only had to add an entry to my loader.conf file to get it loaded before PC-BSD sound detection system, just like audio/emu10kx from ports it won’t work (for me) if kldload’ed later on.
I found that although everything I tested was working fine, audio and video related apps were dumping core (mplayer at start, kaffeine during playback). So I did a pkg_delete on kaffeine and kaffeine-mozilla and reinstalled from packages and soon was blasting MP3′s from a FAT32 partition
MPlayer needs to be recompiled as expected, The KDE sound system will likely need that to but otherwise I’ve observed no real breakages. Not that I’ve taken the time to test every single program!
If like me, your primary reason for using PC-BSD is a quick way of grabbing KDE — you would be better off installing PC-BSD! As far as setting up a working desktop system, one can do that easy through FreeBSD. If one doesn’t want to go into configuration details for ‘extra’s like PF or X11 using PC-BSD or DesktopBSD is a better idea anyway.
If all you want is PBI, export, compile, and install the necessary files from PC-BSDs SVN repository.
Note to SATA hard drives out there, the ATA_STATIC_ID option effects device numbering. FreeBSD GENERIC kernel configuration uses it and detects my SATA drive as ‘ad4′, PC_BSD kernel configuration has it turned off and detects my drive as ‘ad0′ — I only have one SATA II hard drive installed.
Changing the ATA_STATIC_ID kernel option means you will havve to make sure /etc/fstab is in working shape unless you want to see a mount root prompt.
## Custom FreeBSD 7.0 kernel based on PC-BSD 1.5 Kernel config for FreeBSD 6.3# cpu I686_CPUident KAI #options SCHED_$BSD # 4BSD scheduleroptions SCHED_ULE # ULE scheduleroptions PREEMPTION # ENABLE KERNEL THREAD PREEMPTIONoptions INET # INTERNETWORKINGoptions INET6 # IPV6 COMMUNICATIONS PROTOCOLSoptions SCTP # STREAM CONTROL TRANSMISSION PROTOCOLoptions FFS # BERKELEY FAST FILESYSTEMoptions SOFTUPDATES # ENABLE FFS SOFT UPDATES SUPPORToptions UFS_ACL # SUPPORT FOR ACCESS CONTROL LISTSoptions UFS_DIRHASH # IMPROVE PERFORMANCE ON BIG DIRECTORIESoptions UFS_GJOURNAL # ENABLE GJOURNAL-BASED UFS JOURNALINGoptions MD_ROOT # MD IS A POTENTIAL ROOT deviceoptions NFSCLIENT # NETWORK FILESYSTEM CLIENToptions NFSSERVER # NETWORK FILESYSTEM SERVERoptions NFS_ROOT # NFS USABLE AS /, REQUIRES NFSCLIENToptions MSDOSFS # MSDOS FILESYSTEMoptions CD9660 # ISO 9660 FILESYSTEMoptions PROCFS # PROCESS FILESYSTEM (REQUIRES PSEUDOFS)options PSEUDOFS # PSEUDO-FILESYSTEM FRAMEWORKoptions GEOM_PART_GPT # GUID PARTITION TABLES.options GEOM_LABEL # PROVIDES LABELIZATIONoptions COMPAT_43TTY # BSD 4.3 TTY COMPAT [KEEP THIS!]options COMPAT_FREEBSD4 # COMPATIBLE WITH FREEBSD4options COMPAT_FREEBSD5 # COMPATIBLE WITH FREEBSD5options COMPAT_FREEBSD6 # COMPATIBLE WITH FREEBSD6options SCSI_DELAY=5000 # DELAY (IN MS) BEFORE PROBING SCSIoptions KTRACE # KTRACE(1) SUPPORToptions SYSVSHM # SYSV-STYLE SHARED MEMORYoptions SYSVMSG # SYSV-STYLE MESSAGE QUEUESoptions SYSVSEM # SYSV-STYLE SEMAPHORESoptions _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B REAL-TIME EXTENSIONSoptions KBD_INSTALL_CDEV # INSTALL A CDEV ENTRY IN /DEVoptions ADAPTIVE_GIANT # GIANT MUTEX IS ADAPTIVE.options STOP_NMI # STOP CPUS USING NMI INSTEAD OF IPIoptions AUDIT # SECURITY EVENT AUDITING # TO MAKE AN SMP KERNEL, THE NEXT TWO LINES ARE NEEDEDoptions SMP # SYMMETRIC MULTIPROCESSOR KERNELdevice apic # I/O APIC # CPU FREQUENCY CONTROLdevice cpufreq # BUS SUPPORT.device eisadevice pci # FLOPPY DRIVESdevice fdc # ATA AND ATAPI deviceSdevice atadevice atadisk # ATA DISK DRIVESdevice ataraid # ATA RAID DRIVESdevice atapicd # ATAPI CDROM DRIVESdevice atapifd # ATAPI FLOPPY DRIVESdevice atapist # ATAPI TAPE DRIVESoptions ATA_STATIC_ID # STATIC device NUMBERINGdevice atapicam # Atapi CAM support # SCSI CONTROLLERSdevice ahb # EISA AHA1742 FAMILYdevice ahc # AHA2940 AND ONBOARD AIC7XXX deviceSoptions AHC_REG_PRETTY_PRINT # PRINT REGISTER BITFIELDS IN DEBUG # OUTPUT. ADDS ~128K TO DRIVER.device ahd # AHA39320/29320 AND ONBOARD AIC79XX deviceSoptions AHD_REG_PRETTY_PRINT # PRINT REGISTER BITFIELDS IN DEBUG # OUTPUT. ADDS ~215K TO DRIVER.device amd # AMD 53C974 (TEKRAM DC-390(T))device isp # QLOGIC FAMILY#device ispfw # FIRMWARE FOR QLOGIC HBAS- NORMALLY A MODULEdevice mpt # LSI-LOGIC MPT-FUSION#device ncr # NCR/SYMBIOS LOGICdevice sym # NCR/SYMBIOS LOGIC (NEWER CHIPSETS + THOSE OF `NCR')device trm # TEKRAM DC395U/UW/F DC315U ADAPTERS device adv # ADVANSYS SCSI ADAPTERSdevice adw # ADVANSYS WIDE SCSI ADAPTERSdevice aha # ADAPTEC 154X SCSI ADAPTERSdevice aic # ADAPTEC 15[012]X SCSI ADAPTERS, AIC-6[23]60.device bt # BUSLOGIC/MYLEX MULTIMASTER SCSI ADAPTERS device ncv # NCR 53C500device nsp # WORKBIT NINJA SCSI-3device stg # TMC 18C30/18C50 # SCSI PERIPHERALSdevice scbus # SCSI BUS (REQUIRED FOR SCSI)device ch # SCSI MEDIA CHANGERSdevice da # DIRECT ACCESS (DISKS)device sa # SEQUENTIAL ACCESS (TAPE ETC)device cd # CDdevice pass # PASSTHROUGH device (DIRECT SCSI ACCESS)device ses # SCSI ENVIRONMENTAL SERVICES (AND SAF-TE) # RAID CONTROLLERS INTERFACED TO THE SCSI SUBSYSTEMdevice amr # AMI MEGARAIDdevice arcmsr # ARECA SATA II RAIDdevice asr # DPT SMARTRAID V, VI AND ADAPTEC SCSI RAIDdevice ciss # COMPAQ SMART RAID 5*device dpt # DPT SMARTCACHE III, IV - SEE NOTES FOR optionsdevice hptmv # HIGHPOINT ROCKETRAID 182Xdevice hptrr # HIGHPOINT ROCKETRAID 17XX, 22XX, 23XX, 25XXdevice iir # INTEL INTEGRATED RAIDdevice ips # IBM (ADAPTEC) SERVERAIDdevice mly # MYLEX ACCELERAID/EXTREMERAIDdevice twa # 3WARE 9000 SERIES PATA/SATA RAID # RAID CONTROLLERSdevice aac # ADAPTEC FSA RAIDdevice aacp # SCSI PASSTHROUGH FOR AAC (REQUIRES CAM)device ida # COMPAQ SMART RAIDdevice mfi # LSI MEGARAID SASdevice mlx # MYLEX DAC960 FAMILYdevice pst # PROMISE SUPERTRAK SX6000device twe # 3WARE ATA RAID # ATKBDC0 CONTROLS BOTH THE KEYBOARD AND THE PS/2 MOUSEdevice atkbdc # AT KEYBOARD CONTROLLERdevice atkbd # AT KEYBOARDdevice psm # PS/2 MOUSE device vga # VGA VIDEO CARD DRIVER device splash # SPLASH SCREEN AND SCREEN SAVER SUPPORT # SYSCONS IS THE DEFAULT CONSOLE DRIVER, RESEMBLING AN SCO CONSOLEdevice sc device agp # SUPPORT SEVERAL AGP CHIPSETS # POWER MANAGEMENT SUPPORT (SEE NOTES FOR MORE options)#device apm# ADD SUSPEND/RESUME SUPPORT FOR THE I8254.device pmtimer # PCCARD (PCMCIA) SUPPORT# PCMCIA AND CARDBUS BRIDGE SUPPORTdevice cbb # CARDBUS (YENTA) BRIDGEdevice pccard # PC CARD (16-BIT) BUSdevice cardbus # CARDBUS (32-BIT) BUS # SERIAL (COM) PORTSdevice sio # 8250, 16[45]50 BASED SERIAL PORTSdevice uart # GENERIC UART DRIVER # PARALLEL PORTdevice ppcdevice ppbus # PARALLEL PORT BUS (REQUIRED)device lpt # PRINTERdevice plip # TCP/IP OVER PARALLELdevice ppi # PARALLEL PORT INTERFACE device#device vpo # REQUIRES SCBUS AND DA # IF YOU'VE GOT A "DUMB" SERIAL OR PARALLEL PCI CARD THAT IS# SUPPORTED BY THE PUC(4) GLUE DRIVER, UNCOMMENT THE FOLLOWING# LINE TO ENABLE IT (CONNECTS TO SIO, UART AND/OR PPC DRIVERS):#device puc # PCI ETHERNET NICS.device de # DEC/INTEL DC21X4X (``TULIP'')device em # INTEL PRO/1000 ADAPTER GIGABIT ETHERNET CARDdevice ixgb # INTEL PRO/10GBE ETHERNET CARDdevice le # AMD AM7900 LANCE AND AM79C9XX PCNETdevice txp # 3COM 3CR990 (``TYPHOON'')device vx # 3COM 3C590, 3C595 (``VORTEX'') # PCI ETHERNET NICS THAT USE THE COMMON MII BUS CONTROLLER CODE.# NOTE: BE SURE TO KEEP THE 'device MIIBUS' LINE IN ORDER TO USE THESE NICS!device miibus # MII BUS SUPPORTdevice bce # BROADCOM BCM5706/BCM5708 GIGABIT ETHERNETdevice bfe # BROADCOM BCM440X 10/100 ETHERNETdevice bge # BROADCOM BCM570XX GIGABIT ETHERNETdevice dc # DEC/INTEL 21143 AND VARIOUS WORKALIKESdevice fxp # INTEL ETHEREXPRESS PRO/100B (82557, 82558)device lge # LEVEL 1 LXT1001 GIGABIT ETHERNETdevice msk # MARVELL/SYSKONNECT YUKON II GIGABIT ETHERNETdevice nfe # NVIDIA NFORCE MCP ON-BOARD ETHERNETdevice nge # NATSEMI DP83820 GIGABIT ETHERNET#device nve # NVIDIA NFORCE MCP ON-BOARD ETHERNET NETWORKINGdevice pcn # AMD AM79C97X PCI 10/100 (PRECEDENCE OVER 'LE')device re # REALTEK 8139C+/8169/8169S/8110Sdevice rl # REALTEK 8129/8139device sf # ADAPTEC AIC-6915 (``STARFIRE'')device sis # SILICON INTEGRATED SYSTEMS SIS 900/SIS 7016device sk # SYSKONNECT SK-984X & SK-982X GIGABIT ETHERNETdevice ste # SUNDANCE ST201 (D-LINK DFE-550TX)device stge # SUNDANCE/TAMARACK TC9021 GIGABIT ETHERNETdevice ti # ALTEON NETWORKS TIGON I/II GIGABIT ETHERNETdevice tl # TEXAS INSTRUMENTS THUNDERLANdevice tx # SMC ETHERPOWER II (83C170 ``EPIC'')device vge # VIA VT612X GIGABIT ETHERNETdevice vr # VIA RHINE, RHINE IIdevice wb # WINBOND W89C840Fdevice xl # 3COM 3C90X (``BOOMERANG'', ``CYCLONE'') # ISA ETHERNET NICS. PCCARD NICS INCLUDED.device cs # CRYSTAL SEMICONDUCTOR CS89X0 NIC# 'device ED' REQUIRES 'device MIIBUS'device ed # NE[12]000, SMC ULTRA, 3C503, DS8390 CARDSdevice ex # INTEL ETHEREXPRESS PRO/10 AND PRO/10+device ep # ETHERLINK III BASED CARDSdevice fe # FUJITSU MB8696X BASED CARDSdevice ie # ETHEREXPRESS 8/16, 3C507, STARLAN 10 ETC.device sn # SMC'S 9000 SERIES OF ETHERNET CHIPSdevice xe # XIRCOM PCCARD ETHERNET # WIRELESS NIC CARDSdevice wlan # 802.11 SUPPORTdevice wlan_wep # 802.11 WEP SUPPORTdevice wlan_ccmp # 802.11 CCMP SUPPORTdevice wlan_tkip # 802.11 TKIP SUPPORTdevice wlan_amrr # AMRR TRANSMIT RATE CONTROL ALGORITHMdevice wlan_scan_ap # 802.11 AP MODE SCANNINGdevice wlan_scan_sta # 802.11 STA MODE SCANNINGdevice an # AIRONET 4500/4800 802.11 WIRELESS NICS.device ath # ATHEROS PCI/CARDBUS NIC'Sdevice ath_hal # ATHEROS HAL (HARDWARE ACCESS LAYER)device ath_rate_sample # SAMPLERATE TX RATE CONTROL FOR ATHdevice awi # BAYSTACK 660 AND OTHERSdevice ral # RALINK TECHNOLOGY RT2500 WIRELESS NICS.device wi # WAVELAN/INTERSIL/SYMBOL 802.11 WIRELESS NICS.#device wl # OLDER NON 802.11 WAVELAN WIRELESS NIC. # PSEUDO deviceS.device loop # NETWORK LOOPBACKdevice random # ENTROPY devicedevice ether # ETHERNET SUPPORTdevice sl # KERNEL SLIPdevice ppp # KERNEL PPPdevice tun # PACKET TUNNEL.device pty # PSEUDO-TTYS (TELNET ETC)device md # MEMORY "DISKS"device gif # IPV6 AND IPV4 TUNNELINGdevice faith # IPV6-TO-IPV4 RELAYING (TRANSLATION)device firmware # FIRMWARE ASSIST MODULE # THE `BPF' device ENABLES THE BERKELEY PACKET FILTER.# BE AWARE OF THE ADMINISTRATIVE CONSEQUENCES OF ENABLING THIS!# NOTE THAT 'BPF' IS REQUIRED FOR DHCP.device bpf # BERKELEY PACKET FILTER # USB SUPPORTdevice uhci # UHCI PCI->USB INTERFACEdevice ohci # OHCI PCI->USB INTERFACEdevice ehci # EHCI PCI->USB INTERFACE (USB 2.0)device usb # USB BUS (REQUIRED)#device udbp # USB DOUBLE BULK PIPE deviceSdevice ugen # GENERICdevice uhid # "HUMAN INTERFACE deviceS"device ukbd # KEYBOARDdevice ulpt # PRINTERdevice umass # DISKS/MASS STORAGE - REQUIRES SCBUS AND DAdevice ums # MOUSEdevice ural # RALINK TECHNOLOGY RT2500USB WIRELESS NICSdevice rum # RALINK TECHNOLOGY RT2501USB WIRELESS NICSdevice urio # DIAMOND RIO 500 MP3 PLAYERdevice uscanner # SCANNERS# USB ETHERNET, REQUIRES MIIBUSdevice aue # ADMTEK USB ETHERNETdevice axe # ASIX ELECTRONICS USB ETHERNETdevice cdce # GENERIC USB OVER ETHERNETdevice cue # CATC USB ETHERNETdevice kue # KAWASAKI LSI USB ETHERNETdevice rue # REALTEK RTL8150 USB ETHERNET # FIREWIRE SUPPORTdevice firewire # FIREWIRE BUS CODEdevice sbp # SCSI OVER FIREWIRE (REQUIRES SCBUS AND DA)device fwe # ETHERNET OVER FIREWIRE (NON-STANDARD!)device fwip # IP OVER FIREWIRE (RFC 2734,3146)device dcons # DUMB CONSOLE DRIVERdevice dcons_crom # CONFIGURATION ROM FOR DCONS ## from PC-BSD conf#options LIBICONVoptions LIBMCHAINoptions CD9660_ICONVoptions MSDOSFS_ICONVoptions NTFSoptions NTFS_ICONVoptions UDFoptions UDF_ICONVoptions GEOM_UZIP # read only compressed disks# wifidevice wlandevice wlan_wepdevice wlan_ccmpdevice wlan_tkipdevice andevice athdevice ath_haldevice ath_rate_sampledevice awidevice raldevice widevice iwidevice ipwdevice firmwareoptions DEVICE_POLLINGdevice pfdevice pflogdevice pfsyncoptions ALTQoptions ALTQ_CBQoptions ALTQ_REDoptions ALTQ_RIOoptions ALTQ_HFSCoptions ALTQ_CDNRoptions ALTQ_PRIQoptions ALTQ_NOPCC
Este articulo explica de forma simple, como se crea un modulo para el Kernel de FreeBSD.
La verdad, es que me parece que es muy simple de entender.
http://www.freesoftwaremagazine.com/articles/writing_a_kernel_module_for_freebsd
[Articulo]
FreeBSD 7.0 has already been released. If you are a real hacker, the best way to jump in and learn it is hacking together an introductory kernel module. In this article I’ll implement a very basic module that prints a message when it is loaded, and another when it is unloaded. I’ll also cover the mechanics of compiling our module using standard tools and rebuilding the stock FreeBSD kernel. Let’s do it!
There are some prerequisites for this article. I assume you have a little bit of C programming knowledge, though nothing too fancy. If I reference a pointer or a structure, I expect you to understand those concepts without much explanation. I also expect you to be familiar with UNIX-like operating systems and know your way around basic shell usage.
The first thing to do is make sure the development environment you’ll be working in includes everything and is configured properly. I’m going to assume you already have FreeBSD installed and running. If you don’t, and would like some guidance, you can read my article: Secure emails servers with FreeBSD. I’ll be doing a few things differently; so, I would recommend just using it as a resource for the installation, which is identical in both scenarios.
You will also need to make sure the sudo utility is installed and configured for your main user account. This is required to run as “root” the utilities kldload and kldunload. The FreeBSD port for sudo is in /usr/ports/security/sudo.
cd /usr/port/security/sudomake install && make clean
Now su to root and run the visudo utility. Visudo uses the EDITOR environment variable to determine which text editor to use. If you don’t like the default one, override it with setenv EDITOR vim if you are using the default CSH, or export EDITOR=vim if you are using bash. Then simply re-run visudo.
suvisudo
The visudo utility does basic sanity checking on the syntax and makes sure no two people edit the sudoers file at the same time.
# Look for this line, copy it and change the "root" user to your main users name.root ALL=(ALL) SETENV: ALLyourabi ALL=(ALL) SETENV: ALL
As I mentioned in my recent article Review of FreeBSD 7.0, the ULE scheduler brings a new level of performance and multi-processor scalability to FreeBSD. Though it is now considered stable and ready for prime-time, it will not be enabled by default until the 7.1 release. A good litmus test of your setup will be compiling a custom kernel with the ULE scheduler enabled.
If you are on an x86 based machine, the kernel is located in the /usr/src/sys/i386 directory. For amd64 machines, simply replace i386 with amd64, which becomes /usr/src/sys/amd64. The kernel configuration file is located in a directory called conf. Enter that directory and create your own custom kernel configuration file by copying the “generic” default configuration to one of our own naming.
cd /usr/src/sys/amd64/confcp GENERIC CUSTOM
Now it’s time to enable the new ULE scheduler. The new ULE scheduler brings improved performance and scalability compared to the legacy scheduler and also serves as a good demonstration of building and installing a custom kernel.
Open the “CUSTOM” file with your text editor of choice and find the line enabling the legacy 44BSD scheduler and replace it with ULE. In the stock kernel configuration file this should be around line 30 (at the time of this writing).
options SCHED_4BSD # 4BSD scheduler# BECOMES #options SCHED_ULE # ULE scheduler
Now build your new kernel and reboot so it takes effect. FreeBSD has an elegant, simple build system using the standard “make” utility. Simply change directories to the source tree and invoke the make file with the “buildkernel” and “installkernel” targets. If you call them without any parameters, the GENERIC (default) kernel will be built and installed. Since you want your custom kernel, pass in the KERNCONF flag with the name of the target kernel. In this case, it will be the name that you just copied the generic kernel to: CUSTOM.
cd /usr/srcmake buildkernel KERNCONF="CUSTOM"make installkernel KERNCONF="CUSTOM" reboot
Congratulations! As the system boots up, it will run the new custom kernel with the ULE scheduler enabled. You have now verified that you are able to compile and install a kernel, so it’s time to take on your next task: writing a simple kernel module.
When running FreeBSD in VMWare make sure to lower the kernels timer frequency
Note: If you are running FreeBSD in VMWare there is one very important performance tweak to make to your system to follow this article. The kernel’s timer frequency needs to be lowered from ‘1000’ to ‘100’ ticks per second. Edit /boot/loader.conf with your favorite editor and add the following line.
echo kern.hz=100 >> /boot/loader.conf
As you may have noticed, FreeBSD makes efficient use of the make utility for building and installing kernels (and the rest of the operating system). What you may not know yet, but will come as no surprise, is that the FreeBSD developers have also developed make files to ease part of the difficulty of kernel module development.
An in depth look at make files and the make utility are beyond the scope of this article. However, two points of immediate relevance are the bsd.kmod.mk make file and the ability to include other make files within each other.
The bsd.kmod.mk makefile resides in /usr/src/share/mk/bsd.kmod.mk and takes all of the pain out of building and linking kernel modules properly. As you are about to see, you simply have to set two variables:
Then, all you have to do is include to build the module. This elegant setup lets you build your kernel module with only the following skeletal make file and a simple invocation of the “make” utility.
The Makefile for our introductory kernel module looks like this:
# Note: It is important to make sure you include the makefile after declaring the KMOD and SRCS variables. # Declare Name of kernel moduleKMOD = hello_fsm # Enumerate Source files for kernel moduleSRCS = hello_fsm.c # Include kernel module makefile.include
Create a new directory called kernel, under your home directory. Copy and paste the text above into a file called Makefile. This will be your working base going forward.
Now that you have a clue about the build environment, it’s time to take a look at the actual code behind a FreeBSD kernel module and the mechanisms for inserting and removing a module from a running kernel.
A kernel module allows dynamic functionality to be added to a running kernel. When a kernel module is inserted, the “load” event is fired. When a kernel module is removed, the “unload” event is fired. The kernel module is responsible for implementing an event handler that handles these cases.
The running kernel will pass in the event in the form of a symbolic constant defined in the /usr/include/sys/module.h () header file. The two main events you are concerned with are MOD_LOAD and MOD_UNLOAD.
How does the running kernel know which function to call and pass an event type as a parameter to? The module is responsible for configuring that call-back as well by using the DECLARE_MODULE macro.
The DECLARE_MODULE macro is defined in the header on line 117. It takes four parameters in the following order:
name. Defines the name.data. Specifies the name of the moduledata_t structure, which I’ve named hello_conf in my implementation. The moduledata_t type is defined at line 55 of . I’ll talk about this briefly.sub. Sets the subsystem interface, which defines the module type.order. Defines the modules initialization order within the defined subsystemThe moduledata structure contains the name defined as a char variable and the event handler routine defined as a modeventhand_t structure which is defined at line 50 of . Finally, the moduledata structure has void pointer for any extra data, which you won’t be using.
If your head is about to explode from the overview without any code to put in context, fear not. That is the sum of what you need to know to start writing your kernel module, and so with that, “once more into the breach dear friends”. Before you get started, make sure you are in the same kernel directory where you previously created the Makefile file. Fire up your text editor of choice and open a file called hello_fsm.c.
First include the header files required for the data types used. You’ve already seen and the other includes are supporting header files.
#include #include #include #include
Next, you are going to implement the event_handler function. This is what the kernel will call and pass either MOD_LOAD or MOD_UNLOAD to via the event parameter. If everything runs normally, it will return a value of 0 upon normal completion. However, you should handle the possibility that something will go wrong and if the event parameter is neither MOD_LOAD or MOD_UNLOAD, you will set e, your error tracking variable, to EOPNOTSUPP.
/* The function called at load/unload. */static int event_handler(struct module *module, int event, void *arg) { int e = 0; /* Error, 0 for normal return status */ switch (event) { case MOD_LOAD: uprintf("Hello Free Software Magazine Readers! \n"); break; case MOD_UNLOAD: uprintf("Bye Bye FSM reader, be sure to check http://freesoftwaremagazine.com !\n"); break; default: e = EOPNOTSUPP; /* Error, Operation Not Supported */ break; }
return(e);}
Next, you’re going to define the second parameter to the DECLARE_MODULE macro, which is of type moduledata_t. This is where you set the name of the module and expose the event_handler routine to be called when loaded and unloaded from the kernel.
/* The second argument of DECLARE_MODULE. */static moduledata_t hello_conf = { "hello_fsm", /* module name */ event_handler, /* event handler */ NULL /* extra data */};
And finally, you’re going to make a call to the much talked about DECLARE_MODULE with the name of the module and the hello_conf structure.
DECLARE_MODULE(hello_fsm, hello_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
All that is left to do is build the module. Double check that you are in the same directory as the module’s makefile you saw earlier and run:
make
To load the module, you have two options: the kldload utility or the load make target via the makefile. You must use both options via the “sudo” utility as loading and unloading modules requires root privileges.
sudo kldload ./hello_fsm.ko# or #sudo make load
You should see the message “Hello Free Software Magazine Readers!” on your console. To view all loaded modules, use the kldstat utility with no arguments. kldstat does not require root privileges and you can verify that the module is indeed loaded.
kldstatId Refs Address Size Name1 8 0xc0400000 926ed4 kernel2 1 0xc0d27000 6a1c4 acpi.ko3 1 0xc317e000 22000 linux.ko4 1 0xc4146000 2000 hello_fsm.ko
To unload the module, use kldunload or the unload target in the make file. You should see the message printed on the MOD_UNLOAD case, which is “Bye Bye FSM reader, be sure to check http://freesoftwaremagazine.com!”
sudo kldunload hello_fsm or sudo make unload
There you have it, a basic, skeletal kernel module. It prints a message when loaded and a separate message when being unloaded from the kernel. This article covered the mechanics of building, inserting, and removing the module. You know have the basic building blocks to take on more advanced projects: I would recommend looking at writing a character device writer as it is probably the next simplest device driver.
I hope this has been as much fun for you as it has been for me!
Recent Comments