# print error-message to a file?



## Nokobon (May 11, 2009)

Hello,
I've made a custom kernel, but it fails at compiling with an error message.
I just want to print that error in a file but as I'm a newbie to FreeBSD I can't figure it out how to do that.

I tried:

```
make KERNCONF=MYKERNEL kernel > file
```
But that only prints the whole output of the complining process to the file, and stops to print the error message to the screen.

So what do I have to do?
Or is there any error-log for this, I didn't discover yet?

Thanks...


----------



## SirDice (May 11, 2009)

It depends somewhat on the shell you are using. If you use bash add *2>&1* to the end of the line. That will redirect STDERR to STDOUT and as a result to your file.


```
make buildkernel KERNCONF=MYKERNEL > file 2>&1
```

For (t)csh you will need to use *>&*.

```
make buildkernel KERNCONF=MYKERNEL > file >&
```

A simpler approach that will always work is to make use of the script(1) command.


----------



## Nokobon (May 11, 2009)

Yes, thanks for that lightbulb...
I'll try script(1).
I've read something about it some days ago but somehow it didn't come to my mind. xD
I'm really oblivious...


----------



## DutchDaemon (May 11, 2009)

*Just* the errors?


```
make buildkernel KERNCONF=MYKERNEL 2>file
```

Mind you; without the context leading up to the error, this may be uninformative. better capture everything and cut from it what you need to recognise and/or address the problem.


----------



## Nokobon (May 11, 2009)

DutchDaemon said:
			
		

> *Just* the errors?
> 
> 
> ```
> ...



Yeah, you are right...the context might be as important es the error itself.
Now I captured everything with script(1).
That's effective and easy 

By the way...I build my kernel with:

```
make KERNCONF=MYKERNEL kernel
```
What's the difference to:

```
make buildkernel KERNCONF=MYKERNEL
```
?


----------



## swills@ (May 11, 2009)

There's no difference as far as I know. Personally, I like to set KERNCONF=MYKERNEL in /etc/make.conf.


----------



## Nokobon (May 12, 2009)

swills said:
			
		

> There's no difference as far as I know. Personally, I like to set KERNCONF=MYKERNEL in /etc/make.conf.



This file doesn't exist by default, so you have to create it manually?


----------



## phoenix (May 12, 2009)

Nokobon said:
			
		

> By the way...I build my kernel with:
> 
> ```
> make KERNCONF=MYKERNEL kernel
> ...



*make kernel* runs (in essence) *make buildkernel; make installkernel*.  IOW, the kernel gets installed right away, as soon as it is built.

I prefer to do it in two steps (build, then install) as you can use additional flags like *KODIR=/boot/newkernel* with the installkernel, to install the new kernel to a separate directory.  Then you can use *nextboot -k newkernel* to configure the system to boot using the new kernel _on the next boot only_.  If something goes wrong, you just reboot, and it comes back up with the working, known-good, /boot/kernel.

A little extra safety protection is always good.


----------



## SirDice (May 12, 2009)

Nokobon said:
			
		

> This file doesn't exist by default, so you have to create it manually?



Yes, you can create /etc/make.conf if it doesn't exist.


----------



## vivek (May 12, 2009)

You can try something as follows to save the output:

```
script /var/tmp/build.output
make ...
exit
```
Do not save to /tmp, as it may get clean out after reboot.


----------



## DutchDaemon (May 12, 2009)

Or copy it from /usr/share/examples/etc/make.conf and edit it.


----------



## Nokobon (May 13, 2009)

phoenix said:
			
		

> *make kernel* runs (in essence) *make buildkernel; make installkernel*.  IOW, the kernel gets installed right away, as soon as it is built.
> 
> I prefer to do it in two steps (build, then install) as you can use additional flags like *KODIR=/boot/newkernel* with the installkernel, to install the new kernel to a separate directory.  Then you can use *nextboot -k newkernel* to configure the system to boot using the new kernel _on the next boot only_.  If something goes wrong, you just reboot, and it comes back up with the working, known-good, /boot/kernel.
> 
> A little extra safety protection is always good.


I think nextbootis great and I'll use it in the future when ever I build a kernel.

But first I will trie to build a bad kernel and then remove it using the loader prompt...just for educational purpose.
Practise these things may be a good way to become a sysadmin...^^

Regarding to /etc/make.conf:
I don't really see a reason why I should set KERNCONF=MYKERNEL in /etc/make.conf.
When building a kernel with a new name, it seems to be more complicated to set it in a conf-file than to set it directly in the command...


----------



## SirDice (May 13, 2009)

Nokobon said:
			
		

> Regarding to /etc/make.conf:
> I don't really see a reason why I should set KERNCONF=MYKERNEL in /etc/make.conf.
> When building a kernel with a new name, it seems to be more complicated to set it in a conf-file than to set it directly in the command...


If you set it in make.conf you don't have to add the KERNCONF= define to make buildkernel and installkernel. Since most people install the same kernel version for each machine it makes sense to put it in make.conf. That way you will always get the correct kernel when doing make installkernel. If KERNCONF isn't defined in make.conf or on the commandline it will install GENERIC.


----------



## Nokobon (May 13, 2009)

SirDice said:
			
		

> If you set it in make.conf you don't have to add the KERNCONF= define to make buildkernel and installkernel. Since most people install the same kernel version for each machine it makes sense to put it in make.conf. That way you will always get the correct kernel when doing make installkernel. If KERNCONF isn't defined in make.conf or on the commandline it will install GENERIC.



Okay, so setting KERNCONF in  make.conf only makes sense when you install the same kernel on many machines or when you keep the same name for the kernel after editing it.
But I build that kernel only once on one machine so setting KERNCONF on the command-line is less circuitous.


----------



## SirDice (May 13, 2009)

Nokobon said:
			
		

> But I build that kernel only once on one machine so setting KERNCONF on the command-line is less circuitous.


You have to buildkernel etc. when you update, so it'll save typing and you don't have to remember which kernel config you used on that machine :e


----------



## Nokobon (May 13, 2009)

SirDice said:
			
		

> You have to buildkernel etc. when you update, so it'll save typing and you don't have to remember which kernel config you used on that machine :e



Okay, I didn't know that I have do rebuild the kernel when I update.
So far I haven't occupied myself with updating, but soon I will to get 7.2


----------



## BuSerD (May 16, 2009)

swills said:
			
		

> There's no difference as far as I know. Personally, I like to set KERNCONF=MYKERNEL in /etc/make.conf.



I had not thought of that or read it anywhere. Very nice.


----------

