windows subsystem for linux – qemu error in kwsl desktop environment

I wanted to run macos on qemu so I downloaded code from https://github.com/kholia/OSX-KVM and installed it on wsl2 (ubuntu). However, the mouse cursor often doesn’t move in the virtual machine using wslg (and I had to restart every time this happens…) so I tried having a desktop environment instead and installed kwsl. The vm could start normally using windows terminal, but in the desktop environment, it didn’t start and instead gave me errors:

$ sudo ./OpenCore-Boot.sh
No protocol specified
Unable to init server: Could not connect: Connection refused
QEMU 4.2.1 monitor - type 'help' for more information
(qemu) ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
audio: Failed to create voice `dac'
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize ADC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize ADC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
audio: Failed to create voice `adc'
gtk initialization failed

OpenCore-Boot.sh:

#!/usr/bin/env bash

# Special thanks to:
# https://github.com/Leoyzen/KVM-Opencore
# https://github.com/thenickdude/KVM-Opencore/
# https://github.com/qemu/qemu/blob/master/docs/usb2.txt
#
# qemu-img create -f qcow2 mac_hdd_ng.img 128G
#
# echo 1 > /sys/module/kvm/parameters/ignore_msrs (this is required)

############################################################################
# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems!
############################################################################

MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"

# This script works for Big Sur, Catalina, Mojave, and High Sierra. Tested with
# macOS 10.15.6, macOS 10.14.6, and macOS 10.13.6

ALLOCATED_RAM="3072" # MiB
CPU_SOCKETS="1"
CPU_CORES="2"
CPU_THREADS="4"

REPO_PATH="."
OVMF_DIR="."

# This causes high cpu usage on the *host* side
# qemu-system-x86_64 -enable-kvm -m 3072 -cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,hypervisor=off,vmx=on,kvm=off,$MY_OPTIONS

# shellcheck disable=SC2054
args=(
  -enable-kvm -m "$ALLOCATED_RAM" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS"
  -machine q35
  -usb -device usb-kbd -device usb-tablet
  -smp "$CPU_THREADS",cores="$CPU_CORES",sockets="$CPU_SOCKETS"
  -device usb-ehci,id=ehci
  # -device usb-kbd,bus=ehci.0
  # -device usb-mouse,bus=ehci.0
  # -device nec-usb-xhci,id=xhci
  -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
  -drive if=pflash,format=raw,readonly,file="$REPO_PATH/$OVMF_DIR/OVMF_CODE.fd"
  -drive if=pflash,format=raw,file="$REPO_PATH/$OVMF_DIR/OVMF_VARS-1024x768.fd"
  -smbios type=2
  -device ich9-intel-hda -device hda-duplex
  -device ich9-ahci,id=sata
  -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore-Catalina/OpenCore.qcow2"
  -device ide-hd,bus=sata.2,drive=OpenCoreBoot
  -device ide-hd,bus=sata.3,drive=InstallMedia
  -drive id=InstallMedia,if=none,file="$REPO_PATH/BaseSystem.img",format=raw
  -drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
  -device ide-hd,bus=sata.4,drive=MacHDD
  # -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
  -netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
  -monitor stdio
  -device VGA,vgamem_mb=128
)

qemu-system-x86_64 "${args(@)}"

I just deleted everything on my windows system through the ubuntu subsystem. Can I recover the data?

I am an idiot.

