TrueOS Tips, Tricks, and FAQ

#11

Postgresql 10 server on TrueOS

Install via pkg (as root or sudo )

pkg install postgresql10-server

Running it through FreeBSD init system (rc)

Since there are no open-rc scripts for it, you can run it via the RC script like so.

sudo /usr/local/etc/rc.d/postgresql start

Running postgresql through open-rc

I hacked up an init script. Copy the following code snippet into /usr/local/etc/init.d/postgresql
and make sure it has the same permissions and ownerships as other files in /usr/local/etc/init.d/

#!/sbin/openrc-run

name=postgresql

# set defaults
postgresql_enable=${postgresql_enable:-"NO"}
postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
postgresql_user=${postgresql_user:-"postgres"}
eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data10"}
postgresql_class=${postgresql_class:-"default"}
postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
extra_commands="initdb reload"

# Command
command=/usr/local/bin/pg_ctl
command_args="-D ${postgresql_data} ${postgresql_flags}"


postgresql_initdb()
{
    su -l -c ${postgresql_class} ${postgresql_user} -c "exec /usr/local/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
}

get_config() {
[ -f ${postgresql_data%/}/postgresql.conf ] || return 1
eval echo $(sed -e 's:#.*::' ${postgresql_data%/}/postgresql.conf \
    | awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
}

depend() {
    use net
    provide postgresql

    if [ "$(get_config log_destination)" = "syslog" ]; then
        use logger
    fi
}

checkconfig() {

# Check that postgresql_data directory exists
if [ ! -d ${postgresql_data} ] ; then
    eerror "Directory not found: ${postgresql_data}"
    eerror "HINT: Ensure that postgresql_data points to the right path."
    return 1
fi

# Check for the existence of PostgreSQL's config files, and set the
# proper mode and ownership.
# Only three files should be checked as potentially other files
# may be in PGDATA that should not be touched.
local file
for file in postgresql pg_hba pg_ident ; do
    file="${postgresql_data%/}/${file}.conf"
    if [ -f ${file} ] ; then
        checkpath -f -m 0600 -o postgres:postgres ${file}
    else
        eerror "${file} not found"
        return 1
    fi
done

}

start_pre(){
    checkconfig || return 1
    ebegin "Starting Postgresql10"
    rm -f ${postgresql_data%/}/postmaster.pid
}

start() {
    su -l ${postgresql_user} -c "exec ${command} ${command_args} start"
}

stop() {
    ebegin "Stopping Postgresql10"
    su -l ${postgresql_user} -c "exec ${command} ${command_args} stop"
}

initdb(){
  postgresql_initdb
}

status(){
  su -l ${postgresql_user} -c "exec ${command} ${command_args} status"
}

reload() {
    ebegin "Reloading Postgres10 config data"
    su -l ${postgresql_user} -c "exec ${command} ${command_args} reload"
}

Now you can start postgresql service normally

service postgresql start

You can run the following to have it start up with the system by default.

rc-update add postgres

I read rabbitmq’s init file, the postgres rc.d init file and Gentoo’s open-rc file to come up with the script. No unicorns were harmed in its making.

0 Likes

#12

Meltdown, Spectre -FreeBSD first response

Was advised FreeBSD has made their first micro-code update available. Use at your own risk

https://www.freshports.org/sysutils/devcpu-data/

pkg-message:

Installing this port will allow host startup to update the CPU microcode on
a FreeBSD system automatically. In order to enable this feature, add the
following to the system’s /etc/rc.conf:

microcode_update_enable=“YES”

To ensure the update is applied, reboot the system or start the microcode update
service via:

service microcode_update start

If the CPU requires a microcode update, a console message such as the following
will appear:

Updating CPU Microcode…
/usr/local/share/cpucontrol/m32306c3_00000022.fw: updating cpu /dev/cpuctl0 from rev 0x17 to rev 0x22… done.
/usr/local/share/cpucontrol/m32306c3_00000022.fw: updating cpu /dev/cpuctl2 from rev 0x17 to rev 0x22… done.
/usr/local/share/cpucontrol/m32306c3_00000022.fw: updating cpu /dev/cpuctl4 from rev 0x17 to rev 0x22… done.
/usr/local/share/cpucontrol/m32306c3_00000022.fw: updating cpu /dev/cpuctl6 from rev 0x17 to rev 0x22… done.
Done.

Master Sites:

There is no master site for this port.
0 Likes

#13

Open-RC scripting and how to write

1 Like

#14

Settings in /etc/periodic.conf

I like to override some of the defaults for the periodic scripts. Don’t email to root, keep output in a file. Don’t do DNS lookups, clean /tmp, add ZFS, NTP and SMART status in the daily log. Here’s how I do it:

# periodic.conf overrides
# output to file
daily_output="/var/log/daily.log"
daily_status_security_output="/var/log/dailysecurity.log"
daily_status_network_usedns="NO"
daily_status_named_usedns="NO"
daily_clean_tmps_enable="YES"
daily_status_ntpd_enable="NO"
daily_status_zfs_enable="YES"
daily_scrub_zfs_enable="NO"    # set to YES for autoscrubbing at threshold days
daily_scrub_zfs_default_threshold="45"          # days between scrubs
daily_status_smart_enable="YES"
daily_status_smart_devices="/dev/ada0 /dev/ada1 /dev/ada2"
daily_queuerun_enable="NO"
weekly_output="/var/log/weekly.log"
weekly_status_security_output="/var/log/weeklysecurity.log"
monthly_output="/var/log/monthly.log"
monthly_status_security_output="/var/log/monthlysecurity.log"
2 Likes

#15

Cleaning Linux partitions in TrueOS and w/o Linux distro

1 Like

#16

ZFS and how to access missing pools:

https://discourse.trueos.org/t/zfs-and-how-to-access-missing-pools/2476/4

1 Like

#17

USB-Audio as default audio device (HOWTO):

A) Read man-page: 

