スクリプトをコンパイルし、システムの起動前(または途中)で実行するようにシステムに追加します。

スクリプトをコンパイルし、システムの起動前(または途中)で実行するようにシステムに追加します。

どうすればいいのか分からないので、ここにいるすべての人に助けを求めます。

簡単に言えば、背景の詳細

私のRaspberry Pi 5にはUSB3 2.5gb NICが接続されています。(このSBCには独自の1GB NICも内蔵されています)。オペレーティングシステムRaspberry Pi OS Lite 64ビットをインストールしました。Debian バージョン: 12 (nerdy)- はい、すべてが更新されました。

ネットワークとネットワークカードが設定されている詳細/投稿は次のとおりです。

  • USB3 NICを基本/基本インターフェイスとして使用したいです。

質問 起動/再起動するたびに(しばしば終了および開始も可能)USB3 NICを取り外して再接続して物理的に切断する必要がありました。

インターネットで検索しながら、いくつかのコマンドを提案する投稿を見つけました。私の考えではこれはスクリプトにスタックして実行できます。 Ubuntuそしてこの記事はGeekLandから抜粋したものです。すべてが詳細に説明されています。スペイン語で書かれているので、Google翻訳などを使用してください。

私の質問は。 誰かが親切にこれをより永続的な方法で実行し、それを私のシステムに実装する方法を説明できますか?

私の究極の目標は。何らかの方法で私のシステムブートスクリプトに影響を与えますusb3nic.shUSB3 NICを切断して再接続するためのコードを含むスクリプト(それが最善の解決策であれば)スクリプトを開始する前に実行されます私の論理的な考えでは、これが私が経験している問題を解決することができるでしょう。これは一種のカーネル問題のようです。

私はまた、すべての人にコンパイルを手伝ってくれて親切に頼む。usb3nic.shこれについての私の知識は非常に限られているので、これはシステムの起動を妨げるので、基本的に恐ろしい部分です。

これが出力ですそう思います。これらのスクリプトを作成するには、次のものが必要です。

sudo lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0bda:8156 Realtek Semiconductor Corp. USB 10/100/1G/2.5G LAN
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
sudo lsusb -t
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
ls -l /sys/bus/usb/devices/
total 0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 1-0:1.0 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 2-0:1.0 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 2-1 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb2/2-1
lrwxrwxrwx 1 root root 0 Apr 28 14:24 2-1:1.0 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb2/2-1/2-1:1.0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 3-0:1.0 -> ../../../devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3/3-0:1.0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 4-0:1.0 -> ../../../devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb4/4-0:1.0
lrwxrwxrwx 1 root root 0 Apr 28 14:24 usb1 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb1
lrwxrwxrwx 1 root root 0 Apr 28 14:24 usb2 -> ../../../devices/platform/axi/1000120000.pcie/1f00200000.usb/xhci-hcd.0/usb2
lrwxrwxrwx 1 root root 0 Apr 28 14:24 usb3 -> ../../../devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3
lrwxrwxrwx 1 root root 0 Apr 28 14:24 usb4 -> ../../../devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb4
lsusb -v
Bus 002 Device 003: ID 0bda:8156 Realtek Semiconductor Corp. USB 10/100/1G/2.5G LAN
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.20
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         9
  idVendor           0x0bda Realtek Semiconductor Corp.
  idProduct          0x8156
  bcdDevice           31.00
  iManufacturer           1 Realtek
  iProduct                2 USB 10/100/1G/2.5G LAN
  iSerial                 6 001000001
  bNumConfigurations      3
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0039
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              256mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval              11
        bMaxBurst               0
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0068
    bNumInterfaces          2
    bConfigurationValue     2
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              256mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass     13
      bInterfaceProtocol      0
      iInterface              5
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      CDC Ethernet:
        iMacAddress                      3 (??)
        bmEthernetStatistics    0x0031501f
        wMaxSegmentSize               1518
        wNumberMCFilters            0x8000
        bNumberPowerFilters              0
      CDC NCM:
        bcdNcmVersion        1.00
        bmNetworkCapabilities 0x2b
          8-byte ntb input size
          max datagram size
          net address
          packet filter
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              11
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      1
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      1
      iInterface              4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0062
    bNumInterfaces          2
    bConfigurationValue     3
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              256mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      6 Ethernet Networking
      bInterfaceProtocol      0
      iInterface              5
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      CDC Ethernet:
        iMacAddress                      3 (??)
        bmEthernetStatistics    0x0031501f
        wMaxSegmentSize               1518
        wNumberMCFilters            0x8000
        bNumberPowerFilters              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              11
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3

