# How to fast build the ISO image for a customized kernel



## redriver (Jan 13, 2016)

I have modified the kernel in order to fix a bug (related to storage driver for hyper-v), and I have to verify it through a fresh installation. I modified the release/generate-release.sh to build my local copy of FreeBSD 10.2. But it takes quite long time and failed at installworld:

```
install: hcsecd.conf and /home/honzhan/10.2/10.2.0/etc/bluetooth/hcsecd.conf are the same file.
```
The following is my modications. I did 3 modifications:

The script accepts only 1 argument: the customized src folder instead of svn repository.
Remove ${CHROOTDIR}/usr/src to ${CHROOTDIR}
Use parallel build `make -j8`
If I don't want to include src and doc, is there a quick method to build ISO image? Can I avoid `make installworld`? I don't think I need to installworld for build ISO image.


```
--- generate-release.sh 2015-12-28 14:52:08.071568000 +0800
+++ my-generate-release.sh      2016-01-12 19:12:46.745939000 +0800
@@ -46,11 +46,11 @@

usage()
{
-       echo "Usage: $0 svn-branch[@revision] scratch-dir" 2>&1
+       echo "Usage: $0 scratch-dir" 2>&1
        exit 1
}

-if [ $# -lt 2 ]; then
+if [ $# -lt 1 ]; then
        usage
fi

@@ -60,12 +60,12 @@ fi
: ${SVNROOTPORTS:=${SVNROOTBASE}/ports}
: ${SVNROOT:=${SVNROOTSRC}} # for backward compatibility
: ${SVN_CMD:=/usr/local/bin/svn}
-BRANCHSRC=$1
+#BRANCHSRC=$1
: ${BRANCHDOC:=head}
: ${BRANCHPORTS:=head}
: ${WORLD_FLAGS:=${MAKE_FLAGS}}
: ${KERNEL_FLAGS:=${MAKE_FLAGS}}
-: ${CHROOTDIR:=$2}
+: ${CHROOTDIR:=$1}

if [ ! -r "${CHROOTDIR}" ]; then
        echo "${CHROOTDIR}: scratch dir not found."
@@ -83,10 +83,10 @@ case ${TARGET_ARCH} in
esac
SETENV="env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin"
CROSSENV="${SETENV_TARGET} ${SETENV_TARGET_ARCH}"
-WMAKE="make -C /usr/src ${WORLD_FLAGS}"
+WMAKE="make -j8 -C /usr/src ${WORLD_FLAGS}"
NWMAKE="${WMAKE} __MAKE_CONF=/dev/null SRCCONF=/dev/null"
-KMAKE="make -C /usr/src ${KERNEL_FLAGS}"
-RMAKE="make -C /usr/src/release"
+KMAKE="make -j8 -C /usr/src ${KERNEL_FLAGS}"
+RMAKE="make -j8 -C /usr/src/release"

if [ $(id -u) -ne 0 ]; then
        echo "Needs to be run as root."
@@ -95,13 +95,13 @@ fi

set -e # Everything must succeed

-mkdir -p ${CHROOTDIR}/usr/src
-${SVN_CMD} co ${SVNROOT}/${BRANCHSRC} ${CHROOTDIR}/usr/src
-${SVN_CMD} co ${SVNROOTDOC}/${BRANCHDOC} ${CHROOTDIR}/usr/doc
-${SVN_CMD} co ${SVNROOTPORTS}/${BRANCHPORTS} ${CHROOTDIR}/usr/ports
+#mkdir -p ${CHROOTDIR}/usr/src
+#${SVN_CMD} co ${SVNROOT}/${BRANCHSRC} ${CHROOTDIR}/usr/src
+#${SVN_CMD} co ${SVNROOTDOC}/${BRANCHDOC} ${CHROOTDIR}/usr/doc
+#${SVN_CMD} co ${SVNROOTPORTS}/${BRANCHPORTS} ${CHROOTDIR}/usr/ports

-${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src ${WORLD_FLAGS} buildworld
-${SETENV} ${NWMAKE} -C ${CHROOTDIR}/usr/src installworld distribution DESTDIR=${CHROOTDIR}
+${SETENV} ${NWMAKE} -C ${CHROOTDIR} ${WORLD_FLAGS} buildworld
+${SETENV} ${NWMAKE} -C ${CHROOTDIR} installworld distribution DESTDIR=${CHROOTDIR}
mount -t devfs devfs ${CHROOTDIR}/dev
trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
```


----------



## drhowarddrfine (Jan 13, 2016)

While you may get an answer here, you are far more likely to get one on one of the mailing lists for advanced questions like this.


----------



## redriver (Jan 13, 2016)

There is no mailling list for release. It looks like 'freebsd-stable@freebsd.org' is more relative to release. I have sent email to this list.


----------



## SirDice (Jan 13, 2016)

Just build the release by hand. 


```
cd /usr/src
make buildworld buildkernel
cd /usr/src/release
make -DNOPORTS -DNODOC -DNOSRC -DNOPKG release
make -DNOPORTS -DNODOC -DNOSRC -DNOPKG DESTDIR=/storage/releases/myrelease install
```
If you want to use the resulting FTP install directory for poudriere you'll need to remove the NOSRC, poudriere requires the sources.


----------



## Chris_H (Jan 22, 2016)

Greetings, redriver
I wanted to whip up a custom boot/utility/live FreeBSD ISO, awhile back. So I wouldn't forget how I did it; I made myself a web page of my account. Have a look, it's here. It's a bit long, or I'd just paste it.http://bsdwatch.net/articles/custom-freebsd-iso

Hope this helps!

--Chris


----------



## redriver (Jan 29, 2016)

Thanks all. I finally rebuild ISO with another method, which is similar as Chris posted.

The whole release build take very long time (>3 hours) in my virtual machine and finally gives me an error. I cannot tolerate time spend on the long build and error troubleshooting.

My modification is in only one file, so I don't think it deserve that heavy build. Finally, I decided to patch my modification into FreeBSD 10.2 ISO.

First, I build the new kernel, kernel.txz, and generate the new MANIFEST. Then I mount the ISO to /mnt/ folder. Replace /mnt/boot/kernel/kernel, /mnt/usr/freebsd-dist/kernel.txz, and /mnt/usr/freebsd-dist/MANIFEST. After that, I run `/usr/src/release/amd64/mkisoimages.sh` to make the new ISO image. And that image is what I want.


----------