% man snd | grep -A 17 hw.snd.verbose
     hw.snd.verbose
             Level of verbosity for the /dev/sndstat device.  Higher values include
             more output and the highest level, four, should be used when reporting
             problems.  Other options include:

             0   Installed devices and their allocated bus resources.

             1   The number of playback, record, virtual channels, and flags per
                 device.

             2   Channel information per device including the channel's current
                 format, speed, and pseudo device statistics such as buffer
                 overruns and buffer underruns.

             3   File names and versions of the currently loaded sound modules.

             4   Various messages intended for debugging.

B) Set settings accordingly:

% cat /boot/loader.conf.local | grep snd
snd_uaudio_load="YES"
hw.snd.verbose="3"

C) Reboot

D) Check /dev/sndstat:

% cat /dev/sndstat  | grep snd_uaudio
pcm4: <USB audio> at ? kld snd_uaudio (1p:1v/1r:1v) default

E) Set settings accordingly:

% cat /boot/loader.conf.local | grep 'snd.default_unit'
hw.snd.default_unit="4"

F) Reboot

That’s all.

1 Like

#18

A rough overview of using Nvidia Optimus on FreeBSD.

https://wiki.freebsd.org/Graphics/OptimusVideoSupport

2 Likes

#19

Once you change to using the IPFS network

You will need to sync your system as well, run the following commands;

sudo pc-updatemanager confcheck
sudo pc-updatemanager syncconf
sudo pc-updatemanager pkgcheck

0 Likes

Cannot upgrade to 18.03
#20

iPhone Hotspot USB tethering to TrueOS Laptop

Look at this link --> iPhone Hotspot USB tethering to TrueOS Laptop

0 Likes

#21

FreeBSD USB Disk and ZVOL Encryption with GELI

https://antranigv.am/weblog_en/posts/freebsd-geli-encryption-usb-and-zvol/

0 Likes

#22

How to change boot-up delay and root password.

To change the timing of boot-up delay go to:

/boot/defaults/loader.conf

Edit the last line in the loader.conf file to desired delay at:

Speed up boot time
autoboot_delay="02"   <-- indicates delay in seconds

To change root password

During system boot-up, enter a single user mode

Then type:

mount -uw /

Next type:

passwd

Enter your new password for root

Next type:

exit

Now, you can login with your new root’s password :slight_smile:

2 Likes

#23

man loader.conf:

