crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.26k stars 242 forks source link

[BUG]"crc start" can't add CRC section to hosts file and deletes existing section #4251

Open megascus opened 4 months ago

megascus commented 4 months ago

General information

CRC version

CRC version: 2.37.1+36d451
OpenShift version: 4.15.14

CRC status

DEBU CRC version: 2.37.1+36d451
DEBU OpenShift version: 4.15.14
DEBU Running 'crc status'
CRC VM:          Running
OpenShift:       Unreachable (v4.15.14)
RAM Usage:       716MB of 20.98GB
Disk Usage:      21.35GB of 32.68GB (Inside the CRC VM)
Cache Usage:     71.53GB
Cache Directory: C:\Users\megas\.crc\cache

CRC config

- consent-telemetry                     : no
- memory                                : 20480

Host Operating System

ホスト名:               DESKTOP5
OS 名:                  Microsoft Windows 11 Pro
OS バージョン:          10.0.22631 N/A ビルド 22631
OS 製造元:              Microsoft Corporation
OS 構成:                スタンドアロン ワークステーション
OS ビルドの種類:        Multiprocessor Free
登録されている所有者:   megascus@msn.com
登録されている組織:     N/A
プロダクト ID:          00355-60723-44496-AAOEM
最初のインストール日付: 2022/09/22(木), 8:13:38
システム起動時間:       2024/06/14(金), 8:52:09
システム製造元:         Thirdwave Corporation
システム モデル:        XF
システムの種類:         x64-based PC
プロセッサ:             1 プロセッサインストール済みです。
                        [01]: Intel64 Family 6 Model 151 Stepping 2 GenuineIntel ~2100 Mhz
BIOS バージョン:        American Megatrends Inc. 1402A, 2022/04/01(金)
Windows ディレクトリ:   C:\WINDOWS
システム ディレクトリ:  C:\WINDOWS\system32
起動デバイス:           \Device\HarddiskVolume1
システム ロケール:      ja;日本語
入力ロケール:           ja;日本語
タイム ゾーン:          (UTC+09:00) 大阪、札幌、東京
物理メモリの合計:       130,813 MB
利用できる物理メモリ:   90,704 MB
仮想メモリ: 最大サイズ: 150,269 MB
仮想メモリ: 利用可能:   107,140 MB
仮想メモリ: 使用中:     43,129 MB
ページ ファイルの場所:  C:\pagefile.sys
ドメイン:               WORKGROUP
ログオン サーバー:      \\DESKTOP5
ホットフィックス:       6 ホットフィックスがインストールされています。
                        [01]: KB5037591
                        [02]: KB5012170
                        [03]: KB5027397
                        [04]: KB5039212
                        [05]: KB5037663
                        [06]: KB5037959
ネットワーク カード:    3 NIC(s) インストール済みです。
                        [01]: Wintun Userspace Tunnel
                              接続名:           OpenVPN Wintun
                              状態:          メディアは接続されていません
                        [02]: TAP-Windows Adapter V9
                              接続名:           ローカル エリア接続
                              状態:          メディアは接続されていません
                        [03]: Realtek Gaming 2.5GbE Family Controller
                              接続名:           イーサネット
                              DHCP が有効:      はい
                              DHCP サーバー:    192.168.11.1
                              IP アドレス
                              [01]: 192.168.11.20
                              [02]: fe80::a56e:bd94:56e:633a
                              [03]: 2408:211:32d:6500:3938:30b5:6061:ae22
                              [04]: 2408:211:32d:6500:ebbf:c4e1:af0f:f484
Hyper-V の要件:         ハイパーバイザーが検出されました。Hyper-V に必要な機能は表示されません。

Steps to reproduce

  1. crc setup
  2. crc start

Expected

OpenShift Local could start.

Actual

OpenShift Local could not start. And, "crc start" deleted existing section, like "127.0.0.1 localhost" Error message: Error running post start: can't add CRC section, check hosts file

Logs

INFO Using bundle path C:\Users\megas\.crc\cache\crc_hyperv_4.15.14_amd64.crcbundle
INFO Checking minimum RAM requirements
INFO Check if Podman binary exists in: C:\Users\megas\.crc\bin\oc
INFO Checking if running in a shell with administrator rights
INFO Checking Windows release
INFO Checking Windows edition
INFO Checking if Hyper-V is installed and operational
INFO Checking if Hyper-V service is enabled
INFO Checking if crc-users group exists
INFO Checking if current user is in crc-users and Hyper-V admins group
INFO Checking if vsock is correctly configured
INFO Checking if the win32 background launcher is installed
INFO Checking if the daemon task is installed
INFO Checking if the daemon task is running
INFO Checking admin helper service is running
INFO Checking SSH port availability
INFO Loading bundle: crc_hyperv_4.15.14_amd64...
INFO Starting CRC VM for openshift 4.15.14...
INFO CRC instance is running with IP 127.0.0.1
INFO CRC VM is running
Error running post start: can't add CRC section, check hosts file

