{"id":6740,"date":"2022-06-08T10:08:46","date_gmt":"2022-06-08T08:08:46","guid":{"rendered":"https:\/\/blog.via-internet.de\/?p=6740"},"modified":"2022-11-05T14:05:42","modified_gmt":"2022-11-05T13:05:42","slug":"wsl-cookbook","status":"publish","type":"post","link":"https:\/\/via-internet.de\/blog\/2022\/06\/08\/wsl-cookbook\/","title":{"rendered":"WSL | Cookbook"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/wsl\/wsl-config\" target=\"_blank\" rel=\"noreferrer noopener\">wsl.conf<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample wsl.conf<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[boot]\nsystemd=true\n\n[network]\nhostname = playground\ngenerateHosts = false<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Basics<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Run specify distribution<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> wsl --distribution Ubuntu-22.04<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> wsl -d Ubuntu-22.04<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Run Distribution and login as root<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wsl -d Debian -u root<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Change root password<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> wsl.exe --user root --distribution Alpine passwd<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Running X Apps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/nickjanetakis.com\/blog\/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows\">https:\/\/nickjanetakis.com\/blog\/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows<\/a><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export DISPLAY=\"$(\/sbin\/ip route | awk '\/default\/ { print $3 }'):0\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Boot Configuration<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">systemd<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"set-the-systemd-flag-set-in-your-wsl-distro-settings\">Set the systemd flag set in your WSL distro settings<a href=\"https:\/\/devblogs.microsoft.com\/commandline\/systemd-support-is-now-available-in-wsl\/#set-the-systemd-flag-set-in-your-wsl-distro-settings\"><\/a><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You will need to edit the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/windows\/wsl\/wsl-config#wslconf\" target=\"_blank\" rel=\"noreferrer noopener\">wsl.conf<\/a>&nbsp;file to ensure systemd starts up on boot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add these lines to the&nbsp;<code>\/etc\/wsl.conf<\/code>&nbsp;(note you will need to run your editor with sudo privileges, e.g:&nbsp;<code>sudo nano&nbsp;\/etc\/wsl.conf<\/code>):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[boot]\nsystemd=true<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And close out of the nano editor using&nbsp;<code>CTRL+O<\/code>&nbsp;to save and&nbsp;<code>CTRL+X<\/code>&nbsp;to exit.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"final-steps\">Final Check<a href=\"https:\/\/devblogs.microsoft.com\/commandline\/systemd-support-is-now-available-in-wsl\/#final-steps\"><\/a><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Close your WSL distro Windows and run\u00a0<code>wsl.exe\u00a0--shutdown<\/code>\u00a0from PowerShell to restart your WSL instances. Upon launch you should have systemd running. You can check this with<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl list-unit-files\u00a0--type=service<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Change Hostname<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Edit \/etc\/wsl.conf<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[network]\nhostname = wsl2\ngenerateHosts = false<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change the hostname in \/etc\/hosts and \/etc\/hostname<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to \/etc\/wsl.conf:\n# [network]\n# generateHosts = false\n127.0.0.1      localhost\n127.0.1.1      wsl2.localdomain        wsl2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Shutdown wsl<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wsl --shutdown<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Distributions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Create a new Distribution<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Export a distribution<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wsl --export Ubuntu-22.02 ubuntu.tar<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Import with new name<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wsl --import MyUbuntu D:\\WSL\\Distributions\\MyUbuntu ubuntu.tar<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Configuration wsl.conf Sample wsl.conf Basics Run specify distribution Run Distribution and login as root Change root password Running X Apps https:\/\/nickjanetakis.com\/blog\/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows Boot Configuration systemd Set the systemd flag set in your WSL distro settings You will need to edit the&nbsp;wsl.conf&nbsp;file to ensure systemd starts up on boot. Add these lines to the&nbsp;\/etc\/wsl.conf&nbsp;(note you will need to run your editor with sudo privileges, e.g:&nbsp;sudo nano&nbsp;\/etc\/wsl.conf): And close out of the nano editor using&nbsp;CTRL+O&nbsp;to save and&nbsp;CTRL+X&nbsp;to exit. Final Check Close your WSL distro Windows and run\u00a0wsl.exe\u00a0&#8211;shutdown\u00a0from PowerShell to restart your WSL instances. Upon launch you should have systemd running. You can check this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[16,143],"tags":[],"class_list":["post-6740","post","type-post","status-publish","format-standard","hentry","category-cookbook","category-windows-subsystem-for-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/6740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/comments?post=6740"}],"version-history":[{"count":7,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/6740\/revisions"}],"predecessor-version":[{"id":10219,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/6740\/revisions\/10219"}],"wp:attachment":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media?parent=6740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/categories?post=6740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/tags?post=6740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}