编译脚本,将其添加到系统中,以便它在系统启动之前(或期间)运行

编译脚本,将其添加到系统中,以便它在系统启动之前(或期间)运行

我真的不知道该怎么办所以我在这里向大家寻求帮助

长话短说,有一些背景细节

我的 Raspberry Pi 5 连接了 USB3 2.5gb NIC(此 SBC 也有自己的内置 1gb NIC)。我已经安装了操作系统 Raspberry Pi OS Lite 64位Debian 版本:12(书呆子)- 是的,一切都已更新。

网络和网卡已配置这是详细信息/帖子

  • 我只想使用 USB3 NIC 作为我的主/默认接口

问题; 每次启动/重新启动后(ofc甚至关机和开机)我必须通过移除然后再次连接来物理断开 USB3 NIC。

在互联网上搜索我发现/遇到了一些帖子,其中建议了一些命令我猜可以将其堆积成一个脚本并运行。 乌班图,超级用户这篇文章来自 GeekLand详细介绍了这一切使用谷歌翻译或其他东西,因为这是用西班牙语写的。

我的问题是; 有人会足够友善并解释我如何以更永久的方式执行并将其应用到我的系统中吗?

我的最终目标是;以某种方式影响我的系统引导脚本,以便usb3nic.sh包含用于断开和重新连接 USB3 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

现在,将文本粘贴到 nano 中。
保存并退出。 (Ctrl+S>>进入>Ctrl+X)
现在,运行这两个命令。

初始化新的.service 文件并启动服务。

sudo systemctl daemon-reload
sudo systemctl enable usb_reset.service

完成!这将运行ExecStart=.service 文件中的命令,usb2自动重置每次启动。

相关内容