понедельник, 9 октября 2017 г.

Upgrading FreeBSD box with a custom kernel

PATCHING THE BASE SYSTEM
 
From FreeBSD handbook, chapter 23:
Only the GENERIC kernel can be automatically updated by freebsd-update. If a custom kernel is installed, it will have to be rebuilt and reinstalled after freebsd-update finishes installing the updates.
In this post I am going to show how I usually update my FreeBSD home box running a custom kernel inherited from the GENERIC kernel.

First of all, I update the GENERIC kernel. It is very possible.
From the chapter of handbook mentioned above:
freebsd-update will detect and update the GENERIC kernel if /boot/GENERIC exists, even if it is not the current running kernel of the system.
This option suits my requirements, because my kernel based on the GENERIC.
$ sudo freebsd-update fetch
$ sudo freebsd-update install
$ reboot
After the system come back, I upgrade the custom kernel (in my case called FBSD_GF4-1-NOSND).
$ sudo -i
# cd /usr/src
# make buildkernel KERNCONF=FBSD_GF4-1-NOSND
Building a kernel may take a while. After the kernel is built, I install it.
# make installkernel KERNCONF=FBSD_GF4-1-NOSND
# reboot

UPGRADING SOFTWARE PACKAGES

Starting the Autumn, 2017 I dislike packages again. Ports are the strength of FreeBSD! But I am going to describe the process of updating software packages. For the memories.
$ sudo portsnap fetch update
$ sudo pkg update
$ pkg updating | $PAGER
After reading UPDATING info carefully, I upgraded the software next way.
$ sudo pkg upgrade
$ sudo pkg clean
$ sudo pkg autoremove
Then reboot and try to count regressions =)
$ reboot

четверг, 20 апреля 2017 г.

среда, 22 марта 2017 г.

MySQL notes

All "recipes" from this post are for FreeBSD (10.3).

How to completely change MySQL 5.6 with 5.7?

NB, please, that this approach will cause wiping of all MySQL data from your host.
  1. sudo pkg remove mysql56-client # will remove the server too
  2. sudo rm -rd /var/db/mysql /usr/local/etc/mysql
  3. sudo pkg install mysql57-server # will install the client too

Start MySQL

  1. sudo service mysql-server onestart

Auto start MySQL after the system boots

  1. sudo cp /etc/rc.conf /etc/rc.conf.old
  2. echo 'mysql_enable="YES"' >> /etc/rc.conf

First time login as DB server admin

  1. sudo cat /root/.mysql_secret # remember the PASSWORD
  2. mysql -u root -p # type the PASSWORD from /root/.mysql_secret

Reset password before usage of MySQL

Execute the next request in the MySQL monitor.
  • SET PASSWORD = PASSWORD('vs?!h(y=/!er');

Create a regular user account

  • CREATE USER IF NOT EXISTS 'vasilyb'@'localhost' IDENTIFIED BY '21212121' PASSWORD EXPIRE;

Remove a user account

  • DROP USER 'jeffrey'@'localhost';

воскресенье, 17 июля 2016 г.

Restart a USB device from command line

How to restart a USB device from command line?

aka

How to restart a USB device without hardware operations?

Step 1. Find a device to restart

% usbconfig
Find the line according to the device to restart by its name (specified in the cornet brackets). Then find the sub string at the beginning of the found line. It will look like ugenU.A (in the example above: ugen0.3) if U is kinda bus number and A kinda port number.

Step 2. Restart the device

% usbconfig -u 0 -a 3 power_off
% usbconfig -u 0 -a 3 power_on
That's all. Thank you for reading.

пятница, 6 мая 2016 г.

4Front Open Sound System (OSS) installation - FreeBSD package

Intro and Preparation

OSS means Open Sound System. The FreeBSD default kernel statically links the NewPCM OSS driver from version 10. If you use FreeBSD 10 or newer, to avoid further conflict between 4Front vs. NewPCM drivers, please build your own kernel without audio support (you can use my example of how to do this).

Installation

Installation of the 4Front OSS driver is easy. Just install the oss package.
sudo pkg install oss
The pkgng will download at about 90 MiB from the repository and takes at about a half of GiB on the hard drive(s).

Do not forget to clean up the system after the installation.
sudo pkg clean

Enabling


To enable the 4Front OSS audio driver just add the next line to your /etc/rc.conf file and reboot the system.
oss_enable="YES"
cp /etc/rc.conf /etc/rc.conf ; echo 'oss_enable="YES" >> /etc/rc.conf ; reboot

Start OSS without rebooting

sudo service oss start

Test the sound system

