Run /etc/rc.local in Windows subsystem for Linux

user-pic
Vote 0 Votes

Windows 10 的 Linux 子系統 (Windows subsystem for Linux, WSL) 因為不是走一般的開機流程,
所以服務都不會啟動, 也包含了 /etc/rc.local
若要在開啟 WSL 視窗時執行 rc.local, 做法如下(Ubuntu環境)

# 設定 sudo 免密碼
echo "yourusername ALL=(root) NOPASSWD: ALL" >> /etc/sudoers
# 在 bash.bashrc 最後觸發啟動 rc.local
echo "sudo /etc/rc.local &" >> /etc/bash.bashrc

建立 /etc/rc.local, 下面內容是啟動 Apache 的範例, 每開一次視窗, 就會被觸發執行.
加在這裡的 script, 需考慮到多開視窗, 就會啟動多次的情況, 所以用 pidof 判斷服務是否已經在跑了, 沒有才啟動服務.

#!/bin/bash
pidof -s apache2 > /dev/null || service apache2 start 2>/dev/null

About this Entry

This page contains a single entry by Pank published on May 30, 2019 10:06 AM.

Fixed Windows 10 overscan/underscan issues on an ATI card without Catalyst Control Center was the previous entry in this blog.

Basic IPv6 firewall rule for RouterOS is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives