在 OpenWRT 下默认没有自带 lspci,lshw,今晚断网之后自己尝试去摸索,以下是今晚摸索到的信息
按了下 Tab 键,看了下命令表,发现在 OpenWRT 里的基础程序屈指可数,真不愧是嵌入式系统1
2
3
4
5
6
7
8
9
10
11
12
13
14 clear dropbearkey halt ip6tables-save lock modinfo opkg reset swconfig true
which [[ cmp du head ipcalc.sh logd modprobe passwd rm switch_root ubus wifi arping cp
echo hexdump iptables logger mount pgrep rmdir sync ubusd wpa_supplicant ash crond egrep
hostapd iptables-restore login.sh mount_root pidof rmmod sysctl uci wpad askfirst crontab
env hostid iptables-save logread mtd ping route sysupgrade udevtrigger xargs awk cut expr
hotplug-call iw ls mv ping6 scp tail udhcpc xtables-multi basename date false hwclock jffs2mark
lsmod nc pivot_root sed tar uhttpd yes brctl dbclient fgrep id jffs2reset lua netifd poweroff
seq tee umount zcat bunzip2 dd find ifconfig jshn luci-bwc netmsg pppd sh telnet uname busybox
devmem firstboot ifdown jsonfilter luci-reload netstat printf sleep telnetd uniq bzcat devstatus
free ifstatus kill md5sum nice procd snapshot test uptime cat df fsync ifup killall mkdir
nslookup ps snapshot_tool time validate_data chgrp dirname fw3 init kmodloader mkfifo ntpd pwd
sort top vconfig chmod dmesg grep insmod led.sh mknod odhcp6c readlink ssh touch vi chown dnsmasq
gunzip ip6tables less mkswap odhcpd reboot start-stop-daemon tr wc chroot dropbear gzip
ip6tables-restore ln mktemp odhcpd-update reload_config strings traceroute wget
发现有几个比较好玩的命令
以前学 C 语言的时候一直以为 printf 只是一个普通的 IO 流函数,没想到在 linux 下居然有这个命令
printf
其实这个跟 echo 差不多,但是它支持转义字符和字符串,比如这样
1 | root@OpenWrt:/# printf "haha\n\t\\haha\n" haha \haha root@OpenWrt:/# |
挺好玩的,在比如说这个命令 find,比如我要找 proc 的位置,就这样打1
find proc | more
打了这个命令之后,一下子搜到好多结果!
下面还是来说正题吧,proc 这个目录确实才是我想说的,很多关于硬件的基本信息都在这里
用 ls 看了一下 proc 目录里的东西,大概会看到这么一些文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 ls -al
/proc/ -r--r--r-- 1 root root 0 Oct 1 19:16
cmdline -r--r--r-- 1 root root 0 Oct 1 19:16
cpuinfo -r--r--r-- 1 root root 0 Oct 1 19:16
crypto -r--r--r-- 1 root root 0 Oct 1 19:16
devices -r--r--r-- 1 root root 0 Oct 1 19:16
diskstats -rw------- 1 root root 0 Oct 1 19:16
eth0.1 -rw------- 1 root root 0 Oct 1 19:16
eth0.2 -r--r--r-- 1 root root 0 Oct 1 19:16
filesystems dr-xr-xr-x 3 root root 0 Oct 1 19:16
fs -r--r--r-- 1 root root 0 Oct 1 19:16
interrupts -r--r--r-- 1 root root 0 Oct 1 19:16
iomem -r--r--r-- 1 root root 0 Oct 1 19:16
ioports -r--r--r-- 1 root root 0 Oct 1 19:16
kallsyms -r--r--r-- 1 root root 0 Oct 1 19:16
key-users -r-------- 1 root root 0 Oct 1 14:32
kmsg -r--r--r-- 1 root root 0 Oct 1 19:16
loadavg -r--r--r-- 1 root root 0 Oct 1 19:16
meminfo -r--r--r-- 1 root root 0 Oct 1 19:16
misc -r--r--r-- 1 root root 0 Oct 1 19:16
modules lrwxrwxrwx 1 root root 11 Oct 1 19:16
mounts -> self/mounts -r--r--r-- 1 root root 0 Oct 1 19:16
mtd lrwxrwxrwx 1 root root 8 Oct 1 19:16
net -> self/net -r--r--r-- 1 root root 0 Oct 1 19:16
partitions lrwxrwxrwx 1 root root 0 Jan 1 1970
self -> 18827 -r--r--r-- 1 root root 0 Oct 1 19:16
softirqs -r--r--r-- 1 root root 0 Oct 1 19:16
stat -r--r--r-- 1 root root 0 Oct 1 19:16
swaps -r--r--r-- 1 root root 0 Oct 1 19:16
uptime -r--r--r-- 1 root root 0 Oct 1 19:16
version -r--r--r-- 1 root root 0 Oct 1 19:16
vmstat
这些东西让我产生了好奇,用 cat 看了一下,比如
cat /proc/mounts
看到结果之后瞬间秒懂!
原来 mount 的命令里的数据全存在这个文件里了,它还是指向 / self/mounts 的
再来看看 meminfo
1 | cat /proc/meminfo |
这个文件里的东西还真的比 free 来的清楚!
这地方甚至还可以看到 RAM 的存储地址分布!
1 | cat iomem |
趁着这一口气,把这个文件夹里面的东西都看了个遍,看到了很多设备的数据,像 cpuinfo 能看 CPU 型号,mtd 可以看到 flash 的地址构成等等1
2
3
4
5
6
7
8
9
10
11
12
13
14
15root@OpenWrt:/proc# cat mtd
dev: size erasesize name
mtd0: 00030000 00010000 "u-boot"
mtd1: 00010000 00010000 "devdata"
mtd2: 00010000 00010000 "devconf"
mtd3: 003b0000 00010000 "firmware"
mtd4: 002ae819 00010000 "rootfs"
mtd5: 000a0000 00010000 "rootfs_data"
root@OpenWrt:/proc# cat partitions
major minor #blocks name 31 0 192 mtdblock0
31 1 64 mtdblock1
31 2 64 mtdblock2
31 3 3776 mtdblock3
31 4 2746 mtdblock4
31 5 640 mtdblock5
果然这里是个很方便的地方,在这里就可以很轻松的确认设备信息了。