Freebsd - My first steps in the Unix world

From Linux - Help
Jump to navigation Jump to search

My first steps in the BSD / Unix world

Freebsd logo.jpg

PAGE WORK IN PROGRESS

Goal: I'am a Linux user for two years, and I prefer using distributions like Gentoo and Arch Linux. I'am still learning Linux, mostly with books like How Linux Work and the LPI's study guide. Still I decided to try FreeBSD, this document will be a how to for FreeBSD, but like a baby, I need to learn to walk, and after I will neet to learn to run. Do not forget FreeBSD is a great community with a lot of already answered questions, so google will be youre friend (I hate using google, I prefer using the forums and the really nice explain handbook.

Installation

About the installation I have not too much to say, I will choose UFS as filesystem because it runs better than ZFS on a laptop, but If i mount an server or a NAS with a lot of storage I would prefer use ZFS.

You can read a discussion here.

For the rest I found this really basic, If you hang (or find this difficult) you should install more and more manually your distribution (you will learn so much).

I tried this installation on my laptop Lenovo t460s and works fine (only one issue, the wifi does not work). And I installed FreeBSD on my desktop.

A list of my desktop components:

 ARCTIC COOLING ALPINE 11 PLUS
 SEAGATE BARRACUDA 1TB SATA 3.5IN 7200RPM 64MB 6GB/S
 ASUS H170M-PLUS
 INTEL I3-6320 BOX 
 SANDISK SSD PLUS TLC 240GB
 ANTEC VP 500 PC-EC 
 GIGABYTE GV-N105TG1 GAMING-4GD
 CORSAIR DDR4 8GB
 CORSAIR CARBIDE SERIES SPEC-01 BLUE LED
 CORSAIR LED FAN AF120-LED
 IIYAMA GE2488HS-B2 24IN FHD FREESYNC VGA DVI HDMI 250CD/M2 VESA MM BK
 Corsaire k63
  • NOTE: If FreeBSD is installed on a Virtual Machine (ex.: QEMU) then download from here the ready images of FreeBSD.

Corsaire keyboard k63 does not work

I got a little problem with my corsair keyboard when trying to install it from my desktop (so I use a dell Keyboard and use this fix), you can read the solution here, if you have the same issue you need to type:

 $ usbconfig # to determine the device number of the keyboard, ugenX.Y.

Then add a quirk for that device:

 $ usbconfig -d ugenX.Y add_quirk UQ_KBD_BOOTPROTO

Right, my system is installed and I can boot to fresh new installation. What do I do, where do I go? "To Infinity... and Beyond!"

FreeBSD Basics

Installing and maintain pkg

To search the binary package repository for an application:

 # pkg search package_name

or:

 # pkg search -o subversion

If the Ports Collection is already installed, there are several methods to query the local version of the ports tree. To find out which category a port is in, type whereis file, where file is the program to be installed:

 # whereis lsof
 lsof: /usr/ports/sysutils/lsof

Obtaining Information About Installed Packages. For example, to see which version of pkg is installed, run:

 # pkg info pkg
 pkg-1.1.4_1
 Repeat the pkg search with -o to list the origin of each package:

To install, remove, and upgrade a apckage, here as example installing curl:

 # pkg install curl
 # pkg delete curl
 # pkg upgrade curl

Auditing Installed Packages, software vulnerabilities are regularly discovered in third-party applications. To address this, pkg includes a built-in auditing mechanism. To determine if there are any known vulnerabilities for the software installed on the system, run:

 # pkg audit -F

Automatically Removing Leaf Dependencies, removing a package may leave behind dependencies which are no longer required. Unneeded packages that were installed as dependencies can be automatically detected and removed using:

 # pkg autoremove

Removing Stale Packages, by default, pkg stores binary packages in a cache directory defined by PKG_CACHEDIR in pkg.conf(5). Only copies of the latest installed packages are kept. Older versions of pkg kept all previous packages. To remove these outdated binary packages, run:

 # pkg clean

The entire cache may be cleared by running:

 # pkg clean -a

Installing and maintain ports

To download a compressed snapshot of the Ports Collection into /var/db/portsnap:

 # portsnap fetch

When running Portsnap for the first time, extract the snapshot into /usr/ports:

 # protsnap extract

After the first use of Portsnap has been completed as shown above, /usr/ports can be updated as needed by running:

 # protsnap fetch update

To search in ports three:

 # cd /usr/ports
 # make search name=lsof

To receive less information, use the quicksearch feature:

 # cd /usr/ports
 # make quicksearch name=lsof

For more in-depth searching, use make search key=string or make quicksearch key=string, where string is some text to search for. The text can be in comments, descriptions, or dependencies in order to find ports which relate to a particular subject when the name of the program is unknown. When using search or quicksearch, the search string is case-insensitive. Searching for “LSOF” will yield the same results as searching for “lsof”.

To install (as example) subversion must be installed before it can be used to check out the ports tree. If a copy of the ports tree is already present, install Subversion like this:

 # cd /usr/ports/devel/subversion
 # make install clean

To deinstall a port:

 # cd /usr/ports/devel/subversion
 # make deinstall clean

Install Nvidia card driver and xorg

