воскресенье, 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.


четверг, 14 апреля 2016 г.

Listening to the online radio with MPlayer

Install MPlayer

What if I want to listen to the online radio having got only base FreeBSD system? In this case I should only install the MPlayer package. MPlayer is a minimalist but powerful audio and video player, media encoder. It even can repair broken files.

To install it you should execute the next command.

The pkgng may ask you for the confirmation of updating itself. Don't disagree :)

After the pkg package is updated, confirm downloading and installing all packages required for MPlayer functioning.






As you can see MPlayer weights at about 60MB and requires you to download only 16MB over the network. You even needn't to find a [suspected] distributive over the Internet. And this works 'out of the box'. This is why I like UNIX.






Look! MPlayer is installed and you can now use it. But wait! You may ask "How can I use it if there is no graphics on the 'desktop'?". I'll ask: easy, MPlayer does not require video drivers and graphical X11 desktop. You can listen to the music or online radio from your terminal and do your work on the 2nd, 3rd, ..., 8th terminals. (This is the second reason I like UNIX: I have not to install tons of unnecessary software if I just want to listen to the radio.)

How yo use MPlayer

Easy (assuming you already have the a working Internet connection and integrated or discrete sound card, speakers). To listen to the radio you should use the command like this:
$ mplayer 'LOCATOR'
Where the LOCATOR is an media resource locator of the online radio stream (in simple words: URL of the stream you want to listen).

For example:
starts MPLayer and outputs the sound.

To sum up

I want to say that there is nothing impossible for modern operating systems. But FreeBSD (and many other *nix systems) really makes our life easy (compare to the heavy WMP with its horrible startup wizard). MPlayer is cool and easy to use. And you can quickly install it using the FreeBSD's pkgng manager in a seconds.






вторник, 5 апреля 2016 г.

The sudo primer

Introduction

To prevent spoiling your system you should avoid usage of dangerous su command. The sudo utility will help you with that. I am going to show you how to install it and perform its initial configuration.

Intallation

To install the sudo utility just run the next command (as super user)
pkg install sudo

Configuration

Using visudo edit the sudoers file. Add the next lines to the according sections

alias of your host


Host_Alias     LOCALHOST     =     fbsd.fbsd.gf4
where LOCALHOST is just host alias (like variable or named constant in programming) and fbsd.fbsd.gf4 is the name of your host (which you set during FreeBSD installation or configuration; you can find the value in the /etc/rc.conf file, under the hostname option)

user group alias

User_Alias     ADMINS     =     vasily
(you can use the whoami command to determine your user name)

enumerate commands to allow

Cmnd_Alias     PACKAGES     =     /usr/sbin/pkg
[use whereis pkg (pkg is just for example) to get the full path to the command you interested in]

specify the privilege

for example
ADMINS     LOCALHOST=(root)     PACKAGES

save changes and exit su

The picture for the example above

Usage

After you install and configure the sudo utility, you will be able to use the privileged commands from your regular user like this
sudo pkg update
First time sudo will show you the next message.

When sudo prompts the password, please type the password of the user you are working as!

Read the next

Install MPlayer and listen to the online radio.

Bootstrapping package manager

Afrer you installed FreeBSD it is necessary to initialize package manager: pkgng.
I do not know how simple is package management on linux, but I would have you believe that in FreeBSD it is very easy.

Just run the next command (as super user):
# pkg update
and then confirm bootstrapping.

Continue reading -> The sudo primer.

суббота, 26 марта 2016 г.

Enabling G-Journal in FreeBSD

Example 1

First of all, login to your system.
Then look at your fstab file and find a partition to enable geom journal on. Note that it is impossible to enable journal for the root / file system.
I am going to enable journal for the partition of the /var directory located on the ada0p4 geom.

First of all I check if the gjournal kernel module is loaded. If it is not loaded, I add it to the loader configuration (/boot/loader.conf) and load it.
Then I add a new partition for journal provider.
You can see that ada0s6 will become the journal provider.