とても感謝しています!

更新:リクエストした出力をここのコメントに入力してください。

ls -1 /etc/systemd/network/
73-usb-net-by-mac.link
99-default.link
enp0.network
enp1.network
lo.network
---------------------------------------------
/etc/systemd/network/enp0.network
[Match]
#Name=eth0
MACAddress=2c:cf:67:2f:cf:9a
Type=ether
RequiredForOnline=no

[Network]
DHCP=yes

[DHCPv4]
RouteMetric=100
---------------------------------------------
/etc/systemd/network/enp1.network
[Match]
#Name=eth1
MACAddress=00:24:27:88:29:17
Type=ether
RequiredForOnline=no

[Address]
Address=10.0.0.10/24
Broadcast=true
RouteMetric=10

[Network]
DHCP=no
DNS=1.1.1.1

[Route]
Gateway=10.0.0.1
Metric=10
---------------------------------------------
ip l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 2c:cf:67:2f:cf:9a brd ff:ff:ff:ff:ff:ff
---------------------------------------------
ip r
nothing, not even error or something
---------------------------------------------
lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0bda:8151 Realtek Semiconductor Corp. RTL8151 Adapteon Business Mobile Networks BV
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0b05:1a07 ASUSTek Computer, Inc. ROG STRIX SCOPE RX TKL WIRELESS DELUXE
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub



大規模なアップデートが必要な時点です 2024-04-30

一つ修正する興味がある人とヘルプリクエスト残りの問題を解決する方法を知っている人がいる場合は、フィードバックをリクエストしてください。

修正する 本当に想像できないものを保管しておきました... 小切手の詳細ここ

sudo apt-get update
sudo apt-get install git -y
git config --global user.name "YourGitHudUserName"
git config --global user.email "YourRegisterdEmailAdressOnGitHudAccount"
sudo apt-get install libusb-1.0-0-dev
sudo git clone https://github.com/mvp/uhubctl
cd uhubctl
sudo make
sudo make install

それから

ip a > status_before_uhubctl.txt
sudo uhubctl -l 1 -a 0 > output_of_uhubctl.txt
ip a > status_after_uhubctl.txt

これはログです

status_before_uhubctl.txt

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen>
    link/ether 2c:cf:67:2f:cf:9a brd ff:ff:ff:ff:ff:ff

uhubctl 出力.txt

