# Can't set default snd unit from loader.conf



## donallen (May 1, 2020)

Just installed 12.1 on a Thinkpad T410. There were a number of problems that needed to be solved after installation, but let's focus on just one: there was no sound as installed. After some digging and experimenting, I found that setting hw.snd.default_unit to 1 (default is 0) with sysctl did the trick. So I added the following line to /boot/loader.conf to obtain this setting on every reboot:

hw.snd.default_unit="1"

This does not work. When the system comes up, hw.snd.default_unit is 0. Checking dmesg, I find this:

Setting sysctl hw.snd.default_unit failed: 22

Really not helpful. Can anyone tell me what 22 means?


----------



## Sevendogsbsd (May 1, 2020)

Check the first section here: https://www.freebsd.org/doc/handbook/sound-setup.html. I think the setting you made only selects the default sound card, but it doesn't load the sound driver. Not 100% certain on that but read through that first section and see if the recommended changes work for you.


----------



## donallen (May 1, 2020)

You are correct that the setting I made only changes the default unit and does not load the driver. But the driver I need (for Intel sound hardware) is now part of the kernel and does not need to be loaded. The proof of that is in my initial post, though I didn't spell it out explicitly. If I boot the system, log in as root and do

sysctl hw.snd.default_unit=1

the sound now works. No driver loading needed.

Thanks for the response.


----------



## T-Daemon (May 1, 2020)

donallen said:


> *hw.snd.default_unit* to 1 (default is 0) with sysctl did the trick. So I added the following line to */boot/loader.conf*


That's the wrong place. The right place is in /etc/sysctl.conf. From sound(4):

```
Runtime Configuration
     There are a number    of sysctl(8) variables available which can be modified
     during runtime.  These values can also be stored in /etc/sysctl.conf in
     order to automatically set    them during the    boot process.  hw.snd.*    are
     global settings and dev.pcm.* are device specific.

...
      hw.snd.default_unit
```


----------



## donallen (May 1, 2020)

Thank you -- that works.

This leads to a documentation question, though. While I am a very experienced Linux and OpenBSD user and administrator, that is not the case with FreeBSD. There *are* sysctl variables that can be (must be?) set in loader.conf. Quoting from my own loader.conf:
kern.vty="vt"
hw.vga.textmode="1"
hw.psm.synaptics_support="1"
hw.psm.trackpoint_support="1"

Maybe I missed it in the documentation, which I obviously have not read cover-to-cover, but the question becomes how is someone like me is supposed to know that hw.psm.synaptics_support settings belong in /boot/loader.conf, but hw.snd.default_unit settings belong in /etc/sysctl.conf? (Short of posting a question here and fortunately finding someone like you who knows the answer.)

For example, the sysctl man page says:

Some of the variables which cannot be modified during normal system
     operation can be initialized via loader(8) tunables.  This can for
     example be done by setting them in loader.conf(5).  Please refer to
     loader.conf(5) for more information on which tunables are available and
     how to set them.

Which, of course, was what led me to place the sound setting in loader.conf.
The loader.conf man page has no useful information that I can decode about what "tunables" are available. For example, setting hw.vga.textmode in loader.conf works (to get console switching to work properly, another FreeBSD install headache). Where is that documented?

I'm raising these questions to try to understand whether I've been deficient in reading the documentation or the documentation is deficient.


----------



## T-Daemon (May 1, 2020)

donallen said:


> There *are* sysctl variables that can be (must be?) set in loader.conf. Quoting from my own loader.conf:
> kern.vty="vt"
> hw.vga.textmode="1"
> hw.psm.synaptics_support="1"
> ...



Carry out a search in the documentation:

1 - Search in in the manuals:

Execute manpath(1), that will, as the name says, print man pages paths.

```
/usr/share/man:/usr/local/share/man:/usr/local/man:/usr/share/openssl/man:/usr/local/lib/perl5/site_perl/man:/usr/local/lib/perl5/5.30/perl/man
```

To search for documentation in the manuals for `hw.psm.sysnaptics_support`:
`grep -rZn hw.psm.sysnaptics_support /usr/share/man /usr/local/share/man /usr/local/man`

```
Binary file /usr/share/man/mandoc.db matches
/usr/share/man/man4/psm.4.gz:336:.Va hw.psm.synaptics_support
```

`grep -rZn hw.snd.default_unit /usr/share/man /usr/local/share/man /usr/local/man`

```
Binary file /usr/share/man/mandoc.db matches
/usr/share/man/man4/snd_hda.4.gz:88:.Ar hw.snd.default_unit
/usr/share/man/man4/sound.4.gz:340:.It Va hw.snd.default_unit
/usr/share/man/man4/sound.4.gz:349:.Pa /dev/dsp Ns Va ${hw.snd.default_unit} .
/usr/share/man/man4/sound.4.gz:699:.Dl sysctl hw.snd.default_unit=1
/usr/share/man/man4/snd.4.gz:340:.It Va hw.snd.default_unit
/usr/share/man/man4/snd.4.gz:349:.Pa /dev/dsp Ns Va ${hw.snd.default_unit} .
/usr/share/man/man4/snd.4.gz:699:.Dl sysctl hw.snd.default_unit=1
/usr/share/man/man4/pcm.4.gz:340:.It Va hw.snd.default_unit
/usr/share/man/man4/pcm.4.gz:349:.Pa /dev/dsp Ns Va ${hw.snd.default_unit} .
/usr/share/man/man4/pcm.4.gz:699:.Dl sysctl hw.snd.default_unit=1
```



donallen said:


> For example, setting hw.vga.textmode in loader.conf works (to get console switching to work properly, another FreeBSD install headache). Where is that documented?


`grep -rZ hw.vga.textmode /usr/share/man /usr/local/share/man /usr/local/man`

```
Binary file /usr/share/man/mandoc.db matches
/usr/share/man/man4/vt.4.gz:.Cd hw.vga.textmode=1
/usr/share/man/man4/vt.4.gz:.Va hw.vga.textmode
/usr/share/man/man4/vt.4.gz:.It Va hw.vga.textmode
```

Open man vt(4) (pager is less(1)), search in manual `/hw.vga.textmode`, to repeat search press `n`, to repeate search reverse direction press `N`, for (search) help press `h`.

2 - Search in the FreeBSD documentation: `pkg install en-freebsd-doc`, with `pkg info -l en-freebsd-doc` determine installation path, e.g.:

/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/book.html (single HTML), or
/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/faq/book.html (single HTML)

Enter those file paths in a web browser (graphical or console), bookmark them, open when necessary, use find function of the web browser. I have in www/lynx and www/firefox that documentation (and other) bookmarked.

Running `pkg info -l en-freebsd-doc` you may notice a lot of other documentation is installed. You may find the one or other interesting.

Books: https://download.freebsd.org/ftp/doc/en_US.ISO8859-1/books/
Articles: https://download.freebsd.org/ftp/doc/en_US.ISO8859-1/articles/

PS: `hw.psm.sysnaptics_support` is mentiones in the handbook page Sevendogsbsd linked to:


Sevendogsbsd said:


> https://www.freebsd.org/doc/handbook/sound-setup.html.




```
In this example, the graphics card (NVidia) has been enumerated before the sound card (Realtek ALC889). To use the sound
card as the default playback device, change *hw.snd.default_unit* to the unit that should be used for playback:

# *sysctl hw.snd.default_unit=n*

where n is the number of the sound device to use. In this example, it should be 4. *Make this change permanent by adding the
following line to /etc/sysctl.conf:*

hw.snd.default_unit=4
```



donallen said:


> I'm raising these questions to try to understand whether I've been deficient in reading the documentation or the documentation is deficient.


Neither nor, you lacked the know how, but now you have it.


----------



## George (May 1, 2020)

Settings in loader.conf are kernel environment settings. See kenv(). The file is parsed very early, even before the kernel is loaded (by loader(8)). A mistake here can lead to an unbootable system. Examples are in /boot/defaults/loader.conf.

Sysctl.conf is parsed later during the boot process. Typos here won't do much harm.
Sometimes it can be hard to determine which setting is which, as `sysctl` won't tell you.


----------



## donallen (May 3, 2020)

T-Daemon said:


> Carry out a search in the documentation:
> 
> 1 - Search in in the manuals:
> 
> ...



Good information. Thank you for going to the trouble.


----------



## T-Daemon (May 4, 2020)

donallen said:


> Thank you for going to the trouble.


You’re welcome, and no trouble at al, just sharing my experience. In the past I saw here in the forums a command option, but had difficulties finding it in the man pages, not knowing which manual to look into ( the command itself wasn't helpful to determine the exact man page) . I came up with the `grep -rZ` method.

Having the FreeBSD Handbook and FAQ locally at hand ( and all the other books and articles ), I can query a search fast ( if they are single HTML ), or browse through them.


----------

