Let's document some useful, not only "troubleshooting", FreeBSD commands.
I will split those commands into following categories:
- General OS Management
- RAM Management
- Network Management
- Storage Management
- USB device Management
- Power Management
- Display / Graphics Cards Management
General OS Management
General commands for FreeBSD system administration.
Show FreeBSD Version
freebsd-version -kru ; uname -aKU
These two commands in sequence display detailed information about your FreeBSD system's version and kernel. It helps to
- Detect version mismatches between kernel and userland (e.g. after patching).
- Confirm if a reboot is pending.
- See detailed kernel version info (compiled vs. running)
dpasek@freebsd01:~ $
freebsd-version -kru ; uname -aKU
14.2-RELEASE-p1 14.2-RELEASE-p1 14.2-RELEASE-p3 FreeBSD freebsd01.home.uw.cz 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64 1402000 1402000
Pkg Repository Configuration
pkg repos -el | sort -f ; pkg repos -e
This one-liner prints a sorted list of repository names and full configuration of each repository. This is helpful for debugging, auditing, or confirming what repositories are enabled and how they're configured.
dpasek@freebsd01:~ $
pkg repos -el | sort -f ; pkg repos -e
FreeBSD FreeBSD: { url : "pkg+https://pkg.FreeBSD.org/FreeBSD:14:amd64/latest", enabled : yes, priority : 0, mirror_type : "SRV", signature_type : "FINGERPRINTS", fingerprints : "/usr/share/keys/pkg" }
Scroll Raw FreeBSD Console
When you use text console on physical computer (laptop/desktop/server) or even virtual console (VMware Virtual Machine) you can sometime need to scroll the output on console.
You first need to hit [Scroll Lock] key and then you can scroll the console buffer with [PGUP] and [PGDN] keys.
To leave Scroll Lock mode and work with console interactively you have to hit [Scroll Lock] key again.
RAM Management
Commands for FreeBSD memory management.
Total Physical RAM
The sysctl utility can retrieves kernel state, thus can be used to get total physical RAM in running FreeBSD system. Example below is getting physical RAM in Bytes, MB, and GB.
root@fbsd-test02-zfs:~ #
sysctl hw.physmem
hw.physmem: 2102906880 root@fbsd-test02-zfs:~ #
sysctl -n hw.physmem | awk '{ printf "%.2f MB\n", $1 / 1024 / 1024 }'
2005.49 MB root@fbsd-test02-zfs:~ #
sysctl -n hw.physmem | awk '{ printf "%.2f GB\n", $1 / 1024 / 1024 / 1024 }'
1.96 GB root@fbsd-test02-zfs:~ #
Memory Statistics (Used vs Free) - top
You can get the amount of free RAM from the top command.
Below is the output from FreeBSD with 2 GB RAM and ZFS filesystem ...
last pid: 1453; load averages: 0.27, 0.21, 0.17 up 0+01:37:04 01:19:06
28 processes: 1 running, 27 sleeping
CPU: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
Mem: 19M Active, 26M Inact, 122M Wired, 1784M Free
ARC: 48M Total, 8028K MFU, 38M MRU, 260K Anon, 359K Header, 1494K Other
32M Compressed, 75M Uncompressed, 2.31:1 Ratio
Swap: 2048M Total, 2048M Free
Below is the output from FreeBSD with 1 GB RAM and UFS filesystem ...
last pid: 6247; load averages: 0.13, 0.14, 0.13 up 42+23:38:55 01:24:34
27 processes: 1 running, 26 sleeping
CPU: 0.1% user, 0.0% nice, 0.2% system, 0.0% interrupt, 99.7% idle
Mem: 4748K Active, 701M Inact, 232M Wired, 102M Buf, 39M Free
Swap: 410M Total, 410M Free
Let's break down memory categories:
- Active: Memory actively being used by running processes.
- Inact (Inactive): Memory that was recently used but hasn't been accessed for a while. This memory can be quickly repurposed if an application needs it. It's effectively "available" memory, though not strictly "free."
- Laundry: Memory that is "dirty" and needs to be written to disk (laundered) before it can be reused. This is often associated with file system caches.
- Wired: Memory used by the kernel and essential system components. This memory cannot be swapped out.
- Buf (Buffers): Memory used for disk buffers and caches (e.g., file system metadata). This memory can be freed if needed.
- Free: This is the truly unused memory that is immediately available for allocation.
To get a good idea of "available" memory for applications, you generally consider Inact + Buf + Free. FreeBSD's kernel is designed to use as much RAM as possible for caching to speed up I/O, so seeing a low Free number is usually not a concern if Inact and Buf are sizable.
Free Memory - freecolor
freecolor utility displays the total amount of free and used physical and swap memory in the system as a colored bargraph on the command line. freecolor utility is not part of the base system, therefore, it must be installed.
pkg install -y freecolor
Below is the output from FreeBSD with 2 GB RAM and ZFS filesystem ...
root@fbsd-test02-zfs:~ #
freecolor -o -m
total used free shared buffers cached Mem: 1953 327 1625 0 0 0 Swap: 2048 0 2048 root@fbsd-test02-zfs:~ #
freecolor -m
Physical : [#############################......] 83% (1625/1953) Swap : [###################################] 100% (2048/2048) root@fbsd-test02-zfs:~ #
Network Management
Commands for FreeBSD network management.
Show PCI Network Card(s)
pciconf -lv | grep -B 3 -A 1 network
This one-liner helps you identify the PCI network adapter(s) and shows 3 lines before and one after the line containing the word network for context, including device ID, vendor, and possibly the driver in use.
dpasek@freebsd01:~ $
pciconf -lv | grep -B 3 -A 1 network
vmx0@pci0:11:0:0: class=0x020000 rev=0x01 hdr=0x00 vendor=0x15ad device=0x07b0 subvendor=0x15ad subdevice=0x07b0 vendor = 'VMware' device = 'VMXNET3 Ethernet Controller' class = network subclass = ethernet
Show USB Network Card(s)
We can leverage usbconfig command to list USB devices and identify network adapter.
root@dell5530:~ #
usbconfig list
ugen0.1: <XHCI root HUB Intel> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA) ugen0.2: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA) ugen0.3: <Wireless-AC 9260 Bluetooth Adapter Intel Corp.> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA) ugen0.4: <IntegratedWebcamHD Realtek Semiconductor Corp.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA) ugen0.5: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA) ugen0.6: <RTL8153 Gigabit Ethernet Adapter Realtek Semiconductor Corp.> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA) root@dell5530:~ #
This clearly identifies a Realtek RTL8153 based Gigabit Ethernet adapter connected via USB. To confirm its network interface name in FreeBSD, you would typically then run ifconfig -a and look for an interface like ure0 (as Realtek USB Ethernet devices usually get the ure driver).
root@dell5530:~ #
ifconfig -a
lo0: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384 options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 groups: lo nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=0 ether 5c:87:9c:fa:47:72 inet 192.168.5.134 netmask 0xffffff00 broadcast 192.168.5.255 groups: wlan ssid PASNET channel 6 (2437 MHz 11g) bssid f0:21:e0:9d:e3:c6 regdomain FCC country US authmode WPA2/802.11i privacy ON deftxkey UNDEF AES-CCM 2:128-bit txpower 30 bmiss 10 scanvalid 60 protmode CTS wme roaming MANUAL parent interface: iwm0 media: IEEE 802.11 Wireless Ethernet OFDM/54Mbps mode 11g status: associated nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=68009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> ether 00:e0:4c:68:1f:f4 media: Ethernet autoselect (none <half-duplex>) status: no carrier nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> root@dell5530:~ #
In our case, general USB Ethernet driver uether is used for USB NIC, therefore interface name is ue0 and not ure0.
What media network interface supports?
Here is the output for PCI network adpater vmx0 in VMware Virtual Machine
dpasek@freebsd01:~ $
ifconfig -m vmx0
vmx0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500 options=4e407bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS,MEXTPG> capabilities=4f507bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWFILTER,VLAN_HWTSO,NETMAP,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS,MEXTPG> ether 00:50:56:a9:72:bd inet 192.168.8.11 netmask 0xffffff00 broadcast 192.168.8.255 media: Ethernet autoselect status: active supported media: media autoselect nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> dpasek@freebsd01:~ $
And here is the output for USB network adapter ue0 in Dell Precision 5530 Laptop ...
root@dell5530:~ #
ifconfig -m ue0
ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=68009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> capabilities=68009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> ether 00:e0:4c:68:1f:f4 media: Ethernet autoselect (none <half-duplex>) status: no carrier supported media: media autoselect media 1000baseT mediaopt full-duplex,master media 1000baseT mediaopt full-duplex media 100baseTX mediaopt full-duplex media 100baseTX media 10baseT/UTP mediaopt full-duplex media 10baseT/UTP media none nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> root@dell5530:~ #
Network Information
FreeBSD uses the ifconfig(8) and route(8) commands.
By default the FreeBSD ifconfig(8) command displays information in hexadecimal values like netmask 0xffffff00 for example instead of more common CIDR format like /24
dpasek@freebsd01:~ $ ifconfig vmx0
vmx0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=4e407bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS,MEXTPG>
ether 00:50:56:a9:72:bd
inet 192.168.8.11 netmask 0xffffff00 broadcast 192.168.8.255
media: Ethernet autoselect
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
dpasek@freebsd01:~ $
… but you can use -f cidr option to switch to the latter.
dpasek@freebsd01:~ $ ifconfig
-f
cidr
vmx0
vmx0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500 options=4e407bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS,MEXTPG> ether 00:50:56:a9:72:bd inet 192.168.8.11/24 broadcast 192.168.8.255 media: Ethernet autoselect status: active nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
You can also make that permanent with IFCONFIG_FORMAT=inet:cidr variable exported within your shell configs with either export(1) or setenv(1) depending on your preferred shell.
Show Routing Table
netstat -rn is the best command to list all entries in routing table.
root@dell5530:~ #
netstat -rn
Routing tables Internet: Destination Gateway Flags Netif Expire default 192.168.5.254 UGS wlan0 127.0.0.1 link#1 UH lo0 192.168.5.0/24 link#3 U wlan0 192.168.5.134 link#1 UHS lo0 Internet6: Destination Gateway Flags Netif Expire ::/96 link#1 URS lo0 ::1 link#1 UHS lo0 ::ffff:0.0.0.0/96 link#1 URS lo0 fe80::%lo0/10 link#1 URS lo0 fe80::%lo0/64 link#1 U lo0 fe80::1%lo0 link#1 UHS lo0 ff02::/16 link#1 URS lo0 root@dell5530:~ #
Add Default Route
route add -net 0.0.0.0/0 192.168.5.1
or
route add default 192.168.5.1
Add, Change, Delete static entry into Routing Table
Add a static route to the 172.16.10.0/24 network via the 172.16.1.1 gateway:
route add -net 172.16.10.0/24 172.16.1.1
Change the gateway of an already established static route in the routing table:
route change -net 172.16.10.0/24 172.16.1.2
Delete a static route from the routing table:
route delete -net 172.16.10.0/24 172.16.1.2
Remove all routes from the routing table:
route flush
What process is Listening on what port
The sockstat command lists open Internet or UNIX domain sockets.
root@fbsd-test02-zfs:~ #
sockstat -l4
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS root sshd 846 8 tcp4 *:22 *:* ntpd ntpd 799 21 udp4 *:123 *:* ntpd ntpd 799 22 udp4 192.168.8.140:123 *:* ntpd ntpd 799 25 udp4 127.0.0.1:123 *:* root syslogd 732 7 udp4 *:514 *:* root@fbsd-test02-zfs:~ #
-l Show listening sockets
Network usage statistics
systat command can be used to check how much the network interfaces are utilized.
root@freebsd01:~ #
systat -if 1
/0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /10 Load Average | Interface Traffic Peak Total vmx0 in 0.060 KB/s 6.810 KB/s 247.519 GB out 0.444 KB/s 4.865 KB/s 157.102 GB
Storage Management
Commands for FreeBSD storage management.
Disks Available in the System
We can use CAM (Common Access Method). The CAM subsystem is the lowest level of the storage stack in FreeBSD (above the physical device drivers). It provides a generic, protocol-independent way for the kernel to talk to various storage devices like SCSI, SATA, SAS, and USB drives. It handles the direct communication with the hardware. It manages the physical bus, sends commands to the devices, handles error recovery, and provides the low-level "raw" device access.
root@ns1:~ #
camcontrol devlist
<NECVMWar VMware SATA CD00 1.00> at scbus2 target 0 lun 0 (cd0,pass0) <VMware Virtual disk 2.0> at scbus32 target 0 lun 0 (pass1,da0) root@ns1:~ #
We can use GEOM (Upper Layer on top of CAM). GEOM is FreeBSD's modular disk I/O framework. It sits above the CAM layer. Utility geom is universal control utility for GEOM classes. A GEOM class is a kernel module that provides a specific disk-related functionality or "transformation." GEOM (Geometric) is FreeBSD's modular and extensible disk I/O framework. GEOM classes are the building blocks of this framework, allowing you to stack different functionalities on top of one another. GEOM classes operate by taking an existing disk device (a "provider") and transforming it into a new, virtual device (another "provider") that can be used by other classes or the operating system.
dpasek@ns1.home.uw.cz:~ $
geom disk list
Geom name: da0 Providers: 1. Name: da0 Mediasize: 8589934592 (8.0G) Sectorsize: 512 Stripesize: 1048576 Stripeoffset: 0 Mode: r2w2e3 descr: VMware Virtual disk ident: (null) rotationrate: 0 fwsectors: 63 fwheads: 255 Geom name: cd0 Providers: 1. Name: cd0 Mediasize: 0 (0B) Sectorsize: 2048 Mode: r0w0e0 descr: NECVMWar VMware SATA CD00 ident: (null) rotationrate: unknown fwsectors: 0 fwheads: 0 dpasek@ns1.home.uw.cz:~ $
Disk Information and Evaluation
diskinfo(8) can tell you fast how good the disk performs. Just start it against any disk with -cvt arguments and you know what You need to know.
root@freebsd01:~ #
diskinfo -cvt da0
da0 512 # sectorsize 8589934592 # mediasize in bytes (8.0G) 16777216 # mediasize in sectors 0 # stripesize 0 # stripeoffset 1044 # Cylinders according to firmware. 255 # Heads according to firmware. 63 # Sectors according to firmware. VMware Virtual disk # Disk descr. # Disk ident. pvscsi0 # Attachment No # TRIM/UNMAP support 0 # Rotation rate in RPM Not_Zoned # Zone Mode I/O command overhead: time to read 10MB block 0.005232 sec = 0.000 msec/sector time to read 20480 sectors 4.506054 sec = 0.220 msec/sector calculated command overhead = 0.220 msec/sector Seek times: Full stroke: 250 iter in 0.058371 sec = 0.233 msec Half stroke: 250 iter in 0.081958 sec = 0.328 msec Quarter stroke: 500 iter in 0.133898 sec = 0.268 msec Short forward: 400 iter in 0.097736 sec = 0.244 msec Short backward: 400 iter in 0.100374 sec = 0.251 msec Seq outer: 2048 iter in 0.257116 sec = 0.126 msec Seq inner: 2048 iter in 0.315503 sec = 0.154 msec Transfer rates: outside: 102400 kbytes in 0.081982 sec = 1249055 kbytes/sec middle: 102400 kbytes in 0.025202 sec = 4063170 kbytes/sec inside: 102400 kbytes in 0.032936 sec = 3109060 kbytes/sec root@freebsd01:~ #
Disk I/O Statistics
gstat(8) print statistics about GEOM disks. It shows in desired interval (-I 3s) how many IOPS and bandwidth (kBps) the disks provide.
gstat -p -I 3s
dT: 3.084s w: 3.000s
L(q) ops/s r/s kBps ms/r w/s kBps ms/w %busy Name
0 0 0 0 0.000 0 0 0.000 0.0| cd0
0 4620 4619 2309 0.178 1 13 0.340 82.3| da0
Another way is to use iostat(8). The iostat utility displays kernel I/O statistics on terminal, device, and cpu operations. Option -w 1 waits one second between measurements.
root@freebsd01:~ #
iostat -w 1 da0
tty da0 cpu tin tout KB/t tps MB/s us ni sy in id 0 0 27.7 0 0.00 0 0 0 0 100 0 132 0.0 0 0.00 0 0 0 0 100 4 612 20.0 10 0.20 0 0 0 0 100 0 47 0.0 0 0.00 0 0 0 0 100 0 111 250 40 9.81 0 0 1 0 99 0 46 0.5 4886 2.42 0 0 13 3 84 0 44 0.5 5229 2.55 0 0 8 3 89 0 46 0.5 4944 2.41 0 0 7 3 89 0 45 0.5 4928 2.41 0 0 9 3 88 0 186 0.5 540 0.26 0 0 3 0 97 0 105 0.5 250 0.12 0 0 1 0 99 0 115 255 397 98.95 0 0 1 0 99 0 117 255 405 101.07 0 0 1 0 99 0 121 256 392 97.97 0 0 1 0 99 0 47 0.0 0 0.00 0 0 0 0 100 0 44 0.0 0 0.00 0 0 0 0 100 0 46 0.0 0 0.00 0 0 0 0 100
Disk Partitioning and Filesystem Detection
FreeBSD has fstyp(8) command. The fstyp utility is used to determine the filesystem type on a given device. It can recognize BeFS (BeOS), ISO-9660, exFAT, Ext2, FAT, NTFS, and UFS filesystems. When the -u flag is specified, fstyp also recognizes certain additional metadata formats that cannot be handled using mount(8), such as geli(8) providers, and ZFS pools.
Let's see how it works with MBR/UFS.
root@freebsd01:~ #
gpart show
=> 63 16777153 da0 MBR (8.0G) 63 1 - free - (512B) 64 16777152 1 freebsd [active] (8.0G) => 0 16777152 da0s1 BSD (8.0G) 0 15935488 1 freebsd-ufs (7.6G) 15935488 839680 2 freebsd-swap (410M) 16775168 1984 - free - (992K) root@freebsd01:~ #
fstyp /dev/da0s1
ufs root@freebsd01:~ #
fstyp /dev/da0s1a
ufs root@freebsd01:~ #
fstyp /dev/da0s1b
fstyp: /dev/da0s1b: filesystem not recognized root@freebsd01:~ #
gpart is control utility for the disk partitioning GEOM class. gpart show list current partition information for the specified geoms, or all geoms if none are specified.
In our example, we have only disk da0 with MBR partitioning scheme. We see single MBR slice named freebsd and having 8.0 GB of data, starting in sector 64 and having 16777152 sectors where each sector has 512 bytes. Inside this da0s1 MBR slice, there's a BSD disklabel that further divides the space into:
- A 7.6GB UFS partition (da0s1a) for the file system
- A 410MB swap partition (da0s1b) - this cannot be recognized by fstyp
- A small amount of free space at the very end of the BSD slice.
Let's see how it works with GPT/ZFS.
root@fbsd-test02-zfs:~ #
gpart show
=> 40 16777136 da0 GPT (8.0G) 40 1024 1 freebsd-boot (512K) 1064 984 - free - (492K) 2048 4194304 2 freebsd-swap (2.0G) 4196352 12578816 3 freebsd-zfs (6.0G) 16775168 2008 - free - (1.0M) root@fbsd-test02-zfs:~ #
fstyp -u /dev/da0p1
fstyp: /dev/da0p1: filesystem not recognized root@fbsd-test02-zfs:~ #
fstyp -u /dev/da0p2
fstyp: /dev/da0p2: filesystem not recognized root@fbsd-test02-zfs:~ #
fstyp -u /dev/da0p3
zfs root@fbsd-test02-zfs:~ #
Disk usage
In FreeBSD, there are two primary commands for checking disk usage and free space: df and du. They serve different but complementary purposes.
df (disk free) - For File System Overview. df is used to get a summary of disk space usage across all mounted file systems.
root@freebsd01:~ #
df -h
Filesystem Size Used Avail Capacity Mounted on /dev/da0s1a 7.3G 4.3G 2.5G 64% / devfs 1.0K 0B 1.0K 0% /dev root@freebsd01:~ #
Checking Inode Usage: Inodes are data structures that store information about files and directories. If you run out of inodes, you can't create new files even if you have free disk space.
root@freebsd01:~ #
df -i
Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on /dev/da0s1a 7706396 4517068 2572820 64% 43323 998339 4% / devfs 1 0 1 0% 0 0 - /dev root@freebsd01:~ #
du (disk usage) - For Directory/File Specific Usage. du is used to estimate file space usage. Unlike df, which looks at mounted filesystems, du works by traversing directories and summing up the sizes of files and subdirectories. This is useful for finding out what's consuming space within a particular directory.
root@freebsd01:~ #
du -sh /usr
2.2G /usr root@freebsd01:~ #
-h “Human-readable” output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte based on powers of 1024
-s Display an entry for each specified file. (Equivalent to -d 0)
Manage ZFS Boot Environments
FreeBSD has bectl(8) in the base.
We can list all boot environments. We have only one after fresh installation.
root@fbsd-test02-zfs:~ #
bectl list
BE Active Mountpoint Space Created default NR / 1.19G 2025-07-15 22:26 root@fbsd-test02-zfs:~ #
Now we can create a new boot environment (snapshot named 14.3-RELEASE-STATE-2025-07-16-A), which will preserve current state before FreeBSD update.
root@fbsd-test02-zfs:~ #
bectl create 14.3-RELEASE-STATE-2025-07-16
root@fbsd-test02-zfs:~ #
bectl list
BE Active Mountpoint Space Created 14.3-RELEASE-STATE-2025-07-16-A - - 8K 2025-07-15 23:09 default NR / 1.19G 2025-07-15 22:26 root@fbsd-test02-zfs:~ #
Now, we can update default boot environment (default) and if something go wrong, we can revert to the snapshot and start from scratch.
Let's update default boot environment from FreeBSD 14.3-RELEASE to the latest update.
root@fbsd-test02-zfs:~ #
freebsd-update fetch
src component not installed, skipped Looking up update.FreeBSD.org mirrors... 3 mirrors found. Fetching public key from update1.freebsd.org... done. Fetching metadata signature for 14.3-RELEASE from update1.freebsd.org... done. Fetching metadata index... done. Fetching 2 metadata files... done. Inspecting system... done. Preparing to download files... done. Fetching 8 patches..... done. Applying patches... done. The following files will be updated as part of updating to 14.3-RELEASE-p1: /bin/freebsd-version /boot/kernel/zfs.ko /lib/libzpool.so.2 /rescue/[ /rescue/bectl /rescue/bsdlabel /rescue/bunzip2 /rescue/bzcat /rescue/bzip2 /rescue/camcontrol /rescue/cat /rescue/ccdconfig /rescue/chflags /rescue/chgrp /rescue/chio /rescue/chmod /rescue/chown /rescue/chroot /rescue/clri /rescue/cp /rescue/csh /rescue/date /rescue/dd /rescue/devfs /rescue/df /rescue/dhclient /rescue/disklabel /rescue/dmesg /rescue/dump /rescue/dumpfs /rescue/dumpon : root@fbsd-test02-zfs:~ #
freebsd-update install
src component not installed, skipped Creating snapshot of existing boot environment... done. Installing updates... Restarting sshd after upgrade Performing sanity check on sshd configuration. Stopping sshd. Waiting for PIDS: 823. Performing sanity check on sshd configuration. Starting sshd. done. root@fbsd-test02-zfs:~ #
freebsd-version -kru
14.3-RELEASE 14.3-RELEASE 14.3-RELEASE-p1 root@fbsd-test02-zfs:~ #
reboot
After reboot, we can check ZFS snapshots ...
root@fbsd-test02-zfs:~ # bectl list BE Active Mountpoint Space Created 14.3-RELEASE-STATE-2025-07-16 - - 252K 2025-07-15 23:09 14.3-RELEASE_2025-07-15_231751 - - 288K 2025-07-15 23:17 default NR / 1.31G 2025-07-15 22:26 root@fbsd-test02-zfs:~ #
freebsd-version -kru
14.3-RELEASE 14.3-RELEASE 14.3-RELEASE-p1 root@fbsd-test02-zfs:~ #
... and we see, that freebsd-update install did the ZFS snapshot by it self and named it 14.3-RELEASE_2025-07-15_231751. Our booted environment (default) is updated to FreeBSD version 14.3-RELEASE-p1.
If there would be something wrong, we can revert our boot environment to state before FreeBSD update. Let's do it ...
root@fbsd-test02-zfs:~ #
bectl activate 14.3-RELEASE_2025-07-15_231751
Successfully activated boot environment 14.3-RELEASE_2025-07-15_231751 root@fbsd-test02-zfs:~ #
bectl list
BE Active Mountpoint Space Created 14.3-RELEASE-STATE-2025-07-16 - - 252K 2025-07-15 23:09 14.3-RELEASE_2025-07-15_231751 R - 1.26G 2025-07-15 23:17 default N / 51.0M 2025-07-15 22:26 root@fbsd-test02-zfs:~ # freebsd-version -kru 14.3-RELEASE 14.3-RELEASE 14.3-RELEASE-p1 root@fbsd-test02-zfs:~ #
... the current boot environment is still default (N - means active now). Boot environment 14.3-RELEASE_2025-07-15_231751 will be active on next reboot (R - means active on reboot).
Let's reboot the system, and check the boot environment and state of the FreeBSD system.
dpasek@fbsd-test02-zfs:~ $
freebsd-version -kru
14.3-RELEASE 14.3-RELEASE 14.3-RELEASE dpasek@fbsd-test02-zfs:~ $
bectl list
BE Active Mountpoint Space Created 14.3-RELEASE-STATE-2025-07-16 - - 252K 2025-07-15 23:09 14.3-RELEASE_2025-07-15_231751 NR / 1.26G 2025-07-15 23:17 default - - 51.2M 2025-07-15 22:26 dpasek@fbsd-test02-zfs:~ $
After system reboot, we see that our FreeBSD system is back in 14.3-RELEASE without Patch (p1). That's the evidence, we successfully reverted back to boot filesystem snapshot created before FreeBSD update.
Now we can destroy some snapshots which are not needed anymore or switch to FreeBSD 14.3-RELEASE-p1 which is in default boot environment.
USB Device Management
Lot of devices are connected to computer over USB.
Show USB Devices
The usbconfig utility is used to configure and dump information about the USB subsystem.
root@dell5530:~ #
usbconfig list
ugen0.1: <XHCI root HUB Intel> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA) ugen0.2: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA) ugen0.3: <Wireless-AC 9260 Bluetooth Adapter Intel Corp.> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA) ugen0.4: <IntegratedWebcamHD Realtek Semiconductor Corp.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA) ugen0.5: <Hub Genesys Logic, Inc.> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA) ugen0.6: <RTL8153 Gigabit Ethernet Adapter Realtek Semiconductor Corp.> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA) root@dell5530:~ #
Get USB Device Vendor ID and Product ID
We can leverage usbconfig and grep.
From previous command we know that ugen0.6 is Realtek Ethernet Adapter
oot@dell5530:~ #
usbconfig -d ugen0.6 dump_device_desc | grep -E 'idVendor|idProduct'
idVendor = 0x0bda idProduct = 0x8153 root@dell5530:~ #
Dump USB device
root@dell5530:~ #
usbconfig -d ugen0.6 dump_all_desc
ugen0.6: <RTL8153 Gigabit Ethernet Adapter Realtek Semiconductor Corp.> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA) bLength = 0x0012 bDescriptorType = 0x0001 bcdUSB = 0x0300 bDeviceClass = 0x0000 <Probed by interface class> bDeviceSubClass = 0x0000 bDeviceProtocol = 0x0000 bMaxPacketSize0 = 0x0009 idVendor = 0x0bda idProduct = 0x8153 bcdDevice = 0x3000 iManufacturer = 0x0001 <retrieving string failed> iProduct = 0x0002 <retrieving string failed> iSerialNumber = 0x0006 <retrieving string failed> bNumConfigurations = 0x0002 Configuration index 0 bLength = 0x0009 bDescriptorType = 0x0002 wTotalLength = 0x0039 bNumInterfaces = 0x0001 bConfigurationValue = 0x0001 iConfiguration = 0x0000 <no string> bmAttributes = 0x00a0 bMaxPower = 0x0024 Interface 0 bLength = 0x0009 bDescriptorType = 0x0004 bInterfaceNumber = 0x0000 bAlternateSetting = 0x0000 bNumEndpoints = 0x0003 bInterfaceClass = 0x00ff <Vendor specific> bInterfaceSubClass = 0x00ff bInterfaceProtocol = 0x0000 iInterface = 0x0000 <no string> Endpoint 0 bLength = 0x0007 bDescriptorType = 0x0005 bEndpointAddress = 0x0081 <IN> bmAttributes = 0x0002 <BULK> wMaxPacketSize = 0x0400 bInterval = 0x0000 bRefresh = 0x0000 bSynchAddress = 0x0000 Additional Descriptor bLength = 0x06 bDescriptorType = 0x30 bDescriptorSubType = 0x03 RAW dump: 0x00 | 0x06, 0x30, 0x03, 0x00, 0x00, 0x00 Endpoint 1 bLength = 0x0007 bDescriptorType = 0x0005 bEndpointAddress = 0x0002 <OUT> bmAttributes = 0x0002 <BULK> wMaxPacketSize = 0x0400 bInterval = 0x0000 bRefresh = 0x0000 bSynchAddress = 0x0000 Additional Descriptor bLength = 0x06 bDescriptorType = 0x30 bDescriptorSubType = 0x03 RAW dump: 0x00 | 0x06, 0x30, 0x03, 0x00, 0x00, 0x00 Endpoint 2 bLength = 0x0007 bDescriptorType = 0x0005 bEndpointAddress = 0x0083 <IN> bmAttributes = 0x0003 <INTERRUPT> wMaxPacketSize = 0x0002 bInterval = 0x0008 bRefresh = 0x0000 bSynchAddress = 0x0000 Additional Descriptor bLength = 0x06 bDescriptorType = 0x30 bDescriptorSubType = 0x00 RAW dump: 0x00 | 0x06, 0x30, 0x00, 0x00, 0x02, 0x00 root@dell5530:~ #
Power Management
Commands for power management.
Suspend/Resume
On FreeBSD system one can use to enter sleep (S3) state with zzz(8) command.
- To add various tasks that need to happen before sleep happens can be added to the /etc/rc.suspend file.
- To add various tasks that need to happen after sleep ends and resume phase happens, use the /etc/rc.resume file instead.
Display / Graphics Card Management
Commands for managing Display / Graphics CardsShow Display Controller(s)
When you configure graphical desktop environment, you need to know your display controller (graphics card).
pciconf -lv | grep -B 3 -A 1 display
This one-liner helps you identify the PCI display controller(s) [aka graphics card(s)] and shows 3 lines before and one after the line containing the word display for context, including device ID, vendor, and possibly the driver in use.
dpasek@freebsd01:~ $
pciconf -lv | grep -B 3 -A 1 display
vgapci0@pci0:0:15:0: class=0x030000 rev=0x00 hdr=0x00 vendor=0x15ad device=0x0405 subvendor=0x15ad subdevice=0x0405 vendor = 'VMware' device = 'SVGA II Adapter' class = display subclass = VGA
No comments:
Post a Comment