The 4Front OSS has audio player, recorder, advanced mixer, detectors and a few other oss* utilities.
To test the OSS just enter the osstest command and listen a great piano music (what's the song is that? :-) ).
osstest
After OSS is installed you can use both mixer and ossmix utilities as an audio mixer.
ossmix

Volume level control

Libmatemixer does not work properly with OSS because it can not find any device to control. As a temporary fix you may want to put the next command to the MATE's auto start applications.
ossxmix -b

Sources

  1. OSS/FreeBSD

среда, 20 апреля 2016 г.

Browse WWW from terminal

Preface

With FreeBSD (and *nix in general) you can browse the WWW from your text terminal. There is a several text based WWW browsers (elinks based on links based on lynx, Edbrowse, W3M). All of them are not require you to buy expensive hardware to run them. They even work without graphical subsystem.

I am going to show you how to install the ELinks browser.

Installation

Just enter the next command and confirm downloading the package and installing the software.
% sudo pkg install elinks
To run the browser execute, for example, the next command.
% elinks ddg.gg




The ddg.gg is a shortcut link to the DuckDuckGo search engine page.

The greeting screen looks as shown below.


Usage of ELinks is pretty simple and intuitive. Just follow on-screen tips.







ELinks works without graphics (X11) from terminals and terminal emulators.






So you can search something in the Internet, and even use FTP, IRC and a few other protocols with ELinks. Enjoy!

Bibliography

1. Хабрахабр. Обзор текстовых вeб браузеров, date: 2016-04-20.

пятница, 15 апреля 2016 г.

Build a custom kernel

Build a custom kernel

Today I will show you how to build your custom kernel based on the standard GENERIC kernel.

Why?

Let me explain a situation when the custom kernel is useful. I love the MATE desktop environment with the classic GNOME2ish design. The MATE contains the libmatemixer package which provides, for example, possibility to adjust volume level using the according volume panel applet. The libmatemixer's package built with 4FRONT OSS support. Every time I upgrade software packages I have to make libmatemixer with ALSA support from the port.

This is not good. I think so. But I can't merely do `pkg remove alsa ; pkg install oss` because the 4FRONT OSS conflicts with NewPCM OSS built in FreeBSD 10's kernel by default. So before I will be able to install and use OSS from 4FRONT Technologies, I have to cut off all the audio drivers from the default GENERIC kernel.

To do this...

Create a new kernel configuration

Log in to the system as root. Go to the /usr/src/sys/i386/conf directory (where i386 is the architecture of your machine). Then create (if not exists) a directory where you are going to work with your kernels (/root/kernels for example). Then copy an existing kernel configuration to start from and open it in your favorite editor.

cd /usr/src/sys/i386/conf
mkdir /root/kernels
cp GENERIC /root/kernels/F1
ln -s /root/kernels/F1
vi F1

I started from the supplied GENERIC kernel. The first screen of its configuration looks like on the next screenshot.


Configure new kernel

Do not hesitate changing the title and the description of the new kernel in its configuration file.

I recommend you to save the kernel configuration after typing the comment to avoid a possible data lost. If you use vi, just press ESC, type the :w command and press ^j.

I am too lazy to make long description of kernels, so I just noted that my custom kernel called F1 (like the first generation in the biology/genetics) and that it does not contain any sound driver.

To configure (cut off) sound drivers, find the Sound support section in the kernel configuration file using the /Sound vi command.

In vi: press ESC, type /Sound and then press ^j.

This command will toggle you to at about 340 line.


To remove all sound devices drivers, commend out all the lines in the "sound support" section.


Comment all the lines in the "Sound support" section. In vi you may use the next command:
:342,349s/^/#

In vi you may use the :342,349s/^/# command to add the # sign to the beginning of all lines from 342 to 349 (in your configuration file sound support section may be located in the different lines interval!).

vi says that 8 sound devices drivers was excluded from the kernel

Save changes in the kernel configuration file.

Use :wq command of vi to save changes in the kernel configuration file and exit the editor.

Build the kernel

After the kernel is configured, you can build it. Go to the /usr/src directory and start build process.

cd /usr/src
make buildkernel KERNCONF=
F1
# where F1 is the name of the kernel you want to build

The kernel build process takes several minutes and looks like this


On my system it took ten or even twenty minutes.

After the kernel is built you will see the according message on the screen. Now it is possible to...

Install the kernel

To do this just enter the next command


make installkernel KERNCONF=F1

and wait several minutes.

The kernel installation process

Reboot the machine after kernel installation complete.

shutdown -r now
or simple
reboot

Check your work

Look at the output of the uname -a command after reboot. The output should contain the name of the newly installed kernel.

uname -a

To ensure that my new kernel does not support my audio card I started the MPlayer and noticed that there is no sound now. Also I noticed the error message from OSS about missing audio device file.


Advanced. Configuration including

It is possible to include the one kernel configuration to the yours. Like "inheritance" in OOP. " This allows another configuration file to be included in the current one, making it easy to maintain small changes relative to an existing file" documentation says.

You are able to use the next self-descriptive options.
  • option
  • nooption
  • device
  • nodevice
Below is the example of the my kernel configuration based on the GENERIC kernel. My configuration just disables sound devices support from the kernel.
nodevice sound
nodevice snd_cmi
nodevice snd_csa
nodevice snd_emu10kx
nodevice snd_es137x
nodevice snd_hda
nodevice snd_ich
nodevice snd_via8233

Conclusion

So, I proud to say: the mission is complete. I removed audio support from the system. I am going to install the 4FRONT OSS sound system package next week or to. Thank you for your interest.

Bibliography

  1. Руководство FreeBSD. Глава 9. Настройка ядра FreeBSD, 9.5. Сборка и установка собственного ядра.
  2. Open Sound System for FreeBSD
  3. Configuring the FreeBSD Kernel. The Configuration File.