Before gather the logs try following if that fix your issue

$ crc delete -f
$ crc cleanup
$ crc setup
$ crc start --log-level debug

Please consider posting the output of crc start --log-level debug on http://gist.github.com/ and post the link in the issue. https://gist.github.com/megascus/b0caac285a5b0854a0118ed62a94e82e

hosts: https://gist.github.com/megascus/9916cf196a61638a89a321fe42632aaa

gbraad commented 4 months ago

Hmmmmm.... this is weird. Multiple sections are created:

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section

# Added by CRC
# End of CRC section
gbraad commented 4 months ago

This is related to: https://github.com/crc-org/admin-helper/blob/ec8d66df562a5f3b900e12dbcac0d9c48a1bcae7/pkg/hosts/hosts.go#L32 and https://github.com/crc-org/admin-helper/blob/ec8d66df562a5f3b900e12dbcac0d9c48a1bcae7/pkg/hosts/hosts.go#L300-L322

gbraad commented 4 months ago

@megascus Has the file been modified before with notepad? Perhaps the codepage got changed, as the findCrcSection code seems to fail.

megascus commented 4 months ago

@gbraad Yes. I made changes in a text editor. At that time, I added 127.0.0.1 localhost".

Also, I just tried with a blank hosts file(0byte) and the result was the same.(same hosts, same error)

I checked the character encoding with the text editor and it appears that the result's hosts file does not contain any characters other than UTF-8.

gbraad commented 4 months ago

does not contain any characters other than UTF-8.

Hmmm... snce you're on a non-ASCII/English version of Windows I might think the file got wrongly interpreted, as this has been observed before with GB2312 as codepage.

What if the file gets recreated (no file)? If still the same, we can completely exclude this.

megascus commented 4 months ago

I tried with no hosts file.

In that case, the error was: Error running post start: host file not writable, try running with elevated privileges

Also, additional information, as of March I have successfully installed. (The version of OpenShift Local was 4.14.2, although the version of CRC is unknown.)

gbraad commented 4 months ago

Error running post start: host file not writable, try running with elevated privileges

Interesting... kinda like expected, but also unfortunate we can not resolve this ;-)

Also, additional information, as of March I have successfully installed.

So this has worked before?????!??? hmmmmm... Did you install any other software, like antivirus since then? The error comes from a process called win32-admin-helper that is part of CRC to allow a regular user to write to this file.

We haven't changed anything recently in this process, so asking @anjannath if he has some clues.

megascus commented 4 months ago

I remembered that I installed PowerToys. It has the ability to change the hosts file. I don't have time today so I will uninstall and try it later.

https://learn.microsoft.com/en-us/windows/powertoys/

gbraad commented 4 months ago

Interesting... it could be that this tool keeps a lock on the file and reorders (will have to test), but in that case I think other tools would also be affected.

gbraad commented 4 months ago

https://github.com/microsoft/PowerToys/tree/main/src/modules/Hosts/Hosts

Did the tool run during the time you were using CRC?

gbraad commented 4 months ago

I am not a huge fan of bloat, and PowerToys have always been this since Windows 9x. The newer tools felt no different... and even more so it seems:

image

It feels a lot more is kept on in the background, and might cause issues. We will have a look at this, as this might be the case. However, a simple "Disable" for the Hosts File Editor on your end would be a simpel test too that would not need Uninstall.

megascus commented 4 months ago

I have successfully installed it.

I uninstalled PowerToys and rebooted. And then I could install it.

Thank you for your cooperation. It seems difficult to determine the cause, but as information sharing.

hosts file is as following (from 0 byte). https://gist.github.com/megascus/f8573c754e6a37901d38248f1916d06f

(It did not work well with just DISABLED. Thanks.)

megascus commented 4 months ago

https://github.com/microsoft/PowerToys/tree/main/src/modules/Hosts/Hosts

Did the tool run during the time you were using CRC?

No, it didn't. However, PowerToys seems to change the permissions on the hosts file. When I uninstalled PowerToys, it asked for UAC when changing the hosts file, otherwise UAC was not required.

megascus commented 4 months ago

I am satisfied because my immediate problem has been solved. Please close this ticket if necessary.