Current status for hub 2 [1d6b:0003 Linux 6.6.28+rpt-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd>
  Port 1: 0203 power 5gbps U0 enable connect [0bda:8151 Realtek USB 10/100/1G/2.5G LAN 001000001]
Sent power off request
New status for hub 2 [1d6b:0003 Linux 6.6.28+rpt-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.0, >
  Port 1: 0080 off
Current status for hub 1 [1d6b:0002 Linux 6.6.28+rpt-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd>
  Port 1: 0100 power
  Port 2: 0103 power enable connect [0b05:1a07 ASUSTeK ROG STRIX SCOPE RX TKL WIRELESS DELUXE]
Sent power off request
New status for hub 1 [1d6b:0002 Linux 6.6.28+rpt-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.0, >
  Port 1: 0000 off
  Port 2: 0000 off

status_after_uhubctl.txt

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 2c:cf:67:2f:cf:9a brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:24:27:88:29:17 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.10/24 metric 10 brd 10.0.0.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fd75:a6e1:4b04:360:224:27ff:fe88:2917/64 scope global dynamic mngtmpaddr noprefixroute
       valid_lft 1758sec preferred_lft 1758sec
    inet6 fe80::224:27ff:fe88:2917/64 scope link
       valid_lft forever preferred_lft forever

あなたが見たようにイーサネット1ある戻るつまり、NICを物理的に削除して再接続する必要はありません。

今は助けるセクション、誰かが私がどのようにこの問題を解決して削除できるかを説明できますか?下記をご覧ください丸太 または おそらく私はsystemd-networkdを使用しているので、上記のコマンド(デフォルトではUSBポートの電源サイクル)をサービスとしてブートスクリプトに入れることが解決策でした。このアプローチは私が知っているものの中では最高ではないかもしれませんが、効果はあります。"systemd-networkd-wait-online.serviceを起動できません。"一度だけ。 (それとも私は完全に間違っていますか?)

できれば私を助けてください!

ここにいる丸太

systemctl status systemd-networkd-wait-online.service
× systemd-networkd-wait-online.service - Wait for Network to be Configured
     Loaded: loaded (/lib/systemd/system/systemd-networkd-wait-online.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/systemd-networkd-wait-online.service.d
             └─override.conf
     Active: failed (Result: exit-code) since Tue 2024-04-30 11:14:08 CEST; 24min ago
       Docs: man:systemd-networkd-wait-online.service(8)
    Process: 416 ExecStart=/lib/systemd/systemd-networkd-wait-online (code=exited, status=1/FAILURE)
   Main PID: 416 (code=exited, status=1/FAILURE)
        CPU: 9ms

Apr 30 11:12:07 Pi5 systemd[1]: Starting systemd-networkd-wait-online.service - Wait for Network to be Configured...
Apr 30 11:14:08 Pi5 systemd-networkd-wait-online[416]: Timeout occurred while waiting for network connectivity.
Apr 30 11:14:08 Pi5 systemd[1]: systemd-networkd-wait-online.service: Main process exited, code=exited, status=1/FAILURE
Apr 30 11:14:08 Pi5 systemd[1]: systemd-networkd-wait-online.service: Failed with result 'exit-code'.
Apr 30 11:14:08 Pi5 systemd[1]: Failed to start systemd-networkd-wait-online.service - Wait for Network to be Configured.

ベストアンサー1

プログラムの出力は次のとおりですlsusb

Bus 002 Device 003: ID 0bda:8156 Realtek Semiconductor Corp. USB 10/100/1G/2.5G LAN

出力を見てください。

ls -1ong /sys/bus/usb/devices/

このパスは、/sys/devices/pci000:00/*PCIシステムバスのデバイスを表します。 (マザーボードデータは「バス」と呼ばれる指定されたパスを介して送信されます。)

Sysfsは仮想ファイルシステムですカーネルで使用されます。デバイスとドライバに関する情報、およびシステムに接続されているデバイスを設定および制御するために使用されるいくつかの変更可能な情報。

[Unit]
Description=Reset usb2 on startup

[Service]
ExecStart=bash -c "echo '0' > /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms" && bash -c "echo 'auto' > /sys/bus/usb/devices/usb2/power/control
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

ファイルを作成します.service。上記のテキストをコピーして、次のコマンドを実行します。

sudo nano /etc/systemd/system/usb_reset.service

次に、テキストをナノに貼り付けます。
保存と終了。 (Ctrl+S>はい>入力する>Ctrl+X
今、次の2つのコマンドを実行してみてください。

新しい .service ファイルを初期化し、サービスを開始します。

sudo systemctl daemon-reload
sudo systemctl enable usb_reset.service

終わる!これにより、ExecStart=.serviceファイルのコマンドが実行され、usb2起動するたびに自動的にリセットされます。

おすすめ記事