# Building a customized FreeBSD ISO



## linuxunix (Nov 7, 2011)

I am following this link: http://www.cyclecide.com/~rudy/example/custom-freebsd.html to build a customized FreeBSD ISO.All I am in verse to include a mfi module to work.Though FreeBSD 8.2 includes mfi driver in GENERIC kernel but I need to include a new driver version from LSI website.

I performed these steps:


```
First, downlaod the ISO you want to start with (ftp.freebsd.org) 
Mount the ISO so you can 'see' inside it. 
    mdconfig -a -t vnode -f 8.2-x64-dvd.iso  -u 0
    mount_cd9660 /dev/md0 /mnt
    
Prepare a spot to modify the ISO contents. (We are going to copy everything and then make a new ISO.) 
    mkdir 8.2-x64-dvd.iso-custom
    cd 8.2-x64-dvd.iso-custom
    rsync -a /mnt/ .
    
 
     # find the source, unpack it, delete it
     cd 8.2-RC2/base
     mkdir TEMP &&  cat base.?? | tar --unlink -xpzf - -C TEMP
     rm base.??

     # Go there (into the new ISO staging area)
     cd TEMP
```

How can I proceed further. All I need is to:
patching the driver, replacing it,and running *make release* with the proper parameters.

As I can't see sys/dev/mfi under /usr/src, I have no idea how to proceed further.

I have been suggested to follow http://romana.now.ie/writing/customfreebsdiso.html link but it seems to be little complicated.


----------



## SirDice (Nov 7, 2011)

You can probably get all the information you need from release(7) and build(7).


----------



## SirDice (Nov 9, 2011)

Keep in mind that those tutorials are a little old. You can tell by the fact they use cvsup(1). csup(1) has been part of the base OS for quite a while, so there's no need anymore to install net/cvsup-without-gui.


----------



## linuxunix (Nov 9, 2011)

Any idea where I can get the latest document? All I can see http://romana.now.ie/writing/customfreebsdiso.html as the document as per my need but several years old. Do those steps still hold valid? Please suggest in case any step which is talked by the above link holds obselete.


----------



## SirDice (Nov 10, 2011)

linuxunix said:
			
		

> Any idea where I can get the latest document?


Yes, release(7). The /usr/src/release/Makefile file also contains quite a lot of comments.


----------



## linuxunix (Nov 10, 2011)

Thanks.


----------



## peetaur (Jan 26, 2012)

