Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 9th August 2022
J65nko J65nko is offline
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,136
Default Logging OpenBSD virtual machine console output

A shell script to start an OpenBSD VM and log the console input/output to an unique log file
The name of the logs start with the VM name followed by DDMM_HHMMSS.log
18259 Aug  1 04:15 vmlogs/alix_new0731_221336.log
11549 Aug  9 04:39 vmlogs/alix_new0809_043239.log
This name is created with:

LOGFILE="${LOGDIR}/${VMNAME}$(date -j   "+%m%d_%H%M%S").log"
For customizing this format, see date(1) and strftime(3)
Some alternatives shown on the shell command line:
$ date -j   "+%m%d_%H:%M:%S"                                  

$ date -j   "+%m%d_%H_%M_%S" 

$ date -j   "+%b%d_%H_%M_%S"
The following snippet from the script shows how you could start the script:
# if variable VMNAME is not defined you will be prompted to select a VM

# USAGE options:

# 1) $ env VMNAME=alix_new ./dovm.sh
# 2) $ export VMNAME=alix_new ; ./dovm.sh
# 3) Define the shell variable VMNAME in the script
# 4) Just run './dovm.sh' and select a stopped VM from a menu
# 5) If you place it in your $HOMEDIR/bin directory: $ dovm.sh
Using the interactive method 4:
$ dovm.sh
    1     -     1    1.0G       -       - adriaan:wheel  stopped df-us
    2     -     1    1.0G       -       - adriaan:wheel  stopped siralas-clone
    3     -     1    1.0G       -       - adriaan:wheel  stopped hetzner
    4     -     1    500M       -       - adriaan:wheel  stopped alix_new
Select 'ID' number of VM to start : 3
Script started on Tue Aug  9 05:56:44 2022
Connected to /dev/ttypb (speed 115200)
Using drive 0, partition 3.
probing: pc0 com0 mem[638K 1022 a20=on]
disk: hd0+
>> OpenBSD/amd64 BOOT 3.53

com0: 115200 baud
switching console to com0
>> OpenBSD/amd64 BOOT 3.53
root@df-us[~]shutdown -hp now
Shutdown NOW!
shutdown: [pid 33853]
*** FINAL System shutdown message from root@df-us.utp.xnet ***               
System going down IMMEDIATELY                                                  
System shutdown time has arrived

root@df-us[~]syncing disks... done
vmmci0: powerdown

The operating system has halted.
Please press any key to reboot.
Instead of rebooting we press '~." ( tilde followed by a dot) to exit the console.
Script done, output file is /home/adriaan/vmlogs/hetzner0809_055644.log
You will then see a hint to use col(1) to sanitize 'download progress meter' lines:
HINT: You can use col(1) to filter out backspaces on messy lines like this:
    ^MGet/Verify SHA256.sig     0% |                          |     0
    --:-- ETA^MGet/Verify SHA256.sig   100% |**************************|
    2144       00:00 Signature Verified ^MGet/Verify bsd            0%
    |                          |     0       --:-- ETA^MGet/Verify bsd
    8% |**                        |  1792 KB    00:11 ETA^MGet/Verify
    bsd           17% |****

    For example:

    $ col -b <df-us0724_023205.log | less

    Get/Verify SHA256.sig   100% |**************************|  2144       00:00 ETA
    Signature Verified
    Get/Verify bsd          100% |**************************| 22339 KB    00:11 ETA
    Get/Verify bsd.rd       100% |**************************|  4498 KB    00:02 ETA

    Neat huh?
You can disable this hint by setting the variable SHOW_COL_HINT to 0:
Attached Files
File Type: txt dovm.sh.txt (2.9 KB, 18 views)
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 9th August 2022 at 04:32 AM.
Reply With Quote

virtual machine, virtualization, vmctl, vmm

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Machine J65nko OpenBSD General 8 9th May 2019 12:21 AM
Running Virtual Machine Manager on OpenBSD Host! mbzadegan OpenBSD Packages and Ports 1 22nd May 2017 10:01 AM
Create OpenBSD guest for Linux KVM (Kernel-based Virtual Machine) with 'virt-install' J65nko Guides 4 11th December 2014 04:30 AM
can't login on virtual console spermwhale_warrior OpenBSD General 3 19th July 2014 05:05 PM
Network failure and output dumping onto console JMJ_coder NetBSD General 17 17th May 2008 02:27 AM

All times are GMT. The time now is 02:19 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick