# Basic environment setup



## npgm (Jul 25, 2013)

Hi, everyone!

This post is a collection of notes that I've been keeping over the last few days. I'm pretty new to FreeBSD, so a lot of things don't seem obvious to me. I'm hoping this post will help, and encourage, new people to try out FreeBSD.

Comments, suggestions, feedback would be appreciated, especially from people with a lot more experience using FreeBSD. I'm still pretty new to the FreeBSD world, so please correct me if I'm wrong.

This howto is assuming that you've just installed FreeBSD 9.1 and this is your first boot to the system as root. Also, "open in a text editor" means use vi or ee to edit the file, for example, `vi file.txt`.

*Set up the correct locale and system charset.*

Open /etc/login.conf in a text editor. At the end of the default:\ section add the following lines. Make sure to follow the syntax. Only the last line in the section should end in a colon.


```
default:\
    :morestuff:\
    :charset=UTF-8:\
    :lang=en_US.UTF-8:
```

After saving that file, run `cap_mkdb /etc/login.conf` and log out. When you log back in try running `locale` and you should see the new charset in effect.

*Get the current ports snapshot.*

This is important if you want to install software. Download ports for the first time with, `portsnap fetch extract`. Anytime after that just run `portsnap update` to update.

*Fix ntpd time exceeds sanity limit.*

This error came up for while booting. If you didn't get this error, skip to the next section.

Open /etc/rc.conf in a text editor. Add the `ntpdate` lines.


```
...
ntpdate_enable="YES"
ntpdate_hosts="0.us.pool.ntp.org"
ntpd_enable="YES"
...
```

*Set the type of CPU you have processor optimization.*

This one is a bit tricky because it's not as intuitive as you might think. Check out /usr/share/examples/etc/make.conf for a list of the different values you can set. I'm running FreeBSD with a Core i7 processor, but I'm not exactly sure what value I should set this to. Maybe someone can help out in the comments! 

Anyway, if you know what to do, open /etc/make.conf in a text editor and enter your CPU type at this line.
`CPUTYPE?=name`

I'm also unsure about the syntax here. Some people have CPUTYPE?=name, while others have CPUTYPE=name. I know the example make.conf says, "?= allows to buildworld for a different CPUTYPE", but I haven't the faintest idea of what that means. Someone comment!

*Enable the su command for regular users.*

If non-root users need root privileges, then the user root will need to add them to the wheel group by entering the following command. 
`pw groupmod wheel -m username`

You can check what groups any user is in by doing `groups username`. Make sure the new user is in the wheel group, then logout. When the user logs back in, they'll be able to use su.

*Update the FreeBSD base system.*

`freebsd-update fetch install`

*Future section: Enable ZFS*

I'm looking for a ZFS setup tutorial so basic and easy to understand that my twelve year old cousin could set it up. I don't really know much about ZFS. What are pools? How do I set that up? Why do I have to set that up? I'm also still new to FreeBSD, so I bet that adds to the confusion. Links to tutorials would be greatly appreciated!


----------



## free-and-bsd (Aug 18, 2013)

npgm said:
			
		

> Hi, everyone!...I'm pretty new to FreeBSD, so a lot of things don't seem obvious to me.


Good! Then the FreeBSD Handbook is the right place to start. You'll soon find out that brief and basic notes are by no means enough for such system as FreeBSD, and the extended ones have been written and maintained just for that very purpose.



> I'm looking for a ZFS setup tutorial so basic and easy to understand that my twelve year old cousin could set it up.


Depending on your cousin's capabilities this may or may not be possible (you aren't kidding, are you?)...

Anyway, you can google for "ZFS documentation", or "freebsd zfs root". That must give you links to both "basic step-by-step" setup and to detailed information on this advanced file system. Hope your 12-year-old cousin will eventually succeed with this interesting task...


----------



## wblock@ (Aug 18, 2013)

npgm said:
			
		

> *Fix ntpd time exceeds sanity limit.*
> 
> This error came up for while booting. If you didn't get this error, skip to the next section.
> 
> ...



This will not work, because both ntpd(8) and ntpdate(8) use the same socket and will not run at the same time.  But ntpd(8) can handle it alone:

```
ntpd_enable="YES"
ntpd_sync_on_start="YES"
```


----------



## sossego (Aug 18, 2013)

free-and-bsd said:
			
		

> Depending on your cousin's capabilities this may or may not be possible (you aren't kidding, are you?)...
> 
> Anyway, you can google for "ZFS documentation", or "freebsd zfs root". That must give you links to both "basic step-by-step" setup and to detailed information on this advanced file system. Hope your 12-year-old cousin will eventually succeed with this interesting task...



My nephew is twelve and probably could do such with a tutorial. His father is a different story; one of those people who are afraid to touch ye olde computer lest it screws up royally.


----------



## free-and-bsd (Aug 22, 2013)

Well I did it myself using a tutorial found from such googling (`"freebsd 9.1 zfs root"` into Search box). Just followed the instructions by literally copy-pasting command line (well actually I retyped the commands ) from the tutorial and carefully reading what short comments there were -- and here I am with a working system. Sure, later on you _may be interested_ to learn more about the commands you used, even if only out of curiosity.