FILES
     /boot/defaults/loader.conf  default settings -- do not change this file.
     /boot/loader.4th            defines the commands used by loader to read and
                                 process loader.conf.
     /boot/loader.conf           user defined settings.
     /boot/loader.conf.local     machine-specific settings for sites with a common
                                 loader.conf.
0 Likes

#24

#UEFI graphics screw up

0 Likes

#25

A quick Life Preserver howto - Thank you @michael.ger

0 Likes

closed #26
0 Likes

opened #27
0 Likes

#28

Some Lenovo, and probably other computers with UEFI video garbage

UEFI Resolution

Kris Moore edited this page on Jun 6 · 1 revision

On some systems when booted via UEFI you may end up in a console resolution that isn’t supported, resulting in a corrupt display. To work-around this issue you can do the following:

At the boot-loader menu, drop to the Command-Prompt (Under Advanced). Run the command ‘gop set 0’, replacing 0 with 1/2/3/4 until you find a resolution that seems to work with your system.

Once you’ve come up with a working resolution you can hard-code it by putting the 'gop set ’ command in /boot/loader.rc.local.

original link --> UEFI Resolution

0 Likes

#29

Trident ZFS pool /usr/local mystery

Thanks to @rowo, @jgroenveld, & @mer

1 Like

#30

Simple HowTo ZFS send ZFS Receive to move a dataset

A quick writeup that someone on telegram asked for. Simple
example of using zfs send and zfs receive to move a dataset.
This goes through pretty much the basics of gpart, zpool and zfs,
none original, most based on information in Michael W Lucas/Allan Jude
FreeBSD Mastery ZFS/Advanced ZFS plus publically available documentation
off the FreeBSD website.

I basically did the commands and cut-n-pasted them here, so there is
nothing fancy, just the straight commands.

All as root
ada0 is internal SATA SSD
da0 is Samsung 840 SSD in external “USB to SATA” chassis.

First get some basic information so we know what drive is what.
The descr field and ident come in handy.
root@trident-7581:~ # geom disk list
Geom name: ada0
Providers:

  1. Name: ada0
    Mediasize: 250059350016 (233G)
    Sectorsize: 512
    Stripesize: 4096
    Stripeoffset: 0
    Mode: r1w1e2
    descr: Samsung SSD 850 EVO mSATA 250GB
    lunid: 5002538d422eeed0
    ident: S33GNX0J808481X
    rotationrate: 0
    fwsectors: 63
    fwheads: 16

Geom name: da0
Providers:

  1. Name: da0
    Mediasize: 128035676160 (119G)
    Sectorsize: 512
    Stripesize: 4096
    Stripeoffset: 0
    Mode: r0w0e0
    descr: JMicron
    lunname: JMicron 201811153044
    lunid: 3020181115304400
    ident: 201811153044
    rotationrate: unknown
    fwsectors: 63
    fwheads: 255

Another way of getting some information.
root@trident-7581:~ # camcontrol devlist
<Samsung SSD 850 EVO mSATA 250GB EMT41B6Q> at scbus0 target 0 lun 0 (pass0,ada0)
<JMicron 0104> at scbus1 target 0 lun 0 (da0,pass1)

smartmontools on the internal device:
root@trident-7581:~ # smartctl -i /dev/ada0
smartctl 7.0 2018-12-30 r4883 [FreeBSD 13.0-CURRENT amd64] (local build)
Copyright © 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family: Samsung based SSDs
Device Model: Samsung SSD 850 EVO mSATA 250GB
Serial Number: S33GNX0J808481X
LU WWN Device Id: 5 002538 d422eeed0
Firmware Version: EMT41B6Q
User Capacity: 250,059,350,016 bytes [250 GB]
Sector Size: 512 bytes logical/physical
Rotation Rate: Solid State Device
Form Factor: mSATA
Device is: In smartctl database [for details use: -P show]
ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c
SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Mon Mar 11 17:43:34 2019 EDT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Lets see what partitions are around
root@trident-7581:~ # gpart show
=> 40 488397088 ada0 GPT (233G)
40 512 1 freebsd-boot (256K)
552 488169472 2 freebsd-zfs (233G)
488170024 227104 - free - (111M)

=> 40 250069600 da0 GPT (119G)
40 1024 1 freebsd-boot (512K)
1064 984 - free - (492K)
2048 16777216 2 freebsd-swap (8.0G)
16779264 209715200 3 freebsd-zfs (100G)
226494464 23575176 - free - (11G)