We need to instal de nvidia driver and xorg, here I found a solution that works for me.

 # cd /usr/ports/x11/nvidia-driver   ## latest dirver or nvidi-driver-xxx
 # make install clean                ## take a cofee
 # sysrc kld_list+="nvidia-modeset"  ## to add an entry to /etc/rc.conf to load the kernel modules at boot. sysrc(8) is a nice utility that safely edits /etc/rc.conf for you.
 # kldload nvidia-modeset            ## load the required kernel modules now.
 # cd /usr/ports/x11/nvidia-xconfig  ## cmd tools
 # make install clean
 # cd /usr/ports/x11/nvidia-setings  ## gui tools
 # make install clean

Create the /usr/local/etc/X11/xorg.conf.d directory:

 # mkdir -p /usr/local/etc/X11/xorg.conf.d

Use your favourite editor to create /usr/local/etc/X11/xorg.conf.d/driver-nvidia.conf with the following contents:

 Section "Device"
       Identifier "NVIDIA Card"
       VendorName "NVIDIA Corporation"
       Driver "nvidia"
 EndSection

Now we will install xorg: To build and install from the Ports Collection:

 # cd /usr/ports/x11/xorg
 # make install clean

We need to add our user to group video and wheel: (if there is no video then just add the user to wheel)

 # pw groupmod video -m slurms || pw groupmod wheel -m slurms

After this you can reboot your machine and after the reboot you can try if xorg is woring with the command:

 $ startx

Installing sndio

If your coming from the Linux world, you want surly try to install ALSA or Pulseaudio, FreeBSD ship with another sound system that you maybe wanna give a try (of course you cm still install ALSA or Pulse if you want):


Like sais it ship so you do not really need to install it, you just need to create or change /etc/make.conf and add:

 OPTIONS_SET=SNDIO # ... and what you might already have
 OPTIONS_SET+=PORTAUDIO # Portaudio supports sndio, so more software supports sndio (gqrx is an example)
 OPTIONS_UNSET=  PULSEAUDIO PULSE ALSA # ... and what you might already have

Then enable the sndio module in /etc/rc.conf:

 sndiod_enable=YES 

and start the service

 service sndiod start

Then you can install the application audio/aucatctl port (or package):

 # pkg install aucatctl

Installing a windows manager and XDM

Now we need to install a window manager, for me it will be bspwm, you can of course choose yous (KDE, Gnome, Xfce, and so one). I will install a XDM manager, I will pick up the easiest one, slim. To begin type (Here is the how to I followed and works):

 # pkg install bspwm i3lock rofi slim slim-themes

After installing bspwm, you will want to make it the default window manager when you run startx. To do that, create the .xinitrc file in the user's home directory with the line /usr/local/bin/i3:

 $ echo "sxhkd &" >> /usr/home/username/.xinitrc
 $ echo "env bspwm" >> /usr/home/username/.xinitrc

Then, you need to edit your /etc/rc.conf file to include the following lines:

 vboxguest_enable="YES"     # Only if VM. 
 vboxservice_enable="YES"   # Only if VM.
 hald_enable="YES"
 dbus_enable="YES"
 slim_enable="YES"

Do not forget to copy the files for the standard configuration of bspwm:

First we will make a directory to copy the base configuration files for bspwm and sxhkd.

To make the directory:

 $ mkdir /home/(your user name here)/.config/bspwm

To copy the files:

 $ mv /bspwm/examples/bspwmrc /home/(your username here)/.config/bspwm/bspwmrc
 $ chmod +x /home/(your user name here)/.config/bspwm/bspwmrc

Do the same with sxhkd:

 $ mkdir /home/(your user name here)/.config/sxhkd
 $ mv /sxhkd/examples/sxhkdrc /home/(your username here)/.config/sxhkd/sxhkdrc
 $ chmod +x /home/(your user name)/.config/sxhkd/sxhkdrc

Installing fuse-ext2

Crap, I need to read (and more important write) some HDD but they using old filesystems like ext4,... It seems never FreeBSD got support for this kind of filesystem, instead they use USF and ZSF (or Hammer and Hammer2 with DragonFly BSD), but I got luck, I found a thread on the forum with a working solution, see here:

 # pkg install fuse-ext2
 # kldload fuse
 # fuse-ext2 /dev/ada1s1 /mnt/hdd1 -o rw+
 # fuse-ext2 /dev/ada2s1 /mnt/hdd2 -o rw+

Edit and add /etc/rc.conf:

 fuse_enable="YES"

In this example I mount all my HDD to one subdirectories of /mnt. My disk are ada1s1 and ada2s1, the s1 part is like in Linux a partition and ada the type of the HDD (SATA disks)

Installing doas

Did you heard before about does? No, well you surly know everything about sudo, if you prefer to use sudo type:

 # pkg install sudo

After installing sudo you will need to make some change in the sudo file with:

 # visudo   ## use this command because he will make a spell cheking of the file (so if you make any mistakes he will warn you).

Or instead use doas type:

 # pkg install doas

Then create a file /usr/local/etc/doas.conf and add (for more example see man doas):

 permit setenv { -ENV PS1=$DOAS_PS1 SSH_AUTH_SOCK } :wheel
 permit nopass keepenv root as root

Installing MPV and mp3 plugins

To see movies or play music I love to use mpv, I got another player (maybe would I use it later) but for now I stick to use mpv:

You need to type:

 # pkg install mpv mpg123 x264 gstreamer1-plugins-lame 

Now you can see movies with codec x264 or play music with this command:

 $ mpv --shuffle /path/to/your/music/*