FreeBSD List Enabled Services
You can list all enabled services on your FreeBSD box with service -e
root@freebitch:~ # service -e /etc/rc.d/hostid /etc/rc.d/hostid_save /etc/rc.d/cleanvar /etc/rc.d/kldxref /etc/rc.d/devmatch /etc/rc.d/ip6addrctl /etc/rc.d/netif /etc/rc.d/devd /etc/rc.d/pflog /etc/rc.d/pf /etc/rc.d/resolv /etc/rc.d/newsyslog /etc/rc.d/syslogd /etc/rc.d/savecore /etc/rc.d/dmesg /etc/rc.d/virecover /etc/rc.d/motd /etc/rc.d/ntpd /etc/rc.d/rctl /usr/local/etc/rc.d/php-fpm /usr/local/etc/rc.d/nginx /usr/local/etc/rc.d/mysql-server /etc/rc.d/sshd /etc/rc.d/sendmail /etc/rc.d/cron /etc/rc.d/mixer /etc/rc.d/gptboot /etc/rc.d/bgfsck
Error adding new user – pw:user “kuku” disappeared during update
Password database is out of sync. Run below command:
pwd_mkdb -p /etc/master.passwd
FreeBSD pkg upgrade txz not found error
pkg update -f
To make sure local copy of the package catalogue is in sync with repos
Freebsd – Find which package provides certain files
Default Freebsd pkg tool doesn’t have “provides” option like the one in Red Hats yum package manager
yum provides idn2.h
But thanks to Rodrigo Osorio, you can install “pkg-provides” plugin which adds provides option to pkg tool.
root@bsd12:~ # pkg install pkg-provides
All instructions are at the end of install process. Basically you have to add 3 lines to pkg.conf and run update provides database:
root@bsd12:~ # pkg plugins NAME DESC VERSION provides A plugin for querying which package provides a particular file 0.7.1 root@bsd12:~ # pkg provides idn2.h Provides database not found, please update first. root@bsd12:~ # pkg provides -u Fetching provides database: 100% 15 MiB 4.0MB/s 00:04 Extracting database....succes root@bsd12:~ # pkg provides idn2.h Name : libidn2-2.3.0_1 Desc : Implementation of IDNA2008 internationalized domain names Repo : FreeBSD Filename: usr/local/share/gtk-doc/html/libidn2/libidn2.html usr/local/share/gtk-doc/html/libidn2/libidn2-idn2.html usr/local/include/idn2.h
Setup and full usage here:
FreeBSD ZFS and Jails configuration with iocage – Part 1
Iocage requires zfs filesystem. We are going to have 1 network interface on the host system and create cloned loopback interface with different private ip block to use with jails.
Create cloned loopback interface and private network for jails: Jails attached to this loopback interface are unable to access traffic destined for another jail despite sharing an interface. In this design jails are restricted with allow.raw_sockets=0, disallowing any packet sniffing or similar behavior. This restrictions also disallows the use of ping inside the container.
Edit /etc/rc.conf and add below:
cloned_interfaces="lo1" pf_enable="YES" pf_rules="/usr/local/etc/pf.conf" pflog_enable="YES" pflog_logfile="/var/log/pflog"
Edit /usr/local/etc/pf.conf and add below pf rules for nat so jails can access outside. Also we will forward incoming connections on em0 interface port 8080 to jail with ip address 10.0.0.2 port 80:
IP_PUB="192.168.1.10" IP_JAIL="10.0.0.2" NET_JAIL="10.0.0.0/24" PORT_JAIL="8080" #........ # additional rules not shown in this blog #........ nat pass on em0 from $NET_JAIL to any -> $IP_PUB rdr pass on em0 proto tcp from any to $IP_PUB port $PORT_JAIL -> $IP_JAIL 80
Enable pf:
sysrc pf_enable=”YES”
Restart the server
root@bsdzfs:~ # shutdown -r now
Install iocage
root@bsdzfs:~ # pkg install py38-iocage-1.2_8
To view default parameters for jails you can use “iocage get -a default”
We add the -a flag to get all parameters and add the jail name default to see defaults:
root@bsdzfs:~ # iocage get -a default CONFIG_VERSION:27 allow_chflags:0 allow_mlock:0 allow_mount:0 allow_mount_devfs:0 allow_mount_fusefs:0 allow_mount_nullfs:0 allow_mount_procfs:0 allow_mount_tmpfs:0 allow_mount_zfs:0 allow_quotas:0 allow_raw_sockets:0 allow_set_hostname:1 allow_socket_af:0 allow_sysvipc:0 allow_tun:0 allow_vmm:0 assign_localhost:0 available:readonly basejail:0 boot:0 bpf:0 children_max:0 comment:none compression:lz4 compressratio:readonly coredumpsize:off count:1 cpuset:off cputime:off datasize:off dedup:off defaultrouter:auto defaultrouter6:auto depends:none devfs_ruleset:4 dhcp:0 enforce_statfs:2 exec_clean:1 exec_created:/usr/bin/true exec_fib:0 exec_jail_user:root exec_poststart:/usr/bin/true exec_poststop:/usr/bin/true exec_prestart:/usr/bin/true exec_prestop:/usr/bin/true exec_start:/bin/sh /etc/rc exec_stop:/bin/sh /etc/rc.shutdown exec_system_jail_user:0 exec_system_user:root exec_timeout:60 host_domainname:none host_time:1 hostid:8b1c7bda-6e71-274d-8451-cf2078e9eff0 hostid_strict_check:0 interfaces:vnet0:bridge0 ip4:new ip4_addr:none ip4_saddrsel:1 ip6:new ip6_addr:none ip6_saddrsel:1 ip_hostname:0 jail_zfs:0 jail_zfs_mountpoint:none last_started:none localhost_ip:none login_flags:-f root mac_prefix:080027 maxproc:off memorylocked:off memoryuse:off min_dyn_devfs_ruleset:1000 mount_devfs:1 mount_fdescfs:1 mount_linprocfs:0 mount_procfs:0 mountpoint:readonly msgqqueued:off msgqsize:off nat:0 nat_backend:ipfw nat_forwards:none nat_interface:none nat_prefix:172.16 nmsgq:off notes:none nsem:off nsemop:off nshm:off nthr:off openfiles:off origin:readonly owner:root pcpu:off plugin_name:none plugin_repository:none priority:99 pseudoterminals:off quota:none readbps:off readiops:off reservation:none resolver:/etc/resolv.conf rlimits:off rtsold:0 securelevel:2 shmsize:off stacksize:off stop_timeout:30 swapuse:off sync_state:none sync_target:none sync_tgt_zpool:none sysvmsg:new sysvsem:new sysvshm:new template:0 type:jail used:readonly vmemoryuse:off vnet:0 vnet0_mac:none vnet1_mac:none vnet2_mac:none vnet3_mac:none vnet_default_interface:auto vnet_interfaces:none wallclock:off writebps:off writeiops:off
If you get below warning when you first run iocage command, just folow the instructions:
******************************************************************************** fdescfs(5) is not mounted, performance may suffer. Please run: mount -t fdescfs null /dev/fd You can also permanently mount it in /etc/fstab with the following entry: fdescfs /dev/fd fdescfs rw 0 0 ********************************************************************************
To fetch all available releases use “iocage fetch”.
root@bsdzfs:~ # iocage fetch [0] 11.2-RELEASE [1] 11.3-RELEASE [2] 11.4-RELEASE [3] 12.0-RELEASE [4] 12.1-RELEASE [5] 12.2-RELEASE [6] 13.0-RELEASE Type the number of the desired RELEASE Press [Enter] to fetch the default selection: (12.2)
This will list all available releases which can be used for jails. Ask for selection then download and apply all patches. So if you select [5] 12.2-RELEASE will be downloaded and patches will be applied leaving you with 12.2-RELEASE-p9 (as of today)
If you dont want to apply patches you can add –noupdate option
root@bsdzfs:~ # iocage fetch --noupdate
You can also download a release by:
root@bsdzfs:~ # iocage fetch -r 12.2-RELEASE --noupdate
To destroy a downloaded release, and delete all downloaded files:
root@bsdzfs:~ # iocage destroy -r 12.2-RELEASE root@bsdzfs:~ # zfs destroy -v zroot/iocage/download/12.2-RELEASE
Create a jail, install packages and use it as a template for future jails:
Note: iocage uses default /etc/resolv.conf for jails. If you want you can create custom resolv.conf and set as default for jails
root@bsdzfs:~ # iocage set resolver=/etc/resolv.conf.jail default
How to create jail?
Now lets create our first jail, add some reminder notes and give it a ip address:
root@bsdzfs:~ # iocage create -r 12.2-RELEASE -n nginxtemplate nginxtemplate successfully created! root@bsdzfs:~ # iocage set notes="customized php74,nginx,mariadb105 jail" nginxtemplate notes: none -> customized php74,nginx,mariadb105 jail root@bsdzfs:~ # iocage get notes nginxtemplate customized php74,nginx,mariadb105 jail root@bsdzfs:~ # iocage set ip4_addr="lo1|10.0.0.1" nginxtemplate ip4_addr: none -> lo1|10.0.0.1
After we create the jail, we can start it and install some packages:
Start the jail:
root@bsdzfs2:~ # iocage start nginxtemplate * Starting nginxtemplate + Started OK + Using devfs_ruleset: 1003 (iocage generated default) + Using IP options: ip4.addr=lo1|10.0.0.1 ip4.saddrsel=1 ip4=new ip6.saddrsel=1 ip6=new + Starting services OK + Executing poststart OK
Install packages to jail “nginxtemplate” with iocage:
root@bsdzfs2:~ # iocage pkg nginxtemplate install vim-console mc Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 26 package(s) will be affected (of 0 checked): y New packages to be INSTALLED: diffutils: 3.7 gettext-runtime: 0.21 glib: 2.66.8,2 indexinfo: 0.3.1 libX11: 1.7.2,1 libXau: 1.0.9 libXdmcp: 1.1.3 libXext: 1.3.4,1 libffi: 3.3_1 libiconv: 1.16 libpthread-stubs: 0.4 libsigsegv: 2.12 libslang2: 2.3.2_2 libssh2: 1.9.0_3,3 libxcb: 1.14_1 libxml2: 2.9.12 mc: 4.8.26_2 mpdecimal: 2.5.1 pcre: 8.44 perl5: 5.32.1_1 png: 1.6.37_1 python38: 3.8.10 readline: 8.1.1 vim-console: 8.2.3081 xorgproto: 2021.4 zip: 3.0_1 Number of packages to be installed: 26 The process will require 274 MiB more space. 51 MiB to be downloaded. Proceed with this action? [y/N]: [nginxtemplate] [1/26] Fetching vim-console-8.2.3081.txz: .......... done [nginxtemplate] [2/26] Fetching mc-4.8.26_2.txz: .......... done [nginxtemplate] [3/26] Fetching libXext-1.3.4,1.txz: .......... done [nginxtemplate] [4/26] Fetching libXau-1.0.9.txz: .. done [nginxtemplate] [5/26] Fetching libX11-1.7.2,1.txz: .......... done [nginxtemplate] [6/26] Fetching libxcb-1.14_1.txz: .......... done [nginxtemplate] [7/26] Fetching libXdmcp-1.1.3.txz: .. done [nginxtemplate] [8/26] Fetching xorgproto-2021.4.txz: .......... done [nginxtemplate] [9/26] Fetching libpthread-stubs-0.4.txz: . done [nginxtemplate] [10/26] Fetching diffutils-3.7.txz: .......... done [nginxtemplate] [11/26] Fetching indexinfo-0.3.1.txz: . done [nginxtemplate] [12/26] Fetching libsigsegv-2.12.txz: ... done [nginxtemplate] [13/26] Fetching gettext-runtime-0.21.txz: .......... done [nginxtemplate] [14/26] Fetching libssh2-1.9.0_3,3.txz: .......... done [nginxtemplate] [15/26] Fetching python38-3.8.10.txz: .......... done [nginxtemplate] [16/26] Fetching mpdecimal-2.5.1.txz: .......... done [nginxtemplate] [17/26] Fetching readline-8.1.1.txz: .......... done [nginxtemplate] [18/26] Fetching libffi-3.3_1.txz: ..... done [nginxtemplate] [19/26] Fetching perl5-5.32.1_1.txz: .......... done [nginxtemplate] [20/26] Fetching libslang2-2.3.2_2.txz: .......... done [nginxtemplate] [21/26] Fetching png-1.6.37_1.txz: .......... done [nginxtemplate] [22/26] Fetching pcre-8.44.txz: .......... done [nginxtemplate] [23/26] Fetching glib-2.66.8,2.txz: .......... done [nginxtemplate] [24/26] Fetching libxml2-2.9.12.txz: .......... done [nginxtemplate] [25/26] Fetching libiconv-1.16.txz: .......... done [nginxtemplate] [26/26] Fetching zip-3.0_1.txz: .......... done Checking integrity... done (0 conflicting) [nginxtemplate] [1/26] Installing xorgproto-2021.4... [nginxtemplate] [1/26] Extracting xorgproto-2021.4: .......... done [nginxtemplate] [2/26] Installing libXau-1.0.9... [nginxtemplate] [2/26] Extracting libXau-1.0.9: .......... done [nginxtemplate] [3/26] Installing libXdmcp-1.1.3... [nginxtemplate] [3/26] Extracting libXdmcp-1.1.3: ......... done [nginxtemplate] [4/26] Installing libpthread-stubs-0.4... [nginxtemplate] [4/26] Extracting libpthread-stubs-0.4: .... done [nginxtemplate] [5/26] Installing indexinfo-0.3.1... [nginxtemplate] [5/26] Extracting indexinfo-0.3.1: .... done [nginxtemplate] [6/26] Installing libxcb-1.14_1... [nginxtemplate] [6/26] Extracting libxcb-1.14_1: .......... done [nginxtemplate] [7/26] Installing gettext-runtime-0.21... [nginxtemplate] [7/26] Extracting gettext-runtime-0.21: .......... done [nginxtemplate] [8/26] Installing mpdecimal-2.5.1... [nginxtemplate] [8/26] Extracting mpdecimal-2.5.1: .......... done [nginxtemplate] [9/26] Installing readline-8.1.1... [nginxtemplate] [9/26] Extracting readline-8.1.1: .......... done [nginxtemplate] [10/26] Installing libffi-3.3_1... [nginxtemplate] [10/26] Extracting libffi-3.3_1: .......... done [nginxtemplate] [11/26] Installing libX11-1.7.2,1... [nginxtemplate] [11/26] Extracting libX11-1.7.2,1: .......... done [nginxtemplate] [12/26] Installing libsigsegv-2.12... [nginxtemplate] [12/26] Extracting libsigsegv-2.12: ........ done [nginxtemplate] [13/26] Installing python38-3.8.10... [nginxtemplate] [13/26] Extracting python38-3.8.10: .......... done [nginxtemplate] [14/26] Installing png-1.6.37_1... [nginxtemplate] [14/26] Extracting png-1.6.37_1: .......... done [nginxtemplate] [15/26] Installing pcre-8.44... [nginxtemplate] [15/26] Extracting pcre-8.44: .......... done [nginxtemplate] [16/26] Installing libxml2-2.9.12... [nginxtemplate] [16/26] Extracting libxml2-2.9.12: .......... done [nginxtemplate] [17/26] Installing libiconv-1.16... [nginxtemplate] [17/26] Extracting libiconv-1.16: .......... done [nginxtemplate] [18/26] Installing libXext-1.3.4,1... [nginxtemplate] [18/26] Extracting libXext-1.3.4,1: .......... done [nginxtemplate] [19/26] Installing diffutils-3.7... [nginxtemplate] [19/26] Extracting diffutils-3.7: .......... done [nginxtemplate] [20/26] Installing libssh2-1.9.0_3,3... [nginxtemplate] [20/26] Extracting libssh2-1.9.0_3,3: .......... done [nginxtemplate] [21/26] Installing perl5-5.32.1_1... [nginxtemplate] [21/26] Extracting perl5-5.32.1_1: .......... done [nginxtemplate] [22/26] Installing libslang2-2.3.2_2... [nginxtemplate] [22/26] Extracting libslang2-2.3.2_2: .......... done [nginxtemplate] [23/26] Installing glib-2.66.8,2... [nginxtemplate] [23/26] Extracting glib-2.66.8,2: .......... done No schema files found: doing nothing. [nginxtemplate] [24/26] Installing zip-3.0_1... [nginxtemplate] [24/26] Extracting zip-3.0_1: .......... done [nginxtemplate] [25/26] Installing vim-console-8.2.3081... [nginxtemplate] [25/26] Extracting vim-console-8.2.3081: .......... done [nginxtemplate] [26/26] Installing mc-4.8.26_2... [nginxtemplate] [26/26] Extracting mc-4.8.26_2: .......... done ===== Message from libsigsegv-2.12: -- Note that the stackoverflow handling functions of this library need procfs mounted on /proc. ===== Message from python38-3.8.10: -- Note that some standard Python modules are provided as separate ports as they require additional dependencies. They are available as: py38-gdbm databases/py-gdbm@py38 py38-sqlite3 databases/py-sqlite3@py38 py38-tkinter x11-toolkits/py-tkinter@py38 ===== Message from mc-4.8.26_2: -- Midnight Commander was built with subshell support, which works with most popular shells, e.g. bash(1), dash(1), tcsh(1), zsh(1), but not sh(1) due to its lack of "precmd" or equivalent hooks which mc(1) needs to read the subshell's current directory. $ env SHELL=/bin/sh mc common.c: unimplemented subshell type 1 read (subshell_pty...): No such file or directory (2) Please either use more advanced interactive shell, or start mc(1) with -u (--nosubshell) switch if you're confined to /bin/sh for some reason. Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 26 package(s) will be affected (of 0 checked): New packages to be INSTALLED: diffutils: 3.7 gettext-runtime: 0.21 glib: 2.66.8,2 indexinfo: 0.3.1 libX11: 1.7.2,1 libXau: 1.0.9 libXdmcp: 1.1.3 libXext: 1.3.4,1 libffi: 3.3_1 libiconv: 1.16 libpthread-stubs: 0.4 libsigsegv: 2.12 libslang2: 2.3.2_2 libssh2: 1.9.0_3,3 libxcb: 1.14_1 libxml2: 2.9.12 mc: 4.8.26_2 mpdecimal: 2.5.1 pcre: 8.44 perl5: 5.32.1_1 png: 1.6.37_1 python38: 3.8.10 readline: 8.1.1 vim-console: 8.2.3081 xorgproto: 2021.4 zip: 3.0_1 Number of packages to be installed: 26 The process will require 274 MiB more space. 51 MiB to be downloaded. Proceed with this action? [y/N]: [nginxtemplate] [1/26] Fetching vim-console-8.2.3081.txz: .......... done [nginxtemplate] [2/26] Fetching mc-4.8.26_2.txz: .......... done [nginxtemplate] [3/26] Fetching libXext-1.3.4,1.txz: .......... done [nginxtemplate] [4/26] Fetching libXau-1.0.9.txz: .. done [nginxtemplate] [5/26] Fetching libX11-1.7.2,1.txz: .......... done [nginxtemplate] [6/26] Fetching libxcb-1.14_1.txz: .......... done [nginxtemplate] [7/26] Fetching libXdmcp-1.1.3.txz: .. done [nginxtemplate] [8/26] Fetching xorgproto-2021.4.txz: .......... done [nginxtemplate] [9/26] Fetching libpthread-stubs-0.4.txz: . done [nginxtemplate] [10/26] Fetching diffutils-3.7.txz: .......... done [nginxtemplate] [11/26] Fetching indexinfo-0.3.1.txz: . done [nginxtemplate] [12/26] Fetching libsigsegv-2.12.txz: ... done [nginxtemplate] [13/26] Fetching gettext-runtime-0.21.txz: .......... done [nginxtemplate] [14/26] Fetching libssh2-1.9.0_3,3.txz: .......... done [nginxtemplate] [15/26] Fetching python38-3.8.10.txz: .......... done [nginxtemplate] [16/26] Fetching mpdecimal-2.5.1.txz: .......... done [nginxtemplate] [17/26] Fetching readline-8.1.1.txz: .......... done [nginxtemplate] [18/26] Fetching libffi-3.3_1.txz: ..... done [nginxtemplate] [19/26] Fetching perl5-5.32.1_1.txz: .......... done [nginxtemplate] [20/26] Fetching libslang2-2.3.2_2.txz: .......... done [nginxtemplate] [21/26] Fetching png-1.6.37_1.txz: .......... done [nginxtemplate] [22/26] Fetching pcre-8.44.txz: .......... done [nginxtemplate] [23/26] Fetching glib-2.66.8,2.txz: .......... done [nginxtemplate] [24/26] Fetching libxml2-2.9.12.txz: .......... done [nginxtemplate] [25/26] Fetching libiconv-1.16.txz: .......... done [nginxtemplate] [26/26] Fetching zip-3.0_1.txz: .......... done Checking integrity... done (0 conflicting) [nginxtemplate] [1/26] Installing xorgproto-2021.4... [nginxtemplate] [1/26] Extracting xorgproto-2021.4: .......... done [nginxtemplate] [2/26] Installing libXau-1.0.9... [nginxtemplate] [2/26] Extracting libXau-1.0.9: .......... done [nginxtemplate] [3/26] Installing libXdmcp-1.1.3... [nginxtemplate] [3/26] Extracting libXdmcp-1.1.3: ......... done [nginxtemplate] [4/26] Installing libpthread-stubs-0.4... [nginxtemplate] [4/26] Extracting libpthread-stubs-0.4: .... done [nginxtemplate] [5/26] Installing indexinfo-0.3.1... [nginxtemplate] [5/26] Extracting indexinfo-0.3.1: .... done [nginxtemplate] [6/26] Installing libxcb-1.14_1... [nginxtemplate] [6/26] Extracting libxcb-1.14_1: .......... done [nginxtemplate] [7/26] Installing gettext-runtime-0.21... [nginxtemplate] [7/26] Extracting gettext-runtime-0.21: .......... done [nginxtemplate] [8/26] Installing mpdecimal-2.5.1... [nginxtemplate] [8/26] Extracting mpdecimal-2.5.1: .......... done [nginxtemplate] [9/26] Installing readline-8.1.1... [nginxtemplate] [9/26] Extracting readline-8.1.1: .......... done [nginxtemplate] [10/26] Installing libffi-3.3_1... [nginxtemplate] [10/26] Extracting libffi-3.3_1: .......... done [nginxtemplate] [11/26] Installing libX11-1.7.2,1... [nginxtemplate] [11/26] Extracting libX11-1.7.2,1: .......... done [nginxtemplate] [12/26] Installing libsigsegv-2.12... [nginxtemplate] [12/26] Extracting libsigsegv-2.12: ........ done [nginxtemplate] [13/26] Installing python38-3.8.10... [nginxtemplate] [13/26] Extracting python38-3.8.10: .......... done [nginxtemplate] [14/26] Installing png-1.6.37_1... [nginxtemplate] [14/26] Extracting png-1.6.37_1: .......... done [nginxtemplate] [15/26] Installing pcre-8.44... [nginxtemplate] [15/26] Extracting pcre-8.44: .......... done [nginxtemplate] [16/26] Installing libxml2-2.9.12... [nginxtemplate] [16/26] Extracting libxml2-2.9.12: .......... done [nginxtemplate] [17/26] Installing libiconv-1.16... [nginxtemplate] [17/26] Extracting libiconv-1.16: .......... done [nginxtemplate] [18/26] Installing libXext-1.3.4,1... [nginxtemplate] [18/26] Extracting libXext-1.3.4,1: .......... done [nginxtemplate] [19/26] Installing diffutils-3.7... [nginxtemplate] [19/26] Extracting diffutils-3.7: .......... done [nginxtemplate] [20/26] Installing libssh2-1.9.0_3,3... [nginxtemplate] [20/26] Extracting libssh2-1.9.0_3,3: .......... done [nginxtemplate] [21/26] Installing perl5-5.32.1_1... [nginxtemplate] [21/26] Extracting perl5-5.32.1_1: .......... done [nginxtemplate] [22/26] Installing libslang2-2.3.2_2... [nginxtemplate] [22/26] Extracting libslang2-2.3.2_2: .......... done [nginxtemplate] [23/26] Installing glib-2.66.8,2... [nginxtemplate] [23/26] Extracting glib-2.66.8,2: .......... done No schema files found: doing nothing. [nginxtemplate] [24/26] Installing zip-3.0_1... [nginxtemplate] [24/26] Extracting zip-3.0_1: .......... done [nginxtemplate] [25/26] Installing vim-console-8.2.3081... [nginxtemplate] [25/26] Extracting vim-console-8.2.3081: .......... done [nginxtemplate] [26/26] Installing mc-4.8.26_2... [nginxtemplate] [26/26] Extracting mc-4.8.26_2: .......... done ===== Message from libsigsegv-2.12: -- Note that the stackoverflow handling functions of this library need procfs mounted on /proc. ===== Message from python38-3.8.10: -- Note that some standard Python modules are provided as separate ports as they require additional dependencies. They are available as: py38-gdbm databases/py-gdbm@py38 py38-sqlite3 databases/py-sqlite3@py38 py38-tkinter x11-toolkits/py-tkinter@py38 ===== Message from mc-4.8.26_2: -- Midnight Commander was built with subshell support, which works with most popular shells, e.g. bash(1), dash(1), tcsh(1), zsh(1), but not sh(1) due to its lack of "precmd" or equivalent hooks which mc(1) needs to read the subshell's current directory. $ env SHELL=/bin/sh mc common.c: unimplemented subshell type 1 read (subshell_pty...): No such file or directory (2) Please either use more advanced interactive shell, or start mc(1) with -u (--nosubshell) switch if you're confined to /bin/sh for some reason
You can login to jail with “iocage console jailname” command:
root@bsdzfs2:~ # iocage console nginxtemplate FreeBSD 12.2-RELEASE r366954 GENERIC Welcome to FreeBSD! Release Notes, Errata: https://www.FreeBSD.org/releases/ Security Advisories: https://www.FreeBSD.org/security/ FreeBSD Handbook: https://www.FreeBSD.org/handbook/ FreeBSD FAQ: https://www.FreeBSD.org/faq/ Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/ FreeBSD Forums: https://forums.FreeBSD.org/ Documents installed with the system are in the /usr/local/share/doc/freebsd/ directory, or can be installed later with: pkg install en-freebsd-doc For other languages, replace "en" with a language code like de or fr. Show the version of FreeBSD installed: freebsd-version ; uname -a Please include that output and any error messages when posting questions. Introduction to manual pages: man man FreeBSD directory layout: man hier Edit /etc/motd to change this login announcement. root@nginxtemplate:~ # ps -x PID TT STAT TIME COMMAND 5562 - SsJ 0:00.00 /usr/sbin/syslogd -c -ss 5622 - IsJ 0:00.00 /usr/sbin/cron -J 15 -s 5722 0 IJ 0:00.01 login [pam] (login) 5723 0 SJ 0:00.01 -csh (csh) 5726 0 R+J 0:00.00 ps -ax
You can also install packages to jail from jail console:
root@nginxtemplate:~ # pkg install wget Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 3 package(s) will be affected (of 0 checked): New packages to be INSTALLED: libidn2: 2.3.1 libunistring: 0.9.10_1 wget: 1.21 Number of packages to be installed: 3 The process will require 7 MiB more space. 1 MiB to be downloaded. Proceed with this action? [y/N]: y [nginxtemplate] [1/3] Fetching wget-1.21.txz: 100% 673 KiB 689.6kB/s 00:01 [nginxtemplate] [2/3] Fetching libidn2-2.3.1.txz: 100% 111 KiB 113.4kB/s 00:01 [nginxtemplate] [3/3] Fetching libunistring-0.9.10_1.txz: 100% 522 KiB 534.2kB/s 00:01 Checking integrity... done (0 conflicting) [nginxtemplate] [1/3] Installing libunistring-0.9.10_1... [nginxtemplate] [1/3] Extracting libunistring-0.9.10_1: 100% [nginxtemplate] [2/3] Installing libidn2-2.3.1... [nginxtemplate] [2/3] Extracting libidn2-2.3.1: 100% [nginxtemplate] [3/3] Installing wget-1.21... [nginxtemplate] [3/3] Extracting wget-1.21: 100% root@nginxtemplate:~ # exit logout root@bsdzfs2:~ #
You can run a command inside the jail without firing up jail console:
root@bsdzfs2:~ # iocage exec nginxtemplate "ps -ax" PID TT STAT TIME COMMAND 5562 - SsJ 0:00.00 /usr/sbin/syslogd -c -ss 5622 - IsJ 0:00.00 /usr/sbin/cron -J 15 -s 5998 0 R+J 0:00.00 ps -ax
You can view jail configuration with:
root@bsdzfs:~ # iocage get all nginxtemplate
You list all jails with “iocage list”
root@bsdzfs:~ # iocage list +-----+---------------+-------+--------------+----------+ | JID | NAME | STATE | RELEASE | IP4 | +=====+===============+=======+==============+==========+ | 1 | nginxtemplate | up | 12.2-RELEASE | 10.0.0.1 | +-----+---------------+-------+--------------+----------+ root@bsdzfs:~ # iocage list -l +-----+---------------+------+-------+------+-----------------+-----------------+-----+----------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+===============+======+=======+======+=================+=================+=====+==========+==========+ | 1 | nginxtemplate | off | up | jail | 12.2-RELEASE | lo1|10.0.0.1 | - | - | no | +-----+---------------+------+-------+------+-----------------+-----------------+-----+----------+----------+
How to create jail template?
Once we customized our jail we can mark it as template and start creating jails based on this template:
Rename the jail:
root@bsdzfs:~ # iocage rename nginxtemplate T_nginx Jail: nginxtemplate renamed to T_nginx
Set jail as template:
root@bsdzfs:~ # iocage set template=yes T_nginx T_nginx is running. Please stop it first! root@bsdzfs:~ # iocage stop T_nginx * Stopping T_nginx + Executing prestop OK + Stopping services OK + Removing devfs_ruleset: 1000 OK + Removing jail process OK + Executing poststop OK root@bsdzfs:~ # iocage set template=yes T_nginx T_nginx converted to a template.
As you can see from above templates can not be started. Take a look at below example:
root@bsdzfs:~ # iocage start T_nginx Please convert back to a jail before trying to start T_nginx
You can list all available templates in the system with:
root@bsdzfs:~ # iocage list -l -t +-----+---------+------+-------+----------+--------------+-----------------+-----+----------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+=========+======+=======+==========+==============+=================+=====+==========+==========+ | - | T_nginx | off | down | template | 12.2-RELEASE | lo1|10.0.0.1 | - | - | no | +-----+---------+------+-------+----------+--------------+-----------------+-----+----------+----------+
How to create jail from template jail?
Now lets create 2 new jail based on our template:
root@bsdzfs:~ # iocage create -t T_nginx -n www_customer1 www_customer1 successfully created! root@bsdzfs:~ # iocage set ip4_addr="lo1|10.0.0.2" www_customer1 ip4_addr: none -> lo1|10.0.0.2 root@bsdzfs:~ # iocage create -t T_nginx -n www_customer2 www_customer1 successfully created! root@bsdzfs:~ # iocage set ip4_addr="lo1|10.0.0.3" www_customer2 ip4_addr: none -> lo1|10.0.0.3 root@bsdzfs:~ # iocage list +-----+---------------+-------+--------------+-----+ | JID | NAME | STATE | RELEASE | IP4 | +=====+===============+=======+==============+=====+ | - | www_customer1 | down | 12.2-RELEASE | - | | - | www_customer2 | down | 12.2-RELEASE | - | +-----+---------------+-------+--------------+-----+
How to update a jail?
We can update the jail with:
root@bsdzfs:~ # iocage update www_customer1 Snapshot: zroot/iocage/jails/www_customer1@ioc_update_12.2-RELEASE_2021-08-23_12-55-41 created. Updating jail...
Now lets list all jails in the system
root@bsdzfs2:~ # iocage list -l +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+===============+======+=======+======+=================+==============+=====+==========+==========+ | 3 | www_customer1 | off | up | jail | 12.2-RELEASE-p9 | lo1|10.0.0.2 | - | T_nginx | no | +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+ | 2 | www_customer2 | off | up | jail | 12.2-RELEASE | lo1|10.0.0.3 | - | T_nginx | no | +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+
Our template jail was created with noupdate option so template jail is 12.2-RELEASE.
After we update www_customer1 jail its running “12.2-RELEASE-p9” whereas www_customer2 still running “12.2-RELEASE”
How to upgrade a jail?
Lets create a jail based on 11.2-RELEASE:
root@bsdzfs2:~ # iocage create -r 11.2-RELEASE -n bsd112 . . WARNING: FreeBSD 11.2-RELEASE HAS PASSED ITS END-OF-LIFE DATE. Any security issues discovered after Wed Oct 30 20:00:00 EDT 2019 will not have been corrected. Installing updates... done. bsd112 successfully created!
List all jails in the system:
root@bsdzfs2:~ # iocage list -l +-----+---------------+------+-------+------+------------------+--------------+-----+----------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+===============+======+=======+======+==================+==============+=====+==========+==========+ | - | bsd112 | off | down | jail | 11.2-RELEASE-p15 | - | - | - | no | +-----+---------------+------+-------+------+------------------+--------------+-----+----------+----------+ | 8 | www_customer1 | on | up | jail | 12.2-RELEASE-p9 | lo1|10.0.0.2 | - | T_nginx | no | +-----+---------------+------+-------+------+------------------+--------------+-----+----------+----------+ | 2 | www_customer2 | off | up | jail | 12.2-RELEASE | lo1|10.0.0.3 | - | T_nginx | no | +-----+---------------+------+-------+------+------------------+--------------+-----+----------+----------+
Upgrade bsd112 jail:
root@bsdzfs2:~ # iocage upgrade -r 12.2-RELEASE bsd112 . . bsd112 successfully upgraded from 11.2-RELEASE-p15 to 12.2-RELEASE-p9! root@bsdzfs2:~ # iocage list -l +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+===============+======+=======+======+=================+==============+=====+==========+==========+ | - | bsd112 | off | down | jail | 12.2-RELEASE-p9 | - | - | - | no | +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+ | - | www_customer1 | on | down | jail | 12.2-RELEASE-p9 | lo1|10.0.0.2 | - | T_nginx | no | +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+ | - | www_customer2 | off | down | jail | 12.2-RELEASE | lo1|10.0.0.3 | - | T_nginx | no | +-----+---------------+------+-------+------+-----------------+--------------+-----+----------+----------+
Other operations:
You can mark the jail to start on boot with:
root@bsdzfs2:~ # iocage set boot=on www_customer1 boot: 0 -> 1
You can restart specific jail with:
root@bsdzfs2:~ # iocage restart www_customer1 * Stopping www_customer1 + Executing prestop OK + Stopping services OK + Removing devfs_ruleset: 1002 OK + Removing jail process OK + Executing poststop OK * Starting www_customer1 + Started OK + Using devfs_ruleset: 1000 (iocage generated default) + Using IP options: ip4.addr=lo1|10.0.0.2 ip4.saddrsel=1 ip4=new ip6.saddrsel=1 ip6=new + Starting services OK + Executing poststart OK
View jails disk usage:
root@bsdzfs2:~ # iocage df +---------------+-------+------+------+-------+-------+ | NAME | CRT | RES | QTA | USE | AVA | +===============+=======+======+======+=======+=======+ | T_nginx | 1.00x | none | none | 384K | 2.02G | +---------------+-------+------+------+-------+-------+ | bsd112 | 1.60x | none | none | 2.36G | 2.02G | +---------------+-------+------+------+-------+-------+ | www_customer1 | 1.48x | none | none | 355M | 2.02G | +---------------+-------+------+------+-------+-------+ | www_customer2 | 1.05x | none | none | 400K | 2.02G | +---------------+-------+------+------+-------+-------+
You can destroy the jail with:
root@bsdzfs2:~ # iocage destroy www_customer2 This will destroy jail www_customer2 Are you sure? [y/N]: y Destroying www_customer2
How to copy files to jail from host?
You can copy files to jails root directory like any other file operation. First let find out root directory of jail “www_customer1”
root@bsdzfs2:~ # df -h | grep -r www_customer1 zroot/iocage/jails/www_customer1 5.7G 100K 5.7G 0% /zroot/iocage/jails/www_customer1 zroot/iocage/jails/www_customer1/root 7.2G 1.5G 5.7G 21% /zroot/iocage/jails/www_customer1/root devfs 1.0K 1.0K 0B 100% /zroot/iocage/jails/www_customer1/root/dev fdescfs 1.0K 1.0K 0B 100% /zroot/iocage/jails/www_customer1/root/dev/fd
So jails top directory is /zroot/iocage/jails/www_customer1/root/
root@bsdzfs2:~ # ls /zroot/iocage/jails/www_customer1/root/ .cshrc bin etc media proc sbin usr .profile boot lib mnt rescue sys var COPYRIGHT dev libexec net root tmp
Lets create a file under jails root user home from our host machine
root@bsdzfs2:~ # echo "test" > /zroot/iocage/jails/www_customer1/root/root/test.txt
Login to the jail and see if we can access the file within jail
root@bsdzfs2:~ # iocage console www_customer1 Last login: Tue Aug 24 11:51:52 on pts/0 FreeBSD 12.2-RELEASE r366954 GENERIC Welcome to FreeBSD! Release Notes, Errata: https://www.FreeBSD.org/releases/ Security Advisories: https://www.FreeBSD.org/security/ FreeBSD Handbook: https://www.FreeBSD.org/handbook/ FreeBSD FAQ: https://www.FreeBSD.org/faq/ Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/ FreeBSD Forums: https://forums.FreeBSD.org/ Documents installed with the system are in the /usr/local/share/doc/freebsd/ directory, or can be installed later with: pkg install en-freebsd-doc For other languages, replace "en" with a language code like de or fr. Show the version of FreeBSD installed: freebsd-version ; uname -a Please include that output and any error messages when posting questions. Introduction to manual pages: man man FreeBSD directory layout: man hier Edit /etc/motd to change this login announcement. root@www2:~ # pwd /root root@www2:~ # ls .cshrc .history .k5login .login .profile .ssh test.txt root@www2:~ # cat test.txt test
This way you can copy files from host machine to jail
xfce pulseaudio keyboard shortcuts
Open the configuration for your keyboard shortcuts and add the following commands:
pactl — set-sink-volume 0 +10% # raise volume by each 10%
pactl — set-sink-volume 0 -10% # reduce volume by each 10%
pactl — set-sink-mute 0 toggle # mute/unmutes audio
FreeBSD Howto Mix Match Packages and Ports
This document is not for best practices and/or proof of concept
This is a solution for my simple problem: I’m managing FreeBSD server with packages not ports but default package configuration doesn’t meet my needs.
Note: For mariadb there is already a DBD package: p5-DBD-MariaDB but it still requires mysql57-client
Current Scenario :
I use mariadb instead of mysql but FreeBSD 12.1-RELEASE defaults to mysql 5.7 meaning packages are build based on this version of mysql so:
I’ve mariadb 10.4 installed and i need p5-DBD-mysql package for some perl script to run
if i try to install p5-DBD-mysql from packages:
root@bsd12:~ # pkg install p5-DBD-mysql
Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 10 package(s) will be affected (of 0 checked): New packages to be INSTALLED: groff: 1.22.4_3 libevent: 2.1.12 libpaper: 1.1.24.4 mysql57-client: 5.7.31_1 p5-DBD-mysql: 4.050 p5-DBI: 1.643 protobuf: 3.13.0,1 psutils: 1.17_5 uchardet: 0.0.7 Installed packages to be UPGRADED: perl5: 5.30.3 -> 5.32.0 Number of packages to be installed: 9 Number of packages to be upgraded: 1 The process will require 100 MiB more space. 23 MiB to be downloaded. Proceed with this action? [y/N]: y [1/10] Fetching p5-DBD-mysql-4.050.txz: 100% 99 KiB 101.3kB/s 00:01 [2/10] Fetching perl5-5.32.0.txz: 100% 14 MiB 14.9MB/s 00:01 [3/10] Fetching libpaper-1.1.24.4.txz: 100% 24 KiB 24.5kB/s 00:01 [4/10] Fetching p5-DBI-1.643.txz: 100% 705 KiB 721.6kB/s 00:01 [5/10] Fetching mysql57-client-5.7.31_1.txz: 100% 2 MiB 1.9MB/s 00:01 [6/10] Fetching groff-1.22.4_3.txz: 100% 3 MiB 2.9MB/s 00:01 [7/10] Fetching uchardet-0.0.7.txz: 100% 108 KiB 111.0kB/s 00:01 [8/10] Fetching psutils-1.17_5.txz: 100% 57 KiB 58.0kB/s 00:01 [9/10] Fetching protobuf-3.13.0,1.txz: 100% 3 MiB 2.9MB/s 00:01 [10/10] Fetching libevent-2.1.12.txz: 100% 320 KiB 327.6kB/s 00:01 Checking integrity... done (1 conflicting) - mysql57-client-5.7.31_1 conflicts with mariadb104-client-10.4.13_4 on /usr/local/bin/mysql
As you see above it conflicts with my mariadb and continues as below:
Checking integrity... done (0 conflicting) Conflicts with the existing packages have been found. One more solver iteration is needed to resolve them. The following 12 package(s) will be affected (of 0 checked): New packages to be INSTALLED: groff: 1.22.4_3 libevent: 2.1.12 libpaper: 1.1.24.4 mysql57-client: 5.7.31_1 p5-DBD-mysql: 4.050 p5-DBI: 1.643 protobuf: 3.13.0,1 psutils: 1.17_5 uchardet: 0.0.7 Installed packages to be UPGRADED: perl5: 5.30.3 -> 5.32.0 Number of packages to be installed: 9 Number of packages to be upgraded: 1 The process will require 100 MiB more space. Proceed with this action? [y/N]:
Now if i click on “Yes” here pkg will remove my mariadb and install mysql57-client so of course i click on “No”
Solution is change FreeBSD defaults and make it depend on Mariadb104 instead of mysql. For this we need to use ports
About Ports:
There are a lot of flame around mixing pkgs and ports i wont go into that. But in my case its mandatory and pretty harmless because:
I dont use HEAD ports but use Quarterly which is same as pkg version.
Little bit background; pkg uses quarterly updates repo as default on the other hand port users tend to use HEAD branch meaning kind of rolling release.
Port management tools:
Portsnap: uses HEAD branch as default, useless for me
Poudriere: Uses jails, a lot of resources and complicated for single pkg. Helpful if you are going to create batch of packages, have tens or hundreds of FreeBSD servers and want to create your own central repo server.
Synth: Simplified package repository builder, doesn’t require that much resource uses base system as building platform and creates dynamic jails during each build.
I will use svnlite, simple enough for my needs. Basicaly:
1) Change freebsd make defaults to use mariadb instead of mysql
2) Download ports tree
3) create p5-DBD-mysql package from ports
4) install p5-DBD-mysql pkg
5) test
root@bsd12:~ # echo "DEFAULT_VERSIONS= mysql=10.4m" >> /etc/make.conf
Download ports from quarterly repo :
// if you already created ports with another port management tool remove ports directory
root@bsd12:~ # svnlite checkout https://svn.freebsd.org/ports/branches/2020Q4 /usr/ports
it will take a while to download ports ( uses ~1.2GB ) once its done
root@bsd12:~ # cd /usr/ports/
root@bsd12:~ # make fetchindex
root@bsd12:~ # make search name=”p5-DBD-mysql”
Above command is to search for a port in ports tree
root@bsd12:~ # cd databases/p5-DBD-mysql
root@bsd12:~ # make all-depends-list | sort
Now above command shows all dependencies and if you scroll up, you will see now mariadb is listed as dependency instead of mysql
root@bsd12:~ # make package
root@bsd12:~ # pkg add work/pkg/p5-DBD-mysql-4.050.txz
And you are done. You can test installation with below perl script that i copied from cpan site.
Test Script:
#!/usr/local/bin/perl
use strict;
use warnings;
use DBI;
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
"user", "password",
{'RaiseError' => 1});
# Drop table 'foo'. This may fail, if 'foo' doesn't exist
# Thus we put an eval around it.
eval { $dbh->do("DROP TABLE foo") };
print "Dropping foo failed: $@\n" if $@;
# Create a new table 'foo'. This must not fail, thus we don't
# catch errors.
$dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");
# INSERT some data into 'foo'. We are using $dbh->quote() for
# quoting the name.
$dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");
# same thing, but using placeholders (recommended!)
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");
# now retrieve data from the table.
my $sth = $dbh->prepare("SELECT * FROM foo");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
And last step is to lock the pkg so it will not be affected during update process
root@bsd12:~ # pkg lock p5-DBD-mysql p5-DBD-mysql-4.050: lock this package? [y/N]: y Locking p5-DBD-mysql-4.050
Freebsd 12.1-RELEASE Mariadb installation
root@freebitch12:/etc # pkg search mariadb
mariadb-connector-c-3.1.9 MariaDB database connector for C mariadb-connector-odbc-3.1.7_1 MariaDB database connector for odbc mariadb103-client-10.3.23 Multithreaded SQL database (client) mariadb103-server-10.3.23 Multithreaded SQL database (server) mariadb104-client-10.4.13_4 Multithreaded SQL database (client) mariadb104-server-10.4.13_4 Multithreaded SQL database (server) rubygem-azure_mgmt_mariadb-0.17.3 Microsoft Azure Microsoft Azure MariaDB Library for Ruby Client Library for Ruby
root@freebitch12:/etc # pkg install mariadb104-server mariadb104-client
Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 12 package(s) will be affected (of 0 checked): New packages to be INSTALLED: bash: 5.0.17 boost-libs: 1.72.0_2 galera26: 26.4.5 icu: 67.1,1 libedit: 3.1.20191231,1 liblz4: 1.9.2_1,1 mariadb104-client: 10.4.13_4 mariadb104-server: 10.4.13_4 rsync: 3.2.3 unixODBC: 2.3.7 xxhash: 0.7.4 zstd: 1.4.5 Number of packages to be installed: 12 The process will require 483 MiB more space. 60 MiB to be downloaded. Proceed with this action? [y/N]: y .....
root@freebitch12:/etc # vim /etc/rc.conf
mysql_enable="yes" mysql_pidfile="/var/db/mysql/mysql.pid" mysql_optfile="/usr/local/etc/mysql/my.cnf"
root@freebitch12:/etc # service mysql-server start
Installing MariaDB/MySQL system tables in '/var/db/mysql' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mysql The second is mysql@localhost, it has no password either, but you need to be the system 'mysql' user to connect. After connecting you can set the password, if you would need to be able to connect as any of these users with a password and without sudo See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '/usr/local' ; /usr/local/bin/mysqld_safe --datadir='/var/db/mysql' You can test the MariaDB daemon with mysql-test-run.pl cd '/usr/local/mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community:Get InvolvedStarting mysql.
root@freebitch12:/etc # service mysql-server status
mysql is not running.
root@freebitch12:/etc # tail /var/log/mysql/mysqld.err
2020-10-02 19:02:13 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2020-10-02 19:02:13 0 [Note] InnoDB: Waiting for purge to start 2020-10-02 19:02:13 0 [Note] InnoDB: 10.4.13 started; log sequence number 60972; transaction id 21 2020-10-02 19:02:13 0 [Note] InnoDB: Loading buffer pool(s) from /var/db/mysql/ib_buffer_pool 2020-10-02 19:02:13 0 [Note] InnoDB: Buffer pool(s) load completed at 201002 19:02:13 2020-10-02 19:02:13 0 [Note] Plugin 'FEEDBACK' is disabled. 2020-10-02 19:02:13 0 [Note] Server socket created on IP: '127.0.0.1'. 2020-10-02 19:02:13 0 [ERROR] Can't start server : Bind on unix socket: Permission denied 2020-10-02 19:02:13 0 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysql/mysql.sock ? 2020-10-02 19:02:13 0 [ERROR] Aborting
root@freebitch12:/etc # ls -alh /var/run/mysql/
total 8 drwxr-xr-x 2 root wheel 512B Oct 2 19:19 . drwxr-xr-x 7 root wheel 512B Oct 2 19:00 ..
root@freebitch12:/etc # chown mysql:mysql /var/run/mysql/
root@freebitch12:/etc # service mysql-server start
Starting mysql.
root@freebitch12:/etc # service mysql-server status
mysql is running as pid 91966.
root@freebitch12:~ # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Possible Problem
** if you receive below error when you try to run mysql_secure_installation script just restart your server and re-run mysql_secure_installation , you’ll be fine
root@freebitch12:/etc # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
error: Config file /etc/mail/.my.cnf.92133 in invalid location, please move to or merge with /usr/local/etc/mail/.my.cnf.92133
Fatal error in defaults handling. Program aborted
Enter current password for root (enter for none):
Aborting!
Cleaning up...
Freebsd 12.1-RELEASE Sendmail SMTP-Auth Configuration
// Total time 5-10 minutes
// Important: Remove any modifications you make to /etc/mail/freebsd.mc
NOTE: This documents explains how to compile default sendmail to support smtp-auth however; you also have the option to install sendmail pkg from packages collection. This way you don't have to compile sendmail, sendmail version in pkg collection is already compiled with smtp auth enabled!!! When you install sendmail from pkgs collection, system will also install necessary additional pkgs (cyrus-sasl & cyrus-sasl-saslauthd) All you have to do is;
root@freebitch12:/ # pkg install sendmail root@freebitch12:/ # cd /usr/local/etc/mail && cp mailer.conf.sendmail mailer.conf You still need to follow below configurations in order to enable smtp-auth for sendmail; Except you do NOT need to compile sendmail and install cyrus-sasl cyrus-sasl-saslauthd
// check sendmail compiled options
root@freebitch12:/etc/mail # sendmail -d0.1 -bv root
Version 8.15.2 Compiled with: DNSMAP IPV6_FULL LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6 NETUNIX NEWDB NIS PIPELINING SCANF STARTTLS TCPWRAPPERS USERDB XDEBUG Warning: Option: AuthMechanisms requires SASL support (-DSASL) ============ SYSTEM IDENTITY (after readcf) ============ (short domain name) $w = freebitch12 (canonical domain name) $j = freebitch12.localrouter (subdomain name) $m = localrouter (node name) $k = freebitch12 ======================================================== root... deliverable: mailer local, user root
// No SASLv2 support
root@freebitch12:/etc # pkg install cyrus-sasl cyrus-sasl-saslauthd
Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. Checking integrity... done (0 conflicting) The following 2 package(s) will be affected (of 0 checked): New packages to be INSTALLED: cyrus-sasl: 2.1.27_1 cyrus-sasl-saslauthd: 2.1.27_1 Number of packages to be installed: 2 The process will require 8 MiB more space. Proceed with this action? [y/N]: y [1/2] Installing cyrus-sasl-2.1.27_1... *** Updated user `cyrus'. [1/2] Extracting cyrus-sasl-2.1.27_1: 100% [2/2] Installing cyrus-sasl-saslauthd-2.1.27_1... [2/2] Extracting cyrus-sasl-saslauthd-2.1.27_1: 100% .....
// Enable sendmail and saslauthd
root@freebitch12:/etc # vim /etc/rc.conf
sendmail_enable="YES" saslauthd_enable="YES"
// copy freebsd source tree to /usr/src
// required to compile sendmail
root@freebitch12:/etc # svnlite checkout https://svn.freebsd.org/base/releng/12.1/ /usr/src
.... A /usr/src/tools/bus_space/Python/Makefile A /usr/src/tools/bus_space/C/libbus.h A /usr/src/tools/bus_space/bus.c A /usr/src/tools/sched A /usr/src/tools/ifnet A /usr/src/tools/LibraryReport .... A /usr/src/README A /usr/src/Makefile.sys.inc U /usr/src Checked out revision 366374.
// create sendmail make.conf file
root@freebitch12:/etc # vim /etc/make.conf
SENDMAIL_CFLAGS=-I/usr/local/include/sasl -DSASL SENDMAIL_LDADD=/usr/local/lib/libsasl2.so
//compile sendmail with auth support, takes 2-3 minutes
root@freebitch12:/etc # cd /usr/src/lib/libsmutil
root@freebitch12:/usr/src/lib/libsmutil # make cleandir && make obj && make
root@freebitch12:/usr/src/lib/libsmutil # cd /usr/src/lib/libsm
root@freebitch12:/usr/src/lib/libsm # make cleandir && make obj && make
root@freebitch12:/usr/src/lib/libsm # cd /usr/src/usr.sbin/sendmail
root@freebitch12:/usr/src/usr.sbin/sendmail # make cleandir && make obj && make && make install
root@freebitch12:/usr/src/usr.sbin/sendmail # cd /etc/mail
root@freebitch12:/etc/mail # make
// this will create copy of freebsd.mc, freebsd.submit.cf … as hostname.mc, hostname.submit.cf …
// dont make changes to freebsd.mc, make changes to hostname.mc
// in my case freebitch12.mc ……
root@freebitch12:/etc/mail # vim freebitch12.mc
define(`confSMTP_LOGIN_MSG', `freebitch12')dnl define(`confAUTH_OPTIONS', `A p y')dnl TRUST_AUTH_MECH(`LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl
// add any other option you require to hostname.mc
// no need to add DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA’)dnl
// When you enable sendmail in rc.conf it starts listening all interfaces
// Actually if you add this option sendmail wont be able to bind address and would not start
// define(`confAUTH_OPTIONS’, `A p y’)dnl
// this option forces LOGIN/PLAIN SMTP-AUTH after encryption has been established in a TLS tunnel.
// this means you will not see 250-AUTH LOGIN PLAIN if you telnet to port 25
// A is a workaround for broken MTAs that do not implement RFC 2554.
// p option tells sendmail: “don’t permit mechanisms susceptible to simple passive attack (e.g., LOGIN, PLAIN), unless a security layer (think TLS tunnel) is active.”
// you need to use # openssl s_client -connect localhost:25 -starttls smtp to see:
// 250-AUTH LOGIN PLAIN
// y option prohibits anonymous logins
root@freebitch12:/etc/mail # make install
// for each change to mc file you need to run make install like old linux or you can add make install to sendmail start script
// check if SASLv2 support is added
root@freebitch12:/etc/mail # sendmail -d0.1 -bv root
Version 8.15.2 Compiled with: DNSMAP IPV6_FULL LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6 NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS TCPWRAPPERS TLS_EC TLS_VRFY_PER_CTX USERDB XDEBUG ============ SYSTEM IDENTITY (after readcf) ============ (short domain name) $w = freebitch12 (canonical domain name) $j = freebitch12.localrouter (subdomain name) $m = localrouter (node name) $k = freebitch12 ======================================================== root... deliverable: mailer local, user root
root@freebitch12:/etc/mail # service sendmail restart
// test AUTH LOGIN PLAIN support with plain telnet, returns no support
root@freebbitch12:~ # telnet localhost 25
Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 freebbitch12 ESMTP ehlo test 250-freebbitch12.localrouter Hello localhost [127.0.0.1], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-STARTTLS 250-DELIVERBY 250 HELP quit
// test AUTH LOGIN PLAIN support with openssl, returns support
root@freebbitch12:~ # openssl s_client -connect localhost:25 -starttls smtp
....
lots of certificate info
....
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
ehlo test
250-freebbitch12.localrouter Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH LOGIN PLAIN
250-DELIVERBY
250 HELP
quit
221 2.0.0 freebbitch12.localrouter closing connection
Freebsd Wireless Networking Static and Dynamic IP Configuration
FreeBSD documentation pretty much explains everything but there are still some missing steps if you get into trouble and not used to FreeBSD.
Also most of “supposed to work” parameters might not work just like my laptop.
So this write up is to summarize and simplify necessary steps.
Test system is Thinkpad x120e running FreeBSD 12.1-RELEASE-p9 pretty old laptop but still requires some work on freebsd.
Wireless card: Realtek RTL8188CE 1×1 11b/g/n
Step 1:
Load Realtek drivers at boot time, add following lines to /boot/loader.conf
if_rtwn_pci_load="YES"
if_rtwn_usb_load="YES"
For list of Realtek cards supported by rtwn driver:
root@iphone:~ # man rtwn
Reboot the system or load modules manually with kldload.
After the reboot you will still not see wlan interface but check if your wifi card recognized by FreeBSD
root@iphone:~ # sysctl net.wlan.devices
net.wlan.devices: rtwn0
Now you need to create the wlan device:
ifconfig wlan create wlandev rtwn0
Step 2:
DHCP Setup:
Edit /etc/rc.conf and add following :
wlans_rtwn0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"
Edit /etc/wpa_supplicant.conf add your ssid and pw
network={
ssid="freebsdap"
psk="freebsdmall"
}
Now restart networking service:
root@iphone:~ # service netif restart
check your connections with ifconfig and look for wlan0 interface
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether xx:xx:xx:xx:xx:xx
inet 192.168.11.11 netmask 0xffffff00 broadcast 192.168.11.255
groups: wlan
ssid yourssidhere channel 6 (2437 MHz 11g ht/20) bssid xx:xx:xx:xx:xx:xx
regdomain FCC country US authmode WPA2/802.11i privacy ON
deftxkey UNDEF AES-CCM 2:128-bit AES-CCM 3:128-bit txpower 30 bmiss 7
scanvalid 60 protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi
-stbc -ldpc wme roaming MANUAL
media: IEEE 802.11 Wireless Ethernet MCS mode 11ng
status: associated
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
If everything work fine you are good to go.
Now once you restart your bsd box if you are unlucky like me your wlan interface will be gone and you wont be able to connect your AP.
A lot of folks say their setting remains the same but im not one of them so here is the solution:
Solution 1:
We’ll create a shell script and place it under rc.d this way when the box reboots FreeBSD will run our script and we’ll connect to AP automaticaly.
root@iphone:~ # vim /usr/local/etc/rc.d/wifi.sh
and add below lines:
#!/bin/sh
ifconfig wlan create wlandev rtwn0
service netif restart
Now make it executable:
chmod +x /usr/local/etc/rc.d/wifi.sh
Solution 2:
This time we will use crontab instead of rc.d, move wifi.sh to /root/ directory.
root@iphone:~ # crontab -e
and add following entry:
@reboot /root/wifi.sh
Now a reminder dont try to edit crontab with a text editor such as
root@iphone:~ # vim /etc/crontab
That is Freebsds global crontab file and format is different
Restart you bsd box and enjoy wifi connection with dhcp
Static IP
We will keep eveything same as dhcp configuration but edit 3 files /etc/rc.conf, /etc/resolv.conf and wifi.sh
in /etc/rc.conf change this line:
ifconfig_wlan0="WPA SYNCDHCP"
with this one:
ifconfig_wlan0="WPA inet 192.168.11.11 netmask 255.255.255.0"
defaultrouter="192.168.11.1"
Add below line to /etc/resolv.conf
nameserver 8.8.8.8
Add below line to wifi.sh file
service routing restart
Basically we change dhcp configuration with our static ip, add a name server since we are not using dhcp and restart routing service
One last tip if you gonna use window manager you might want to install wifimgr a GUI-based tool to manage WiFi network configuration.
root@iphone:~ # pkg install wifimgr