To enable journaling for a partition you should make sure that the partition is not mounted. If it is mounted, you should to unmount it:
# umount -f /var/
and enable journaling using the next command:
# gjournal label -f ada0p4 ada0s6
where ada0p4 is a data provider and ada0s6 is a journal provider.
After journaling is enabled you should edit the fstab file.
For example if your data provider geom was ada0p4, you should replace its device with /dev/ada0p4.journal. You also should use asynchronous mounting for journaled partition using the async option.
After that you should to disable soft updates for the partition and tune its file system to set gjournal.
This was the last stepping stone to enable journaling for the partition, so you may mount it back now.

Example 2

The full geom journal enabling typescript may look like this.
$ su
# gpart add -t freebsd -a 4k ada0
# umount -f /usr/
# gjournal label -f ada0p5 ada0p7
# cp /etc/fstab /etc/fstab.old
# ed
e e /etc/fstab
e 5c
e /dev/ada0p5    /usr    ufs    rw,async    2    2
e .
e w
e q
# tunefs -J enable -n disable /dev/ada0p5.journal
# mount /usr/

Continue reading -> Bootstrapping package manager.

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

Installing FreeBSD 10.2

Today I will show you how to install the FreeBSD 10.2 operating system upon your computer. This process is quite easy and fast.

First of all you have to put previously prepared installation DVD to the tray of your optical drives reader and (re-)boot the computer.

After the computer boot you will see the next screen.
Press B or ENTER to boot FreeBSD installer immediately.

After boot process complete you will see the Installer welcome screen.
Press ENTER or I to start installation. The first stepping stone is key map selection.
Use arrow keys (UP and DOWN) to select the keyboard map you prefer.
Then press ENTER.
Press UP and, then, ENTER keys to continue with the selected map.
This screens asks you to type the name of the computer. Do it.
Then press ENTER to confirm. The next dialog allows to select operating system's components you wish to install. Move the selection using the UP and DOWN keys and check or uncheck components using the SPACE bar.
If you see a [*] mark on the contrary component, it means the component will be installed.


I usually install all the components except the extra documentation.
Disk partitioning is the most important part of the installation.
The Auto (UFS) option is the simplest. Just press ENTER...

...and again to grant FreeBSD access to the entire hard drive.
Select the GPT partition scheme as it is modern and the most commonly used and compatible scheme.
This user friendly pseudo graphical partition editor suggests you very easy and flexible disk setup. But I like to use separate file systems for a /usr and /var directories. To achieve this I set the selection over the ada0p2 partition (in using double press DOWN key) and delete it (press D) because of the aforementioned reason. Then I select ada0p3 partition and delete it too because I want to have a larger swap partition.
Then I select ada0 scheme and press C to create a new partition for the root file system. The partition editor shows the window where I specify the type (freebsd-ufs), the size (4GB) of the creating partition and the mount point (/).
After pressing the ENTER key I create the the partition for swap. I set partition type to freebsd-swap, size to 2GB (this is a required minimum for desktop systems) and leave mount point and label empty for this partition.
Then I create one more partition. This time is for the /usr directory.
And, finally, I create 4GB partition for the /var directory.
The rest free space I am going to use for G-Journals for the /usr and /var directories file systems.
I press F here to finish partitioning...
...and ENTER here to commit changes to the disk.

  *  *  *

FreeBSD starts copying files from check sums verification...
...and then extracts distribution files of the selected components from archives.
This stage takes a few minutes (up to ten).
Files copied! Next screen asks to type root's password.
Now FreeBSD installer tries to configure the network.
I pressed ENTER here.
And here.
Here too.
And here :-)
Of course YES :-) and wait few seconds.
Then...
...accept correctly determined network settings.
Here...
  ...I didn't know (it is the virtual machine), so I selected <No>...
 ...and pressed ENTER.
Then I select my region and...
...country.
Then I choose my primary time zone...
 ...and accepted time zone abbreviation.
The next screen offers different services.
I usually activate all of them exclude local caching validation resolver.
Then Installer asks us if we want to add users to the system.
I usually agree and add myself.
Note, that you should list groups separate them by space.
After confirmation I got the clean installed FreeBSD.
Here I press ENTER,
N (to prevent opening post installation shell)
and ENTER or R to reboot to the installed system.

That's enough for today: FreeBSD has been installed!

Read the next: Enabling G-Journal in FreeBSD.