FreeBSD3.pdf

FREEBSD
Operating Systems FreeBSD Project
Dept. of Computer
Sharif University of Technology
SOME USEFUL COMMANDS

ifconfig


ls


List content of current direcory
cd


For finding or change IP address and …
Change current directory
ssh

For execute command in remote machine
INSTALL FREEBSD SOFTWARE
pkg_add
 Pkg_add –v –r {package name}

-v: verbose output
 -r: replace if package is exist

COMPILE
GNU Compiler Collection
 Editors like vim or ee… (ee filename.c)
 Sourcecode: filename.c
 Compile:

COMPILE

1.
Compile:
gcc filename.c –o out.o
COMPILE

2.
Compile:
make

Read from makefile
COMPILE

2.
Compile:
make

Read from makefile
CUSTOMIZE KERNEL

Access kernel source from:

/usr/src/sys
cd usr/src/sys/i386/conf
 cp GENERIC MYKERNEL


Backup!
Edit MYKERNEL
 cd /usr/src
 Compile the new kernel

make buildkernel KERNCONF=MYKERNEL
 Use NOCLEAN=YES to compile changed files only

CUSTOMIZE KERNEL

Install new Kernel


make installkernel KERNCONF=MYKERNEL
Reboot into new kernel…
KERNEL LOADABLE MODULE
Is an object file that contains code to extend the
running kernel
 #man kld
 kldstat: status of dynamic kernel linker
 kldload: load a filename.ko into kernel
 kldunload: unload a filename.ko from kernel

HELLO WORLD KLD
hello.c
#include <sys/param.h>, <sys/kernel.h>, <sys/systm.h>
/* The function called at load/unload. */
static int load(struct module *module, int cmd, void
*arg) {
int error = 0;
switch (cmd) {
case MOD_LOAD:
uprintf("Hello, world!\n");
break;
case MOD_UNLOAD:
uprintf("Good-bye, cruel world!\n");
break;
default:
error = EOPNOTSUPP;
break;}
return(error);}

HELLO WORLD KLD
hello.c (continue):
/* The second argument of DECLARE_MODULE. */
static moduledata_t hello_mod = {
"hello", /* module name */
load, /* event handler */
NULL /* extra data */
};
DECLARE_MODULE(hello, hello_mod,
SI_SUB_DRIVERS, SI_ORDER_MIDDLE);

HELLO WORLD KLD

Makefile:
KMOD= hello
# Name of KLD to build.
SRCS= hello.c
# List of source files.
.include <bsd.kmod.mk>
make
 Ls –F
@@
Makefile

export_syms
hello.c
hello.kld
hello.ko*
hello.o
machine@
HELLO WORLD KLD
$ sudo kldload ./hello.ko
Hello, world!
$ sudo kldunload hello.ko
Good-bye, cruel world!