I wanted to delete all my ubuntu related files from the ubuntu subsystem within windows. So I just sudo rm -rf /* in the ubuntu home directory. I did sudo because earlier there were a lot of permission denied. Now when there were less permission denied, I started getting all sorts of other errors from windows and then I realized it was also deleting files outside of ubuntu. Now everything is working weird even in windows. I just canceled the command with ctrl+C as soon as I realized but too much has been damaged. Any way to fix this? Any way to reverse the last command?
Please help!

dd – Can’t make a live USB using Linux subsystem

I’m trying to install Linux-lite
Tried Rufus but uefi option didn’t show up in boot sequence.
So I thought I would use the dd command using Linux bash on Windows.

Obviously lsblk doesn’t work
So I got the physical-name from PowerShell

Get-CimInstance  Win32_DiskDrive | Select Caption,DeviceID,InterfaceType,Size | Where-Object {$_.InterfaceType -eq "USB"}

Output

Caption                         DeviceID           InterfaceType        Size
-------                         --------           -------------        ----
SanDisk Cruzer Blade USB Device \.PHYSICALDRIVE2 USB           15373048320

Which I tried in Linux terminal

sudo mkfs.vfat -I \.PHYSICALDRIVE2

But I got this error

mkfs.fat 4.1 (2017-01-24)
mkfs.vfat: unable to open .PHYSICALDRIVE2: No such file or directory

I’m stuck here and I don’t know how to move forward with installation.

windows subsystem for linux – Install under WSL2 with default non-root username BESIDES value of %USERNAME%

Years ago, I started using ‘root’ as my Windows username. Yeah, I know… in retrospect, it wasn’t a great idea, but it seemed cute and harmless back when the closest Windows and Linux ever really got to each other was booting from independent primary partitions or running as VirtualBox guests of each other.

Anyway… I enabled WSL2, installed Ubuntu 20.04 from the Microsoft store, then discovered that the resulting virtual installation apparently picked up ‘root’ from %USERNAME% and made a mess.

I’m not averse to just blowing it away and starting over with the Ubuntu installation, but I’m scratching my head trying to figure out how to keep the installer from doing the exact same thing the next time around. I’m sure there HAS to be a way to set an environment variable or something that tells the installer to use something besides the current value of %USERNAME%… but I’m not sure what it is. Does anybody know?

windows subsystem for linux – How to upgrade ubuntu 18.04 to 20.04 in WSL when “wsl –export” fails

I’m trying to follow the directions to upgrade my WSL 1 Ubunutu (18.04) release to WSL 2 Ubuntu-20.04 and the first step gives me an error message I don’t know how to work around.

wsl --set-version ubuntu 
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Exporting the distribution failed.
bsdtar: Couldn't read link data: I/O error
bsdtar: Error exit delayed from previous errors.

I have also tried doing it the “normal” Ubuntu way and get different “errors”:

$ lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:    18.04
Codename:   bionic
cfclark@p53:
~
$ sudo apt update

Hit:1 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
cfclark@p53:
~
$ sudo apt upgrade

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  libdumbnet1
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
cfclark@p53:
~
$ sudo do-release-upgrade

Checking for a new Ubuntu release
Get:1 Upgrade tool signature (1554 B)                                                                                                                                                                       
Get:2 Upgrade tool (1340 kB)                                                                                                                                                                                
Fetched 1342 kB in 0s (0 B/s)                                                                                                                                                                               
authenticate 'focal.tar.gz' against 'focal.tar.gz.gpg' 
extracting 'focal.tar.gz'
(4l>7(r(?1;3;4;6l87(4l=)0(1;66rlspci: Cannot find any working access method.

Checking package manager
Reading package lists... Done
Building dependency tree
Reading state information... Done
Hit http://archive.ubuntu.com/ubuntu bionic InRelease
Hit http://ppa.launchpad.net/git-core/ppa/ubuntu bionic InRelease
Hit http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit http://security.ubuntu.com/ubuntu bionic-security InRelease
Fetched 0 B in 0s (0 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done

Restoring original system state

Aborting
Reading package lists... Done
Building dependency tree
Reading state information... Done
=== Command detached from window (Sun May 23 13:26:05 2021) ===
=== Command terminated with exit status 1 (Sun May 23 13:26:15 2021) ===

networking – Packets loss inside LAN for Windows 10 with Ubuntu sub-system

I am trying to reach win10 machine inside my LAN. It is accessible from other machines just fine. But I am having troubles with one specific machine. It has also OS Windows 10 with Ubuntu 18 subsystem. When I am pinging from windows cmd it has packets loss up to 25%-100%. When I ping same IP from Ubuntu it doesn’t have any packets loss. Are there any network settings were affected when I installed sub-system? And how to trouble shoot and fix this issue? Disabling firewall on Windows didn’t have any effect.
I tried to check firewall on Ubuntu with ufw status but got

ERROR: problem running iptables: iptables v1.6.1: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

Pings from Windows and Ubuntu difference

Would really appreciate any advice. Thank you!

firewall – Determining/associating the log subsystem for apps installed via package managers

I’ve watched this highly informative talk on the unified logs and been reading whatever documentation or blog posts I can find on the subject, but I haven’t found or don’t understand how to link an app (for example, an SSHD server) that has been installed via, say Macports or pkgsrc, to a subsystem.

Is it something the developer has to specify within the code? I use launchctl plists quite often, is it something I can add there? (the man page has nothing on it, same goes for the log man page)

If I list the files in /System/Library/Preferences/Logging/Subsystems/ and /Library/Preferences/Logging/Subsystems/ there’s a lot of plists that Apple call “logging profiles”. The /Library/… one has com.openssh.sshd.plist with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>DEFAULT-OPTIONS</key>
    <dict>
        <key>Level</key>
        <dict>
            <key>Enable</key>
            <string>default</string>
        </dict>
    </dict>
</dict>
</plist>

I can’t see if this applies to:

  • only the SSHD supplied by Apple in /usr/sbin/sshd
  • any SSHD run on the machine
  • the sshd entry in /etc/services
  • something else…

Perhaps I can write a logging profile and place it in there for apps I install? Are apps automatically placed in subsystems because of system resources they ask for? I’m just not sure.

Sorry if the question is confusing, it’s because I’m confused! Any help or insight given will be much appreciated.

Note: The system I’m currently on is 10.14 but I’m asking in a general way as I know the unified logs came in after 10.10 and (as the talk points out) there are slight differences even between OS minor versions.

windows subsystem for linux – How to change the right cuda version in WSL

I worked on the WSL-ubuntu1804, And I installed the cuda, tensorrt, pytorch, and some package I forget. Now I run the nvcc -V on the bash shell, it show me :

(torch1.6) sanwz@DESKTOP-NHKU0MT:/usr/local$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

so I find the nvcc file at /usr/local/cuda/bin and run ./nvcc -V
I got the right info:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

The cuda folder at /usr/local/ linking to the /usr/local/cuda-10.2
enter image description here
and there is only one folder like cuda-*

Does it mean my default cuda compiler driver version is 9.0? How should I change it .

I received a phishing/spam email from Google Delivery Subsystem about an email I never sent. How?

Screenshot:

enter image description here

The text covered with red is exactly my email address except the end is @google.com instead of @gmail.com.

The suspicious link “Unsubscribe_click_here” is:
mailto:cr@burlondesti.com,kz@grendeoszel.com,ma@bindolamiats.com,couar.ort@gmail.com,krandelowez@foxmail.com,3561036101@qq.com,jacques.chirac088@gmail.com,sosiea0@outlook.com?Subject=.Unsubcribe%20now//

If I expand email details to show more info:

enter image description here

Yellow is my email address. The sender’s email address is legitimate, so are all the other details.

Here are screenshots of a legitimate email from Mail Delivery Subsystem that I received recently for comparison:

Legit email

enter image description here

How is this possible? I definitely did not send that email and I’m pretty sure my gmail was not accessed by someone else (Google would have alerted me). This is the first time I see this. It seems whoever did this was somehow able to trick the google delivery system to think that I sent that email.

mount – Mounting SMB Share in Windows Subsystem for Linux (Ubuntu)

How can I connect to a SMB share from Ubuntu running in Windows Subsystem for Linux (WSL)?

This took me a while to sift through, a lot of questions and answers have been posted throughout the years, and some put me on the right track, but it still took me more than a day to do it.

First here is my setup:

Client: Windows 10 Home 20H2 19042.804 | Ubuntu for WSL 20.04.2 LTS build 20210222
Server: FreeBSD 12.1-RELEASE
Network: Class C

Purpose

Briefly, my purpose was to have a unified home directory across my various accounts on my machines, and virtual machines.

So in more words, this is quite a very simple setup, but my purpose was to have a single home directory across all my machines. So right now, my home directory on my Windows machine is the same as my home directory on my FreeBSD server, and now, finally, also on my Linux account on Ubuntu for WSL.

The advantages of this should be obvious: it’s just a lot more comfortable to work. I also have this file manager called CX File Manager on my Android phone that can connect to my NFS share, so putting all my pictures and videos on my server when my phone gets full is a breeze! I just move the DCIM folder to the SMB share, and it does it in the background while I sleep, or whatever.

Method

Some of you might be drooling already, so here’s how.

  1. Your NFS share has to be added to your Windows account as a drive. You go in the File Explorer > Map Network Drive > Enter the information, assign a drive letter. Mine is Z: for my personal home directory.

  2. Then you add this line to /etc/fstab in Ubuntu for WSL

    //192.168.0.110/ /home/ drvfs auto,rw,nosuid,exec,uid=<1000>,gid=<1000> 0 0

Of course, you’ll want to plug in the right names, the UID/GID of your user on your server, and make sure it fits your requirements, but that’s essentially it!

Explanation

Because Ubuntu for Linux doesn’t support CIFS, you need to use drvfs instead of mounting your share directly from Ubuntu. You can also specify the drive letter instead of the SMB share name (Z: instead of 192.168.0.110), but that makes so you can’t use the drive in Windows anymore, Ubuntu takes sole control of the drive, and it shows as being disconnected in Windows, so that wasn’t extremely useful.

It shouldn’t work

This isn’t backed-up by any documentation, but your credentials are already stored in Windows. As we saw, you could specify your Windows drive letter instead of the share name, and it would kinda work, but Windows would see the drive as busy, however we know drvfs is “using those credentials”, or at least it’s mounting through the Windows SMB share that’s already connected with your credentials. Somehow, specifyinng the share name instead of the drive letter allows us to use the drive in both WSL, and Windows, at the same time.

I’ve just managed to get this to work, I’ve not seen any conflicts, sync problems, etc. but if you’re not too hard on it, it should work just fine. Most code editors recognize external changes to files anymore, now, anyway, and that’s probably what’s going to be happening with it. I just tested with vi, and it said the file was modified, Windows saw the file on the share right away… Looks like it’s working pretty solid.