SMOLNET PORTAL home about changes
* Assorted notes on using FreeBSD
… and, to lesser extent, other BSDs

** Disks
*** What is that disk I’ve just inserted
**** and where is it?

~dmesg~ works, of course for finding the device name:

#+BEGIN_EXAMPLE
~> dmesg | tail
umass0 on uhub2
umass0: <Seagate Portable, class 0/0, rev 2.00/1.30, addr 2> on usbus3
umass0:  SCSI over Bulk-Only; quirks = 0x0100
umass0:6:0: Attached to scbus6
da0 at umass-sim0 bus 0 scbus6 target 0 lun 0
da0: <Seagate Portable 0130> Fixed Direct Access SPC-2 SCSI device
da0: Serial Number 2GH30VDX    
da0: 40.000MB/s transfers
da0: 476940MB (976773168 512 byte sectors)
da0: quirks=0x2<NO_6_BYTE>
#+END_EXAMPLE

~camcontrol~ can be used to list disks:

#+BEGIN_EXAMPLE
~> sudo camcontrol devlist
<WDC WD10EZEX-08WN4A0 01.01A01>    at scbus0 target 0 lun 0 (pass0,ada0)
<ST31000524AS JC4B>                at scbus2 target 0 lun 0 (pass1,ada1)
<HL-DT-ST DVDRAM GH22NS70 EX00>    at scbus5 target 0 lun 0 (cd0,pass2)
<Seagate Portable 0130>            at scbus6 target 0 lun 0 (da0,pass3)
#+END_EXAMPLE

**** ok, I found it, but what is there?

~gpart~ shows the partition scheme and, if you’re lucky, the fs:

#+BEGIN_EXAMPLE
~> gpart show da0
=>       63  976773105  da0  MBR  (466G)
         63       1985       - free -  (993K)
       2048  976771120    1  ntfs  (466G)
#+END_EXAMPLE

~file -s~ shows lots of stuff:

#+BEGIN_EXAMPLE
~> file -s /dev/da0s1
/dev/da0s1: DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS    ",…
#+END_EXAMPLE

~fstyp~ is the specialized program to find the fs type:

#+BEGIN_EXAMPLE
~> fstyp /dev/da0s1
ntfs
#+END_EXAMPLE

*** Restoring/updating the bootloader

[[https://forums.freebsd.org/threads/update-of-the-bootcodes-for-a-gpt-scheme.80163/][Full Howto]]

In my particular case,

#+BEGIN_EXAMPLE
~> gpart show ada1
=>        40  1953525088  ada1  GPT  (932G)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048     4194304     2  freebsd-swap  (2.0G)
     4196352  1949327360     3  freebsd-zfs  (930G)
  1953523712        1416        - free -  (708K)
#+END_EXAMPLE

The command I need is

: gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1

*** ZFS
**** Creating mirror
I have a pool with ~ada1p3~ being the only device there.
Let’s say I have another drive of the same size, ~ada0~.
Steps to create a mirror:

First, backup the partition table
#+BEGIN_EXAMPLE
# gpart backup ada1 > ada1.gpt
# cat ada1.gpt
GPT 128
1   freebsd-boot         40       1024 gptboot0 
2   freebsd-swap       2048    4194304 swap0 
3    freebsd-zfs    4196352 1949327360 zfs0 
#+END_EXAMPLE

Now, restore it to the mirror drive. Copy the bootcode as well

#+BEGIN_EXAMPLE
# gpart destroy -F ada0
ada0 destroyed
# gpart restore /dev/ada0 <ada1.gpt
# gpart show ada0
=>        40  1953525088  ada0  GPT  (932G)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048     4194304     2  freebsd-swap  (2.0G)
     4196352  1949327360     3  freebsd-zfs  (930G)
  1953523712        1416        - free -  (708K)

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i1 ada0
partcode written to ada0p1
bootcode written to ada0
#+END_EXAMPLE

Add the new device to the pool:

#+BEGIN_EXAMPLE
# zpool attach zroot ada1p3 ada0p3
# zpool status
  pool: zroot
 state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
	continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Mon Oct  9 10:20:17 2023
	37.7G scanned at 2.36G/s, 704K issued at 44K/s, 438G total
	0B resilvered, 0.00% done, no estimated completion time
config:

	NAME        STATE     READ WRITE CKSUM
	zroot       ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    ada1p3  ONLINE       0     0     0
	    ada0p3  ONLINE       0     0     0

errors: No known data errors
#+END_EXAMPLE

Wait for resilvering to finis.

** user and group management

[[man:pw][man pw(8)]] does everything

Example: adding user to a group

: pw groupmod operator -m $USER


** cron

On machines, that are not online 24/7, ~sysutils/anacron~ can be used
to ensure execution of periodic scripts.
Response: text/plain
Original URLgopher://tilde.pink/0/~jsv/freebsd.org
Content-Typetext/plain; charset=utf-8