In the tutorial you'll encounter various features of ZFS, so you may refer to the  documentation at the Oracle web site. It is so good and exhaustive, giving both simplified and detailed explanations and examples, that it is hardly possible to write anything better...


----------



## xibo (Aug 23, 2013)

The march/CPUTYPE processor name for an intel core i*, is corei7, while the name for a second or third generation core i* processor is corei7-avx.

Note that defining CPUTYPE, as well as CFLAGS/LDFLAGS/... is both experimental and unsupported.


----------



## TheDreamer (Oct 1, 2013)

npgm said:
			
		

> *Get the current ports snapshot.*
> 
> This is important if you want to install software. Download ports for the first time with, `portsnap fetch extract`. Anytime after that just run `portsnap update` to update.



The second command should probably be: `portsnap fetch update`

Unless you have something like: `portsnap -I cron update && pkg_version -vIl\<` in /etc/crontab



			
				npgm said:
			
		

> *Enable the su command for regular users.*
> 
> If non-root users need root privileges, then the user root will need to add them to the wheel group by entering the following command.
> `pw groupmod wheel -m username`
> ...



Personally, I preferring installing security/sudo, create /usr/local/etc/sudoers from /usr/local/etc/sudoers.sample and uncommenting the first '%wheel' line.  Gives you similar to letting them use su, but prompting for their own password.  This way you don't have to give out the root password.

Making more advanced configurations, can be more fine grained on what non-root users are allowed to do as root (or as a service user, such as www) and/or log what they are doing.

Plus its a good habit as there are places where there are no direct root logins.



			
				npgm said:
			
		

> *Fix ntpd time exceeds sanity limit.*
> 
> This error came up for while booting. If you didn't get this error, skip to the next section.
> 
> ...





			
				wblock@ said:
			
		

> This will not work, because both ntpd(8) and ntpdate(8) use the same socket and will not run at the same time.  But ntpd(8) can handle it alone:
> 
> ```
> ntpd_enable="YES"
> ...



Actually, it does work because /etc/rc.d/ntpdate is called before /etc/rc.d/ntpd, because /etc/rc.d/ntpd has a REQUIRES for 'ntpdate'.

'ntpdate_hosts=' isn't required, in this case, because if its empty it parses /etc/ntp.conf for 'server' and 'peer' lines for hosts to use.

The Dreamer


----------



## johnblue (Oct 2, 2013)

TheDreamer said:
			
		

> 'ntpdate_hosts=' isn't required, in this case, because if its empty it parses /etc/ntp.conf for 'server' and 'peer' lines for hosts to use.


Agreed.

As /etc/ntp.conf states:


```
# The following three servers will give you a random set of three
# NTP servers geographically close to you.
# See http://www.pool.ntp.org/ for details. Note, the pool encourages
# users with a static IP and good upstream NTP servers to add a server
# to the pool. See http://www.pool.ntp.org/join.html if you are interested.
#
# The option `iburst' is used for faster initial synchronisation.
#
server 0.freebsd.pool.ntp.org iburst
server 1.freebsd.pool.ntp.org iburst
server 2.freebsd.pool.ntp.org iburst
```

Also, I don't know how to say this without it sounding bad, but FreeBSD does have friends that are in other countries in the world.



When constructing a howto keep in mind a hard coded server FQDN that is geographical specific usually is not optimal either technically or socially.


----------



## TheDreamer (Oct 13, 2013)

johnblue said:
			
		

> ```
> # The following three servers will give you a random set of three
> # NTP servers geographically close to you.
> # See http://www.pool.ntp.org/ for details. Note, the pool encourages
> ...



I've wondered about this, all the members I get back when I query {0,1,2,3}.freebsd.pool.ntp.org are in the US.  But, if I were in another country would the result be the same?  Since it's theoretically possible to get different answers depending on where the query is originating from.  No idea how to generate a DNS query to appears to come from somewhere else on the planet to see.  Or it was decided to do US when the vendor pool was requested.  It is mentioned that {0,1,2,3}.pool.ntp.org can return servers all over the world, but when I test it all the servers returned are in the US.

For other countries/continents, you can replace 'freebsd' with continental zones (europe, asia, oceania, north-america, south-america, africa), or the 2 letter ISO country code.

The thing to watch for with 2.xxx.pool.ntp.org, is that it contains both IPv4 and IPv6 hosts.  And, if you don't have IPv6 connectivity you might get stuck with a server you can't poll.

Changing the line to:


```
server -4 2.freebsd.pool.ntp.org iburst
```

Will make it only lookup IPv4 addresses for this.  Unless, you are somewhere that has recursive query caching servers configured to filter AAAA.  Which is something that is happening at my place of work.

The Dreamer


----------



## Juanitou (Oct 13, 2013)

TheDreamer said:
			
		

> I've wondered about this, all the members I get back when I query {0,1,2,3}.freebsd.pool.ntp.org are in the US.  But, if I were in another country would the result be the same?  Since it's theoretically possible to get different answers depending on where the query is originating from.


For what is worth, the four IPs returned by `1.freebsd.pool.ntp.org` are located in France, where I live.

If I got you wellâ€¦


----------

