So something like this.
You can adjust the minutes variable to for how many minutes you want it to create log files for, it then counts down from there and temporarily configure sudo to not ask for your password and then run it from your user shell or create a cronjob to make start at time X. Then afterwards you screen crashes/freezes and you reboot your machine you will have a directory with dmesg files with a date and timestamp, then go through the file with the correct timestamp from around when your screen crash/freeze occurred.
#!/bin/bash if [[ ! -d $HOME/dmesg_output ]] then mkdir -p $HOME/dmesg_output fi minutes=180 until [[ minutes -eq 0 ]] do sudo dmesg > $HOME/dmesg_output/$(date +%R%S-%F)-dmesg.txt minutes=$(($minutes - 1)) echo $minutes sleep 60 done