I’m reusing the drive that’s in da0, so first destroy any formatting
root@trident-7581:~ # gpart destroy -F /dev/da0
da0 destroyed
root@trident-7581:~ # gpart show
=> 40 488397088 ada0 GPT (233G)
40 512 1 freebsd-boot (256K)
552 488169472 2 freebsd-zfs (233G)
488170024 227104 - free - (111M)

Create paritition table (textbook stuff here)
root@trident-7581:~ # gpart create -s gpt /dev/da0
da0 created
root@trident-7581:~ # gpart show
=> 40 488397088 ada0 GPT (233G)
40 512 1 freebsd-boot (256K)
552 488169472 2 freebsd-zfs (233G)
488170024 227104 - free - (111M)

=> 40 250069600 da0 GPT (119G)
40 250069600 - free - (119G)

Create a single ZFS partition, aligned at 1M boundary.
label of extzfs
root@trident-7581:~ # gpart add -t freebsd-zfs -a 1m -l extzfs /dev/da0
da0p1 added
root@trident-7581:~ # gpart show
=> 40 488397088 ada0 GPT (233G)
40 512 1 freebsd-boot (256K)
552 488169472 2 freebsd-zfs (233G)
488170024 227104 - free - (111M)

=> 40 250069600 da0 GPT (119G)
40 2008 - free - (1.0M)
2048 250066944 1 freebsd-zfs (119G)
250068992 648 - free - (324K)

Check the min_ashift value, we want 12 to force ZFS to use
4096 blocksize at minimum
root@trident-7581:~ # sysctl -a | grep ashift
vfs.zfs.min_auto_ashift: 12 <<< already good
vfs.zfs.max_auto_ashift: 13

Here’s how you set it
root@trident-7581:~ # sysctl -w vfs.zfs.min_auto_ashift=12
vfs.zfs.min_auto_ashift: 12 -> 12

Let’s find a label to use for the zpool vdev. I like
using gpt labels.
root@trident-7581:~ # ls -ltr /dev/gpt
total 0
crw-r----- 1 root operator 0x285 Mar 11 17:27 extzfs

You could also use the raw partition like da0p1
root@trident-7581:~ # ls -ltr /dev/da*
crw-r----- 1 root operator 0x283 Mar 11 17:22 /dev/da0
crw-r----- 1 root operator 0x284 Mar 11 17:27 /dev/da0p1

Now we create a zpool. This is a simple or striped zpool vdev
root@trident-7581:~ # zpool create extzfs gpt/extzfs
root@trident-7581:~ # zpool status
pool: extzfs
state: ONLINE
scan: none requested
config:

NAME          STATE     READ WRITE CKSUM
extzfs        ONLINE       0     0     0
  gpt/extzfs  ONLINE       0     0     0

errors: No known data errors

pool: trident
state: ONLINE
scan: scrub repaired 0 in 0 days 00:01:03 with 0 errors on Wed Feb 13 07:04:37 2019
config:

NAME        STATE     READ WRITE CKSUM
trident     ONLINE       0     0     0
  ada0p2    ONLINE       0     0     0

errors: No known data errors

Lets see what zfs datasets are around and mounted
root@trident-7581:~ # zfs mount
trident/ROOT/18.12-RELEASE-U7 /
trident/tmp /tmp
trident/usr/home /usr/home
trident/usr/jails /usr/jails
trident/usr/obj /usr/obj
trident/usr/ports /usr/ports
trident/usr/src /usr/src
trident/var/audit /var/audit
trident/var/log /var/log
trident/var/mail /var/mail
trident/var/tmp /var/tmp
extzfs /extzfs <<< Here’s one we just created

Take a snapshot of what we want to send
root@trident-7581:~ # zfs snapshot trident/usr/home@testsnap
root@trident-7581:~ # zfs list -t snap
NAME USED AVAIL REFER MOUNTPOINT
trident/ROOT/18.12-RELEASE-U7@2019-02-15-03:43:19 288M - 4.06G -
trident/ROOT/18.12-RELEASE-U7@2019-02-21-03:12:54 265M - 4.79G -
trident/ROOT/18.12-RELEASE-U7@2019-02-28-14:17:57 378M - 5.25G -
trident/ROOT/18.12-RELEASE-U7@2019-03-11-14:57:06 268M - 5.78G -
trident/usr/home@01Mar2019 14.0G - 29.1G -
trident/usr/home@testsnap 0 - 16.5G -

Send the snapshot to the new zpool
root@trident-7581:~ # zfs send trident/usr/home@testsnap | zfs receive extzfs/home
root@trident-7581:~ #
root@trident-7581:~ # zfs mount
trident/ROOT/18.12-RELEASE-U7 /
trident/tmp /tmp
trident/usr/home /usr/home
trident/usr/jails /usr/jails
trident/usr/obj /usr/obj
trident/usr/ports /usr/ports
trident/usr/src /usr/src
trident/var/audit /var/audit
trident/var/log /var/log
trident/var/mail /var/mail
trident/var/tmp /var/tmp
extzfs /extzfs
extzfs/home /extzfs/home <<<< Here it is

Yep, files are there.
root@trident-7581:~ # ls /extzfs/home
mremski tmp

At this point you can use zfs get/set commands to change mountpoints and use the new
device as “/usr/home”.

If you are doing this to realign the block size on an existing vdev, you could now
do
zfs unmount the old one
zpool destroy -f oldpool

check your min_ashift value
zpool create on the old device.

If you have this on an external drive, don’t forget to “zpool export” before you unplug or power it off.
root@trident-7581:~ # zpool export extzfs
root@trident-7581:~ # zfs list
NAME USED AVAIL REFER MOUNTPOINT
trident 41.3G 183G 88K none
trident/ROOT 8.32G 183G 88K none
trident/ROOT/18.12-RELEASE-U4 484K 183G 4.79G /
trident/ROOT/18.12-RELEASE-U5 592K 183G 5.25G /
trident/ROOT/18.12-RELEASE-U6 568K 183G 5.78G /
trident/ROOT/18.12-RELEASE-U7 8.32G 183G 5.79G /
trident/ROOT/initial 676K 183G 4.06G /mnt
trident/tmp 140K 183G 140K /tmp
trident/usr 33.0G 183G 88K none
trident/usr/home 30.5G 183G 16.5G /usr/home
trident/usr/jails 88K 183G 88K /usr/jails
trident/usr/obj 88K 183G 88K /usr/obj
trident/usr/ports 88K 183G 88K /usr/ports
trident/usr/src 2.53G 183G 2.53G /usr/src
trident/var 1.09M 183G 88K none
trident/var/audit 88K 183G 88K /var/audit
trident/var/log 744K 183G 744K /var/log
trident/var/mail 112K 183G 112K /var/mail
trident/var/tmp 88K 183G 88K /var/tmp

Then when you plug it back in, you zpool import:
root@trident-7581:~ # zpool import extzfs
root@trident-7581:~ # zfs list
NAME USED AVAIL REFER MOUNTPOINT
extzfs 16.9G 98.4G 88K /extzfs
extzfs/home 16.9G 98.4G 16.9G /extzfs/home
trident 41.3G 183G 88K none
trident/ROOT 8.32G 183G 88K none
trident/ROOT/18.12-RELEASE-U4 484K 183G 4.79G /
trident/ROOT/18.12-RELEASE-U5 592K 183G 5.25G /
trident/ROOT/18.12-RELEASE-U6 568K 183G 5.78G /
trident/ROOT/18.12-RELEASE-U7 8.32G 183G 5.79G /
trident/ROOT/initial 676K 183G 4.06G /mnt
trident/tmp 140K 183G 140K /tmp
trident/usr 33.0G 183G 88K none
trident/usr/home 30.5G 183G 16.5G /usr/home
trident/usr/jails 88K 183G 88K /usr/jails
trident/usr/obj 88K 183G 88K /usr/obj
trident/usr/ports 88K 183G 88K /usr/ports
trident/usr/src 2.53G 183G 2.53G /usr/src
trident/var 1.09M 183G 88K none
trident/var/audit 88K 183G 88K /var/audit
trident/var/log 744K 183G 744K /var/log
trident/var/mail 112K 183G 112K /var/mail
trident/var/tmp 88K 183G 88K /var/tmp

2 Likes