I tried all the above, read the comments, the man pages, the handbook, random howtos, etc. and nothing worked. [EDIT: by the way, I am building 8-STABLE here, and don't know if the same applies to 9-*]

In the end, this is what worked. It is clearly a hack, and appears as if the FreeBSD release system is broken. But I am guessing it is a documentation issue, otherwise I would never been able to download an iso 



Download the sources through cvsup (rather than csup, but maybe both work)
    This step inspired by these 2 pages:
http://romana.now.ie/writing/customfreebsdiso.html
http://wiki.idefix.fechner.net/index.php/FreeBSD-Build_Own_CD

    I downloaded them to /usr/cvs

 Put them in a CVS root, following these instructions:

http://www.freebsd.org/doc/en/articles/cvs-freebsd/article.html

    Here is exactly what I did (same as handbook with different paths):

```
% mkdir /usr/ncvs
        % cvs -d /usr/ncvs init
        % cd /usr/cvs2
        % cvs -d /usr/ncvs checkout CVSROOT
        % cd CVSROOT
        % cp /usr/cvs/* .
        % cvs add *
```


 Patch the Makefile (hack #1, my own idea):


```
--- /usr/src/release/Makefile   2012-01-24 10:22:36.550332286 +0100
+++ /usr/cvs2/CVSROOT/src/release/Makefile      2012-01-26 11:48:45.793630981 +0100
@@ -499,6 +499,12 @@
 .endif
 .endif
 .endif
+#pm: added hack
+       -test -f asdfasdf && echo "Copying whole src since it is missing"
+       if [ ! -f ${CHROOTDIR}/usr/src/sys/conf ]; then \
+               cp -an /usr/cvs2/CVSROOT/src// ${CHROOTDIR}/usr/src/ ; \
+       fi
+
        # Add version information to those things that need it.
        if [ ! -f ${CHROOTDIR}/tmp/.world_done ]; then \
                cd ${CHROOTDIR}/usr/src/sys/conf && \
```

Without this patch, I was getting this error:

```
...
        cvs checkout: Updating src/usr.sbin/zzz
        rm -rf /root/archive/FreeBSD/usr/ports
        # Add version information to those things that need it.
        if [ ! -f /root/archive/FreeBSD/tmp/.world_done ]; then  cd /root/archive/FreeBSD/usr/src/sys/conf && [newline added for readability]
        mv newvers.sh foo &&  sed "s/^RELEASE=.*/RELEASE=8.2-STABLE-20110927/" foo > newvers.sh &&  rm foo;  fi
        cd: can't cd to /root/archive/FreeBSD/usr/src/sys/conf
        *** Error code 2
```

    The "-test -f asdfasdf" part of my patch is just because I don't understand how to write/edit a Makefile, and echo alone didn't work.

 Make a symlink (hack #2, my own idea)

`# ln -s /usr/cvs2/CVSROOT /usr/cvs2/CVSROOT/`

Without this, I got this error:

```
cd /root/archive/FreeBSD/usr &&   cvs -R  -d /usr/cvs2/CVSROOT  co  -P src
        cvs [checkout aborted]: /usr/cvs2/CVSROOT/CVSROOT: No such file or directory
        *** Error code 1
```

 Run make

`# make release BUILDNAME=8.2-STABLE-20110927 CHROOTDIR=/root/archive/FreeBSD CVSROOT=/usr/cvs2/CVSROOT`

FYI I also tried without the symlink and:

`# make release BUILDNAME=8.2-STABLE-20110927 CHROOTDIR=/root/archive/FreeBSD CVSROOT=/usr/cvs2`

which just results in a different error.

 Make iso files (last part mentioned here).

    If you were planning on adding some scripts and other files, add them now to dvd1.

`# cd /usr/cvs2/CVSROOT/src/release/amd64/`

`# sh mkisoimages.sh -b FreeBSD82STABLE20110927 ~/archive/FreeBSD-8.2-STABLE-20110927.iso ~/archive/FreeBSD/R/cdrom/dvd1`

And thanks for the links, which helped a bunch. The handbook seems to have nothing at all about "make release".


----------



## linuxunix (Apr 19, 2012)

When did you insert the mfi module? I don*'*t see any step talking about it. *P*lease suggest. All I want to build is FreeBSD 9.0 with customized mfi driver.


----------



## peetaur (Apr 19, 2012)

You need to edit your kernel configuration file:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html

And maybe you need this too:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-building.html


----------



## linuxunix (Apr 22, 2012)

Peetaur,

Can you help me with actual steps (as you have been successful with your setup) for inserting 	mfi_freebsd90_x64_rbm.tgz (attached with this thread http://forums.freebsd.org/showthread.php?p=174683#post174683)?

I can see lots of links but I need the actual step for inserting this driver and to create the ISO.


----------



## linuxunix (Apr 22, 2012)

What is cvs2 here?


----------



## linuxunix (Apr 23, 2012)

peetaur said:
			
		

> You need to edit your kernel configuration file:
> 
> http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html
> 
> ...



Thanks for the above link.
I am following http://wiki.idefix.fechner.net/index.php/FreeBSD-Build_Own_CD completely.
On one of the step it says 

```
Then apply your changes to /usr/src (kernel config files, patches everything you need).
```

Is that talking about /usr/src/sys/amd64/conf/GENERIC kernel? What entry I need here related to mfi?

Also

```
Create a directory for own packages that will be included to the CD:
mkdir -p /root/ownpackages/disc1
Now copy all packages to the directory /root/ownpackages/disc1.
```

Copy all packages ..which packages it's talking about?

Again, my question is what about the mfi driver I have? Do I need to do diff here to insert it as a patch?


----------



## peetaur (Apr 23, 2012)

linuxunix said:
			
		

> What is cvs2 here?



I look back at what I wrote and am as confused as you are. I'll try to make sense of it... here is my old step 2 including comments, and the bold parts are new.


```
make a directory to create a real local cvs repository (not the working dir, but the repository itself)
        % mkdir /usr/ncvs
    initialize the repository    
        % cvs -d /usr/ncvs init
    [B]inserting this step here to fix a small bit of confusion: create the working directory
        % mkdir /usr/cvs2[/B]
    change to the working directory (not the repository, but the checked out version)
        % cd /usr/cvs2
    check out the repository you just created (which should be empty)
        % cvs -d /usr/ncvs checkout CVSROOT
    change directory to CVSROOT (I don't know why it is named that... I guess it is just a different standard than the normal trunk/branches/tags way to organize things)
        % cd CVSROOT
    copy your actual code (downloaded in my step #1 in a previous post) to the empty checked out cvs working directory (so now the working directory isn't empty)
        % cp /usr/cvs/* .
    add the files to the repository (so now the real cvs repository isn't empty)
        % cvs add *
    [B]at this point there was no commit/push or whatever the cvs equivalent is, but I didn't look that up since it works in the end anyway.[/B]
```


----------



## peetaur (Apr 23, 2012)

linuxunix said:
			
		

> Thanks for the above link.
> I am following http://wiki.idefix.fechner.net/index.php/FreeBSD-Build_Own_CD completely.
> On one of the step it says
> 
> ...



Yes, /usr/src/sys/amd64/conf/GENERIC is your "kernel config file". You should also back it up first, and you could also rename it, since it is not the "GENERIC" one anymore, but a modification of it.




			
				linuxunix said:
			
		

> What entry I need here related to mfi?



Unfortunately, I don't know. I thought it would be the same name as the kernel module that is built. 

For example in my GENERIC file, which after (& not including) 8.2-RELEASE includes:


> device          mps             # LSI-Logic MPT-Fusion 2


Which replaces the need to load the mps.ko kernel module.

But if you don't have a kernel module... I don't know which name you use. I would search elsewhere for other examples, and then try to find those examples in my GENERIC file to make sense of it.

This is also in my GEMERIC file:


> device          mfi             # LSI MegaRAID SAS



So looking at that, I would assume that if you modified the existing mfi code (not copied it somewhere, renamed it, etc.) you can just verify that your kernel config file has mfi like mine, and that your changes to mfi are in your working source tree, and then just build without editing.




			
				linuxunix said:
			
		

> Also
> 
> ```
> Create a directory for own packages that will be included to the CD:
> ...



I think this is the stuff you created using pkg_create. If you didn't create any, don't worry about it. (I skip this step, since you would use portsnap fetch, etc. to build the latest ports anyway.)



			
				linuxunix said:
			
		

> Again , my question is what about the mfi driver I have? Do I need to do diff here to insert it as a patch?



If you modified the mfi driver source code, you should have edited/patched the code in your build tree (in my example, the /usr/cvs2 directory), before the build. (Do I understand your question?)


----------



## peetaur (Apr 23, 2012)

One more comment about what I said  about renaming "GENERIC" to something else, and step 5 in my original howto thing. If you rename it, then I guess the new name needs to go somewhere in step 5.


----------



## linuxunix (Apr 23, 2012)

Thanks Peetaur for the quick response.

This is what I did until  now(below). Suggest if this looks Ok.

```
Preparing the Local Repository:

mkdir -p /usr/local/etc/cvsup
cp /usr/share/examples/cvsup/cvs-supfile /usr/local/etc/cvsup/ncvs

Edit the file:
*default host=cvsup10.us.freebsd.org
*default base=/usr
*default prefix=/home/storage/ncvs
*default release=cvs
*default delete use-rel-suffix

*default compress

# Add these
src-all
src-crypto
src-eBones
src-secure
src-sys-crypto
ports-all
doc-all
#www

cvsroot-all

Checkout the sources:

mkdir /home/storage/ncvs
cvsup -g -L2 ncvs

Building the Custom ISO:

Delete /usr/src and check it out from your local repository:

cd /usr
rm -R src
mkdir -p /usr/src
cd /usr
cvs -R  -d /home/storage/ncvs  co  -P -r RELENG_6 src
cd /usr/
cp -pR src src.orig

Applying the Kernel changes:

Move to the arch/conf directory and copy the GENERIC configuration file to the name you want to give your kernel. For example:

         # cd /usr/src/sys/amd64/conf			
         # cp GENERIC MYKERNEL

Comment the following line in the file MYKERNEL by placing # at the   beginning of the line.


         device     cbb    #cardbus (yenta) bridge

Add the following line to the file /usr/src/sys/conf/files .

         dev/mfi/mfi_syspd.c     optional     mfi

  (Note add this line next to the line which has dev/mfi/mfi_cam.c optional mfi)


Copy the attached zip (mfi.zip) file under the path /usr/src/sys/dev (Before proceeding to next step make sure
 that the directory with name â€œmfiâ€ does not exist under path /usr/src/sys/dev/. If already a directory with
 name â€œmfiâ€ exists, move it to some other folder. 

Under the directory /usr/src/sys/dev, run the following command to unzip the source.

            # tar â€“x â€“f mfi.zip
```

Now If I see the next suggested steps on http://wiki.idefix.fechner.net/index.php/FreeBSD-Build_Own_CD it says 
"..We will use a unattened install procedure to install the own build kernels so we don't have to modify the sysinstall package.."



> To use our own install script edit:
> /usr/src/usr.sbin/sysinstall/Makefile
> and add:
> CFLAGS+= -DLOAD_CONFIG_FILE=install.cfg
> ...



No idea if I really need it. What actually packages I need here. Still didn't get it.

As of now, what I did is added 
	
	



```
CFLAGS+= -DLOAD_CONFIG_FILE=install.cfg
```
 to /usr/src/usr.sbin/sysinstall/Makefile and created an install.cfg file in /usr/src/release and created a directory (/root/ownpackages/disc1) for own packages that will be included to the CD. Skipped this 





> Now copy all packages to the directory /root/ownpackages/disc1.


Just ran :


```
cd /usr
diff -Nur src.orig src >/root/patch.diff
```

Will it be sufficient. When I ran the last command, it's asking file to patch:
What issue it could be?


----------



## linuxunix (Apr 23, 2012)

Hi,

I am struggling hard to build a custom ISO.
if you can elaborate your overall steps that would help me with my new mfi driver.


----------



## peetaur (Apr 24, 2012)

You need to be more specific.


----------

