åå ã¯ãVirtualBox + Ubuntu 22.04 ã®ãããã¯ã¼ã¯ã®ç解ãé²ãã¾ããã
ä»åã¯ãããã§ä½ã£ã QEMU ã使ã£ã¦ãVirtualBox + Ubuntu 22.04 ã¨ã®ãããã¯ã¼ã¯ã®çéã確èªãã¦ããã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
ã¯ããã«
ãQEMUãåãããã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
QEMUãåããã®è¨äºä¸è¦§
以ä¸ã¯ãBuildroot ã® Documentation ã®ãªã³ã¯ã§ãã
https://buildroot.org/downloads/manual/manual.html
ããã§ä½¿ç¨ããç°å¢ã¯ãVirtualBox ã«å
¥ãã Ubuntu 22.04 ã§ãã
Buildroot ã使ãã¾ããBuildroot ã«å«ã¾ãã¦ãã U-Boot ã¨ãQEMU ã使ãã¾ãã
ãã¼ã« |
è¨å®å¤ |
Buildroot |
qemu_aarch64_virt_defconfig |
U-Boot |
qemu_arm64_defconfig |
QEMU |
virtï¼virt-8.2ï¼ |
IPv6 ã®ç¡å¹å
ã¾ãã¯ããã±ãããã£ããã£ã§è¦ã«ãããªãã®ã§ãVirtualBox + Ubuntu 22.04 ã®ç°å¢ã§ãIPv6 ãç¡å¹åãã¾ãã
IPv6 ãç¡å¹åããæ¹æ³ã¯ãä¸æçã« IPv6 ãç¡å¹åããåèµ·åãããå
ã«æ»ãæ¹æ³ã¨ãåèµ·åãã¦ã IPv6 ãç¡å¹ã®ã¾ã¾ã«ãªãæ¹æ³ãããã¾ãã
ç¾å¨ã®ç¶æ³ã確èªãã¾ãã
$ ip a
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
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:54:d5:cb brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
valid_lft 86331sec preferred_lft 86331sec
inet6 fe80::eb16:b65:e9c5:ddc9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:c0:67:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.56.101/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8
valid_lft 531sec preferred_lft 531sec
inet6 fe80::2d19:efaa:a12d:f974/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:6c:c6:1a:3c brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 ã表示ããã¦ããã®ã§ãç¾å¨ã¯ IPv6 ãæå¹ãªç¶æ
ã§ãã
ã¾ããä¸æçã« IPv6 ãç¡å¹åããæ¹æ³ã§ããããã¯åèµ·åããã¨å
ã«æ»ãã¾ãã
sysctl ã³ãã³ãã使ãã¾ãã
sysctl ã³ãã³ãã¯ãã«ã¼ãã«ã®ãã©ã¡ã¼ã¿ãå¤æ´ããã³ãã³ãã§ãã以ä¸ã®ããã«ã-w ãªãã·ã§ã³ã使ã£ã¦ããã©ã¡ã¼ã¿ãè¨å®ããã¨ããã®è¨å®ãå³åº§ã«ã·ã¹ãã ã«åæ ããã¾ãã
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
ä¸æ¹ãæ°¸ç¶çã« IPv6 ãç¡å¹åããæ¹æ³ã¯ã2ã¤ããã¾ãã
1ã¤ã¯ã/etc/sysctl.conf ã«è¨å®ãæ¸ãè¾¼ãã§ãèµ·åæã«å®è¡ãããã¹ã¯ãªãããä½æãã¦ã/etc/sysctl.conf ãåæ ãããã¨ããæ¹æ³ãããã¾ããããªããèªç¶ãªæ¹æ³ã§ã¯ãªãæ°ãããã®ã§ãããã§ã¯ãã1ã¤ã®æ¹æ³ã§ç¡å¹åãã¾ãã
ãã¼ããã¼ãã¼ã® grub ã®è¨å®ãã¡ã¤ã«ï¼/etc/default/grubï¼ã§ãã«ã¼ãã«ãã©ã¡ã¼ã¿ã¨ãã¦ã追å ã§ãipv6.disable=1
ã渡ãæ¹æ³ã§ãã
/etc/default/grub ãç·¨éãã¦ãã«ã¼ãã«ãã©ã¡ã¼ã¿ã« ipv6.disable=1
ã追å ãã¾ãã
-GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
+GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
追å ã§ããããgrub ãæ´æ°ãã¾ãã
$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.5.0-41-generic
Found initrd image: /boot/initrd.img-6.5.0-41-generic
Found linux image: /boot/vmlinuz-6.5.0-35-generic
Found initrd image: /boot/initrd.img-6.5.0-35-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done
æ´æ°ã§ããããåèµ·åãã¾ãã
å度ãç¾å¨ã®ç¶æ
ã確èªãã¾ãã
$ ip a
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
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:54:d5:cb brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
valid_lft 86275sec preferred_lft 86275sec
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:c0:67:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.56.101/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8
valid_lft 475sec preferred_lft 475sec
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:6c:c6:1a:3c brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 ã表示ãããªããªãã¾ãããIPv6 ã®ç¡å¹åã«ã¤ãã¦ã¯ä»¥ä¸ã§ãã
tcpdumpã®ã¤ã³ã¹ãã¼ã«
ååã¯ãWireshark ã使ãã¾ããããã³ãã³ãã©ã¤ã³ã§ç¢ºèªããããã«ãtcpdump ãã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
$ sudo apt install tcpdump
tcpdump ã®ä½¿ãæ¹ã¯ãroot 権éãå¿
è¦ãªã®ã§ãsudo ãä»ãã¦å®è¡ãã¾ãã
ã¾ãã対象ã¨ãããããã¯ã¼ã¯ã¤ã³ã¿ã¼ãã§ã¼ã¹ã -i ãªãã·ã§ã³ã§æå®ãã¾ãã
ããã§ãã±ããã確èªãããã¨ãã§ãã¾ãããè¦ãããããããã«ãããã¤ããªãã·ã§ã³ã使ãã¾ãã
ãªãã·ã§ã³ |
説æ |
-n |
ãã¹ãã¢ãã¬ã¹ãååã«å¤æããªã |
-nn |
ãã¹ãã¢ãã¬ã¹ã«å ãã¦ããã¼ãçªå·ãååã«å¤æããªã |
-t |
ã¿ã¤ã ã¹ã¿ã³ãã表示ããªã |
-n 㨠-nn ã¯ãå®éã«ä½¿ã£ã¦ã¿ã¦ãéããåããã¾ããã§ããã
ããã§ã¯ã-n 㨠-t ã使ãã¾ãã
VirtualBox + Ubuntu 22.04 ã®ã¤ã³ã¿ã¼ãããã«ç¹ããã¤ã³ã¿ãã§ã¼ã¹ï¼enp0s3ï¼ã§ tcpdump ãèµ·åãã¦ãããQEMU ãã http://www.google.co.jp
ã« wget ã³ãã³ããå®è¡ããã¨ããããã£ããã£ãã¦ã¿ã¾ãã
ã¾ããQEMU å´ã§ããwget ã³ãã³ãã® -S ãªãã·ã§ã³ã¯ããµã¼ãå´ã®ã¬ã¹ãã³ã¹ã表示ãã¾ãã
Connecting to www.google.co.jp (142.251.222.35:80)
HTTP/1.1 200 OK
Date: Mon, 15 Jul 2024 03:42:07 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Shift_JIS
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-zMcYJVB4lYrRFDRhLYbOHQ' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: AEC=AVYB7codc8r_4hcLjRGK8ssLHyqdH-1AI-Dpk-JGz4vq9sNl1vihwclMgQ; expires=Sat, 11-Jan-2025 03:42:07 GMT; path=/; domain=.google.co.jp; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=515=mBDHsj1Jrb6pnJeOb602tO0agFHDUcXdJ3ZMg9kGbp_K7XiJaWr17yawIkAj-Aczp6tsj3kIhBYVuMu34KBWF1Bkb-m-9odbcyF5o228MjIXPCYMfCTH0wTRXGYcTOmyPh17HRoLNp-4qRWcObcyxLyTPLy_L-4Uo7mNUajmRh8; expires=Tue, 14-Jan-2025 03:42:07 GMT; path=/; domain=.google.co.jp; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
wget: can't open 'index.html': File exists
Date æ
å ±ã確èªã§ãã¾ãããã®æ
å ±ã§æå»åãããåºæ¥ãããã¾ãã
次ã«ãVirtualBox + Ubuntu 22.04 å´ã§ãã¤ã³ã¿ã¼ãããã«ç¹ããã¤ã³ã¿ãã§ã¼ã¹ã tcpdump ãå®è¡ããå
容ã§ãã
$ sudo tcpdump -tn -i enp0s3
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on enp0s3, link-type EN10MB (Ethernet), snapshot length 262144 bytes
IP 10.0.2.15.44635 > 192.168.3.1.53: 43604+ [1au] A? www.google.co.jp. (45)
IP 10.0.2.15.40942 > 192.168.3.1.53: 35084+ [1au] AAAA? www.google.co.jp. (45)
IP 192.168.3.1.53 > 10.0.2.15.44635: 43604 1/4/9 A 172.217.174.99 (319)
IP 192.168.3.1.53 > 10.0.2.15.40942: 35084 1/4/9 AAAA 2404:6800:4004:80c::2003 (331)
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [S], seq 2027278432, win 64240, options [mss 1460,sackOK,TS val 3004422288 ecr 0,nop,wscale 7], length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [S.], seq 14400001, ack 2027278433, win 65535, options [mss 1460], length 0
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 1, win 64240, length 0
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [P.], seq 1:80, ack 1, win 64240, length 79: HTTP: GET / HTTP/1.1
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [.], ack 80, win 65535, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [.], seq 1:2921, ack 80, win 65535, length 2920: HTTP: HTTP/1.1 200 OK
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 2921, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [.], seq 2921:7301, ack 80, win 65535, length 4380: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 7301, win 61320, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [.], seq 7301:13141, ack 80, win 65535, length 5840: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 13141, win 61320, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [P.], seq 13141:14109, ack 80, win 65535, length 968: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 14109, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [P.], seq 14109:16933, ack 80, win 65535, length 2824: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 16933, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [P.], seq 16933:19757, ack 80, win 65535, length 2824: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 19757, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [P.], seq 19757:21581, ack 80, win 65535, length 1824: HTTP
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [.], ack 21581, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [F.], seq 21581, ack 80, win 65535, length 0
IP 10.0.2.15.36010 > 172.217.174.99.80: Flags [F.], seq 80, ack 21582, win 62780, length 0
IP 172.217.174.99.80 > 10.0.2.15.36010: Flags [.], ack 81, win 65535, length 0
^C
26 packets captured
26 packets received by filter
0 packets dropped by kernel
å
é ã§ãhttp://www.google.co.jp
ã DNS ã§åãåããã¦ãIP ã¢ãã¬ã¹ 172.217.174.99
ãåå¾ãã¦ãã¾ãã
ãã®å¾ã¯ãåå¾ãã IP ã¢ãã¬ã¹ã使ã£ã¦ãhttp ãããã³ã«ã§ããã¼ã¿ï¼index.htmlï¼ãåå¾ãã¦ãã¾ãã
tcpdump ã®ä½¿ãæ¹ã¯ä»¥ä¸ã«ãªãã¾ãã
QEMUã®ãããã¯ã¼ã¯ã®ç¢ºèª
ã¾ããIPã¢ãã¬ã¹ã¨ãã«ã¼ãã£ã³ã°ãã¼ãã«ã確èªãã¾ãã
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue 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
valid_lft forever preferred_lft forever
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop qlen 1000
link/ether f2:22:5f:2c:0a:eb brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fec0::5054:ff:fe12:3456/64 scope site dynamic flags 100
valid_lft 86114sec preferred_lft 14114sec
inet6 fe80::5054:ff:fe12:3456/64 scope link
valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 * 255.255.255.0 U 0 0 0 eth0
ç¶ãã¦ãå¤é¨ã¨ã®ãããã¯ã¼ã¯ã®æ¥ç¶ã確èªãã¾ãã
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=255 time=11.169 ms
64 bytes from 8.8.8.8: seq=1 ttl=255 time=6.995 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 6.995/9.082/11.169 ms
PING google.com (172.217.174.110): 56 data bytes
64 bytes from 172.217.174.110: seq=0 ttl=255 time=15.283 ms
64 bytes from 172.217.174.110: seq=1 ttl=255 time=14.880 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 14.880/15.081/15.283 ms
åé¡ãªããã¤ã³ã¿ã¼ãããã«ç¹ãããã¨ã¨ãDNS ã«ããåå解決ãè¡ããã¦ãããã¨ã確èªã§ãã¾ããã
routeã³ãã³ãã® _gateway ã¯ãå
·ä½çãªã¢ãã¬ã¹ãç¥ãããã§ããã
PING _gateway (10.0.2.2): 56 data bytes
64 bytes from 10.0.2.2: seq=0 ttl=255 time=0.533 ms
64 bytes from 10.0.2.2: seq=1 ttl=255 time=0.480 ms
^C
--- _gateway ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.480/0.506/0.533 ms
ãªãã»ã©ã10.0.2.2 ã§ããã
VirtualBox ã¨åããããã¯ã¼ã¯ã¢ãã¬ã¹ãªã®ã§ãã¨ã¦ããããããã§ãã
VirtualBox ã§ã¯ãã«ã¼ã¿ã¼ã 10.0.2.2 ã§ãèµ·åãã Ubuntu 22.04 ã® IPã¢ãã¬ã¹ã 10.0.2.15 ã§ãã
ä¸æ¹ãQEMU ã§ã¯ãåãããã«ã¼ã¿ã¼ã 10.0.2.2 ã§ãèµ·åãã Buildroot ã® IPã¢ãã¬ã¹ã 10.0.2.15 ã§ãã
IPã¢ãã¬ã¹ãæ´æ°ããããããªãããªï¼ã¨æã£ã¦ãDHCPã¯ã©ã¤ã¢ã³ãã§ãIPã¢ãã¬ã¹ãåé¤ãã¦ã¿ã¾ããã
udhcpc: started, v1.36.1
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
deleting routers
adding dns 10.0.2.3
ãªãªã¼ã¹ã®ã¯ãã§ãããããã«ååå¾ããã¾ããã
ãããããããã§ãQEMU ã®ãããã¯ã¼ã¯ã®æ
å ±ãåããã¾ããã
ã«ã¼ã¿ã¼ã¯ 10.0.2.2 ã¯åã£ã¦ã¾ãããDNS ãµã¼ãã 10.0.2.3 ã®ããã§ãã
1 /bin/busybox 0 /dev/console
1 /bin/busybox 1 /dev/console
1 /bin/busybox 2 /dev/console
51 /bin/busybox 0 socket:[41]
51 /bin/busybox 1 /dev/null
51 /bin/busybox 2 /dev/null
51 /bin/busybox 3 /tmp/messages
55 /bin/busybox 0 /dev/null
55 /bin/busybox 1 /dev/null
55 /bin/busybox 2 /dev/null
55 /bin/busybox 3 socket:[42]
95 /bin/busybox 0 /dev/null
95 /bin/busybox 1 /dev/null
95 /bin/busybox 2 /dev/null
95 /bin/busybox 3 pipe:[60]
95 /bin/busybox 4 pipe:[60]
97 /bin/busybox 0 /dev/console
97 /bin/busybox 1 /dev/console
97 /bin/busybox 2 /dev/console
97 /bin/busybox 10 /dev/tty
/usr/bin/lsof
lrwxrwxrwx 1 root root 17 Jul 13 09:09 /usr/bin/lsof -> ../../bin/busybox*
Buildroot ã§ã¯ãæ®éã® lsof ã³ãã³ãã¯æã£ã¦ãªãã¦ãBusyBox ãæã£ã¦ããç°¡æç㪠lsof ã³ãã³ãã®ããã§ãã
ãã£ã¦ãPIDãå®è¡ãã¡ã¤ã«ãã¹ããªã¼ãã³ãããã¡ã¤ã«ããããã表示ããã¾ããã
listen ãã¦ããã¼ãã¨ããããªã¼ãã³ãããã¡ã¤ã«ãç¥ãããã£ãã®ã§ãããBusyBox ã® lsofã³ãã³ãã§ã¯é£ããããã§ãã
lsofã³ãã³ããã¤ã³ã¹ãã¼ã«ãã
ã§ã¯ãlsofã³ãã³ãã®ã½ã¼ã¹ã³ã¼ãããã¦ã³ãã¼ããã¦ãã¦ãã¯ãã¹ã³ã³ãã¤ã«ãã¦ãBuildroot ã§ä½¿ããããã«ãã¦ã¿ããã¨æãã¾ãã
lsofã³ãã³ãã® GitHub ã®ãªãªã¼ã¹ãã¼ã¸ã§ãã
github.com
ææ°ãã¼ã¸ã§ã³ã¯ãlsof 4.99.3 ã®ããã§ãã
ã§ã¯ãã¦ã³ãã¼ããã¾ãã
$ wget https://github.com/lsof-org/lsof/archive/refs/tags/4.99.3.tar.gz
$ tar zxvf 4.99.3.tar.gz
$ cd lsof-4.99.3/
ç¶ãã¦ãã³ã³ãã£ã°ãè¡ãå¿
è¦ãããããã§ãããã¾ãã¯ãINSTALL ãã¡ã¤ã«ã軽ãçºãã¦ã¿ã¾ãã
ãã¼ããconfigure ãè¡ã£ã¦ãã ãããã¨æ¸ããã¦ããã¾ããããã¡ã¤ã«åã Configureï¼å
é ã大æåï¼ã®ãã¡ã¤ã«ããããã¾ãããæªãããªããã¨æã£ãã®ã§ã00README ã¨ãããã¡ã¤ã«ãè¦ã¦ã¿ã¾ãããã¡ãã¯ãConfigure ãå®è¡ããªãããã¨æ¸ããã¦ãã¾ãã
Configure linux ã¨å®è¡ããã°è¯ãããã§ãã
lsofã³ãã³ãããã¤ãã£ãã§ã³ã³ãã¤ã«ãã
ã¾ãã¯ããã¤ãã£ãã§ãã«ãï¼x86ï¼ã§è©¦ãã¦ããã¾ããã£ãããã¯ãã¹ã³ã³ãã¤ã«ããã£ã¦ããã¾ãã
$ ./Configure linux
å®è¡ããã¨ãããã¤ã質åããã¾ãããããåãããªãã®ã§ãã¨ãããããå
¨ã¦ãªã¿ã¼ã³ãæ¼ãã¾ããã
Makefile ãåºæ¥ããããªã®ã§ããã¨ã¯ make ããã°ããã¯ãã§ãã
$ make -j $(nproc)
ç¡äºã«å®è¡ãã¡ã¤ã«ï¼lsofï¼ãä½ãããããã§ãã®ã§ã試ãã¾ãã
$ ./lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 5768 daisuke 3u IPv4 41976 0t0 TCP daisuke-VirtualBox:55128->192.168.4.1:ssh (ESTABLISHED)
ï¼çç¥ï¼
Ubuntu ã«æ¢ã«å
¥ã£ã¦ãæ¹ã® lsof ã®åºåã¨åããããªæãã ã£ãã®ã§ã大ä¸å¤«ããã§ãã
lsofã³ãã³ããã¯ãã¹ã³ã³ãã¤ã«ãã
次ã¯ãã¯ãã¹ã³ã³ãã¤ã«ãã¦ããã¾ãã
Web ã§æ
å ±ãæ¢ããããChatGPT ã«èãã¦ã¿ãã®ã§ãããMakefile ã®å¤æ°ãç´æ¥æ¸ãæããæ¹æ³ãããªãããã§ãã
Makefile ã®å
é ã«ãCC=cc ã¨ããã¾ãã®ã§ããããã¯ãã¹ã³ã³ãã¤ã©ã«ç½®ãæãã¾ãã
-CC= cc
+CC= arm-linux-gnueabi-gcc
$ make clean
$ make -j $(nproc)
ï¼çç¥ï¼
/usr/lib/gcc-cross/arm-linux-gnueabi/11/../../../../arm-linux-gnueabi/bin/ld: ./lib/liblsof.a: error adding symbols: file format not recognized
collect2: error: ld returned 1 exit status
make: *** [Makefile:64: lsof] ã¨ã©ã¼ 1
make ãåºåããå
容ãè¦ãã¨ãlib ãã©ã«ãã«ç§»åãã¦ããã¯ãã¯ãã¹ã³ã³ãã¤ã©ã使ããã¦ãã¾ããã§ããã
ã¨ãããã¨ã§ãlib ãã©ã«ãã® Makefile ãæ¸ãæãã¾ãã
-CC= cc
+CC= arm-linux-gnueabi-gcc
-AR= ar cr ${LIB} ${OBJ}
+AR= arm-linux-gnueabi-ar cr ${LIB} ${OBJ}
-RANLIB= ranlib ${LIB}
+RANLIB= arm-linux-gnueabi-ranlib ${LIB}
ã§ã¯ãmake ãã¾ãã
$ make clean
$ make -j $(nproc)
ï¼çç¥ï¼
arm-linux-gnueabi-gcc -o lsof dfile.o dmnt.o dnode.o dprint.o dproc.o dsock.o dstore.o arg.o main.o print.o store.o usage.o util.o -L./lib -llsof -ltirpc -lselinux
/usr/lib/gcc-cross/arm-linux-gnueabi/11/../../../../arm-linux-gnueabi/bin/ld: -ltirpc ãè¦ã¤ããã¾ãã: ãã®ãããªãã¡ã¤ã« ããã£ã¬ã¯ããªã¯ããã¾ãã
/usr/lib/gcc-cross/arm-linux-gnueabi/11/../../../../arm-linux-gnueabi/bin/ld: -lselinux ãè¦ã¤ããã¾ãã: ãã®ãããªãã¡ã¤ ã«ããã£ã¬ã¯ããªã¯ããã¾ãã
collect2: error: ld returned 1 exit status
make: *** [Makefile:64: lsof] ã¨ã©ã¼ 1
ã¯ãã¹ã³ã³ãã¤ã©ç¨ã® libtirpc.so 㨠libselinux.so ãè¦ã¤ãããªããã¨ããã¨ã©ã¼ã®ããã§ãã
Ubuntu ã«ã¯ãä»ã®ã¢ã¼ããã¯ãã£ã®ã©ã¤ãã©ãªã apt ã§ã¤ã³ã¹ãã¼ã«ãããã¨ãåºæ¥ãããã§ãã
æµãã¨ãã¦ã¯ãã¾ããã¢ã¼ããã¯ãã£ã追å ãã¾ãããã®å¾ã/etc/apt/sources.list ãç·¨éãã¦ãapt update ã§ã¨ã©ã¼ãåºãªãããã«ãã¾ããããã¾ã§åºæ¥ãããå¿
è¦ãªã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ãã¾ãã
ã¾ããç¾å¨ã®ããã©ã«ãã®ã¢ã¼ããã¯ãã£ã確èªãã¾ãã
$ dpkg --print-architecture
amd64
PC ã® 64bit ã¨è¨å®ããã¦ãã¾ããã
次ã«ã追å ããã¢ã¼ããã¯ãã£ã確èªãã¾ãã
$ dpkg --print-foreign-architectures
i386
PC ã® 32bit ãè¨å®ããã¦ãã¾ããã
ããã«ãä»åã®ã¯ãã¹ã³ã³ãã¤ã©ï¼32bit ARMï¼ã®è¨å®ã追å ãã¾ãã
$ sudo dpkg --add-architecture armhf
$ dpkg --print-foreign-architectures
i386
armhf
追å ãããã¨ãåºæ¥ã¾ããã
ããã§ãapt update ãè¡ãã¨ãã¨ã©ã¼ãåºã¾ããã
/etc/apt/sources.list ã®ç·¨éãå¿
è¦ãªããã§ãã
ç¾å¨ã® sources.list ã®å
容ã§ãï¼ã³ã¡ã³ãã¯åé¤ãã¾ããï¼ã
$ cat /etc/apt/sources.list
deb http://jp.archive.ubuntu.com/ubuntu/ jammy main restricted
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb http://jp.archive.ubuntu.com/ubuntu/ jammy universe
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates universe
deb http://jp.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
ãã®ç¶æ
ã ã¨ãå
¨è¡ã«ã¤ãã¦ãç¾å¨ã®å
¨ã¦ã®ã¢ã¼ããã¯ãã£ãæ¢ããã¨ãã¾ããããããä»å追å ãã armhf ã¯å¥ã® URL ãªã®ã§ãapt update ã§ãã¨ã©ã¼ãåºã¦ãã¾ãã¾ãã
ããã§ãåè¡ã«ã¤ãã¦ãé©ç¨ããã¢ã¼ããã¯ãã£ãæå®ããããã«å¤æ´ãå¿
è¦ãªããã§ãã
ã¾ããarmhf ç¨ã® URL ã追å ãã¾ãã
$ sudo nano /etc/apt/sources.list
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy main restricted
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy universe
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy-updates universe
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy multiverse
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-security main restricted
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-security universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-security multiverse
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
ãããããã¨ã§ãapt update ãã¨ã©ã¼ãªãå®è¡ã§ããããã«ãªãã¾ããã
ã§ã¯ããããããå¿
è¦ãªã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ããã³ãã³ã®å¾ã«ã¢ã¼ããã¯ãã£ãæå®ãã¾ãã
$ sudo apt-get install libtirpc-dev:armhf libselinux1-dev:armhf
$ find /usr/ -name 'libtirpc*'
/usr/lib/x86_64-linux-gnu/libtirpc.so.3.0.0
/usr/lib/x86_64-linux-gnu/libtirpc.so
/usr/lib/x86_64-linux-gnu/pkgconfig/libtirpc.pc
/usr/lib/x86_64-linux-gnu/libtirpc.so.3
/usr/lib/x86_64-linux-gnu/libtirpc.a
/usr/lib/arm-linux-gnueabihf/libtirpc.so.3.0.0
/usr/lib/arm-linux-gnueabihf/libtirpc.so
/usr/lib/arm-linux-gnueabihf/pkgconfig/libtirpc.pc
/usr/lib/arm-linux-gnueabihf/libtirpc.so.3
/usr/lib/arm-linux-gnueabihf/libtirpc.a
$ find /usr/ -name 'libselinux*'
/usr/share/doc/libselinux1-dev
/usr/share/doc/libselinux1
!/usr/lib/x86_64-linux-gnu/libselinux.so.1
/usr/lib/x86_64-linux-gnu/libselinux.a
/usr/lib/x86_64-linux-gnu/libselinux.so
/usr/lib/x86_64-linux-gnu/pkgconfig/libselinux.pc
/usr/lib/arm-linux-gnueabihf/libselinux.so.1
/usr/lib/arm-linux-gnueabihf/libselinux.a
/usr/lib/arm-linux-gnueabihf/libselinux.so
/usr/lib/arm-linux-gnueabihf/pkgconfig/libselinux.pc
/usr 以ä¸ãæ¤ç´¢ããã¨ãã¡ããã¨ã¤ã³ã¹ãã¼ã«ããã©ã¤ãã©ãªã確èªã§ãã¾ããï¼é·ãã®ã§ä¸é¨çç¥ãã¾ããï¼ã
ããã§ã¯ããã®ã©ã¤ãã©ãªã使ãããã« Makefile ãå¤æ´ãã¾ãã
ã¾ããããããã£ã¬ã¯ããªã® Makefile ã§ãã
-CC= cc
+CC= arm-linux-gnueabihf-gcc
次ã«ãlib ãã£ã¬ã¯ããªã® Makefile ã§ãã
-CC= cc
+CC= arm-linux-gnueabihf-gcc
-AR= ar cr ${LIB} ${OBJ}
+AR= arm-linux-gnueabihf-ar cr ${LIB} ${OBJ}
-RANLIB= ranlib ${LIB}
+RANLIB= arm-linux-gnueabihf-ranlib ${LIB}
make ãã¦ã¿ãã¨ãå
ã»ã©ã®ã¨ã©ã¼ã¯ç¡ããªãããã«ããå®äºãã¾ããã
æ©éãBuildroot ã«è»¢éãã¦å®è¡ãã¦ã¿ã¾ãã
./lsof: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory
ã¨ã©ã¼ã«ãªãã¾ãããã¯ãã¹ã³ã³ãã¤ã©ç°å¢ã«ã¯ã¤ã³ã¹ãã¼ã«ãã¾ããããå®è¡ç°å¢ã«ã©ã¤ãã©ãªãç¡ãã¨ãããã¨ã ã¨æãã¾ãã
ã¨ãããããã¤ã³ã¹ãã¼ã«ãã2ã¤ã®ã©ã¤ãã©ãªã® .so ã Buildroot ã® lsof ã¨åãå ´æã«è»¢éãã¦ãå®è¡ãã¦ã¿ã¾ãã
./lsof: error while loading shared libraries: libpcre2-8.so.0: cannot open shared object file: No such file or directory
ãã¼ãããã¡ã§ããä»ã®ã©ã¤ãã©ãªãç¡ãã¨ãããã¨ã§ããããã
ãã¡ãã¨ã§ã/usr/lib/arm-linux-gnueabihf/libpcre2-8.so.0 ã Buildroot ã«è»¢éãã¦ãå®è¡ãã¦ã¿ãã¨ã次ã¯ãlibc ã®ãã¼ã¸ã§ã³ã対å¿ãã¦ããªãï¼ã¯ãã¹ç°å¢ãæ°ããï¼ã¨ããã¨ã©ã¼ãåºã¾ããã
ä»æ¹ãªãã®ã§ãUbuntu 22.04 ãã Ubuntu 18.04 ã«æ»ãã¦ã試ãã¦ã¿ã¾ãã
Ubuntu ã§ãapt ã§å
¥ãã¯ãã¹ã³ã³ãã¤ã©ã£ã¦ä»¥ä¸ã®2ã¤ãããã¾ãããéããåãã£ã¦ãã¾ããã
- crossbuild-essential-armhfï¼
dpkg --add-architecture armhf
ãå®æ½ããå ´åã«ãããç´¹ä»ããã¦ããã¯ãã¹ã³ã³ãã¤ã©
- gcc-arm-linux-gnueabihfï¼ã¤ã³ã¹ãã¼ã«ããã¨ã㯠g++-arm-linux-gnueabihf ãæå®ããæ¹ããããããï¼ï¼æ¤ç´¢ããã¨ããã¡ãã®æ¹ãããããããã
ä»ã¾ã§ã¯ä½ãèããã«å¾è
ã使ã£ã¦ã¾ããããä»åã¯åè
ã使ã£ã¦ã¿ã¾ãã
$ sudo apt install crossbuild-essential-armhf
以ä¸ã®è¿½å ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¾ã:
binutils binutils-arm-linux-gnueabihf binutils-common binutils-x86-64-linux-gnu cpp-7-arm-linux-gnueabihf
cpp-arm-linux-gnueabihf dpkg-cross g++-7-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc-7-arm-linux-gnueabihf
gcc-7-arm-linux-gnueabihf-base gcc-7-cross-base gcc-8-cross-base gcc-arm-linux-gnueabihf libasan4-armhf-cross
libatomic1-armhf-cross libbinutils libc6-armhf-cross libc6-dev-armhf-cross libcilkrts5-armhf-cross libconfig-auto-perl
libconfig-inifiles-perl libdebian-dpkgcross-perl libfile-homedir-perl libfile-which-perl libgcc-7-dev-armhf-cross
libgcc1-armhf-cross libgomp1-armhf-cross libstdc++-7-dev-armhf-cross libstdc++6-armhf-cross libubsan0-armhf-cross
libyaml-perl linux-libc-dev-armhf-cross
ããè¦ãã¨ãä¾åããã±ã¼ã¸ã¨ãã¦ãgcc-arm-linux-gnueabihf ãå
¥ã£ã¦ãã¾ãããã¤ãã§ã«ãg++-arm-linux-gnueabihf ãå
¥ã£ã¦ãã¾ããä»åº¦ããã¯ãcrossbuild-essential-armhfï¼64bitã®å ´å㯠crossbuild-essential-arm64ï¼ãå
¥ãããã¨ã«ãã¾ãã
ã§ã¯ãåæ§ã«ã追å ã®ã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããã³ã³ãã£ã°ã§ linux ãæå®ããMakefile ãåæ§ã«æ¸ãæãã¦ãã«ããã¾ããåçãªã³ã¯ãªãåé¡ãªãå®äºãã¾ããã
ä¸å¿ãglibc ã®ãã¼ã¸ã§ã³ã確èªãã¾ãã
$ dpkg -l | grep libc6
ii libc6:amd64 2.27-3ubuntu1.6 amd64 GNU C Library: Shared libraries
ii libc6:armhf 2.27-3ubuntu1.6 armhf GNU C Library: Shared libraries
ii libc6-armhf-cross 2.27-3ubuntu1cross1.1 all GNU C Library: Shared libraries (for cross-compiling)
ii libc6-dbg:amd64 2.27-3ubuntu1.6 amd64 GNU C Library: detached debugging symbols
ii libc6-dev:amd64 2.27-3ubuntu1.6 amd64 GNU C Library: Development Libraries and Header Files
ii libc6-dev:armhf 2.27-3ubuntu1.6 armhf GNU C Library: Development Libraries and Header Files
ii libc6-dev-armhf-cross 2.27-3ubuntu1cross1.1 all GNU C Library: Development Libraries and Header Files (for cross-compiling)
ã ãã¶å¤ãã®ã§å¤§ä¸å¤«ãªæ°ããã¾ãã
ã§ã¯ãlsof ã®ãã£ã¬ã¯ããªã¨ãã¯ãã¹ã³ã³ãã¤ã©ã®ã©ã¤ãã©ãªãå§ç¸®ãã¦ãUbuntu 22.04 ã«ã³ãã¼ãã¾ãã
Buildroot ã«è»¢éãã¦ãå®è¡ãã¦ã¿ã¾ãããåãã¾ããï¼
å¿
è¦ãªãã¼ã«ãã¯ãã¹ã³ã³ãã¤ã«ã㦠Buildroot ã§åãããã¨ã¯ããªããªãé£ããã¨ãããã¨ãåããã¾ããã
ãããã«
ä»åã¯ãQEMU ã®ãããã¯ã¼ã¯ã®èª¿æ»ã¨ãã®æºåãå¿
è¦ãªãã¼ã«ã®ã¯ãã¹ã³ã³ãã¤ã«ãè¡ãã¾ããã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã