alpine linux 之嵌入式搭建

目录

  • 启动
  • 修改源
  • 安装 openssh
  • 设置开机网络 ip
  • 参考

最近发现了 alpine linux 这个文件系统,这是一个基于 musl libcbusybox 的面向安全的轻量级 Linux 发行版。

下载了他的文件系统,只有 3M 多的压缩包,非常适合嵌入式系统。

地址:https://alpinelinux.org/downloads/

下载后,针对使用修改文件

  • /etc/inittab 文件中添加
ttyS2::respawn:-/bin/ash
  • /etc/securetty 文件中添加
ttyS2

此时就可启动进入系统

  • 修改 /etc/profile 文件的 PS1
PS1='alpine:\w\$ '

/etc/fstab 文件添加

proc                 /proc                proc       defaults              0  0
devpts               /dev/pts             devpts     mode=0620,gid=5       0  0
tmpfs                /tmp                 tmpfs      defaults              0  0
sysfs                /sys                 sysfs      defaults              0  0

此文件 fstab 使用 mount -a 可挂载,需新建 /dev/pts 文件夹

启动

将文件系统放到 tf 卡,设置 uboot 中的 bootargs

setenv bootargs "root=/dev/mmcblk0p4 rw rootfstype=ext4 rootwait init=/sbin/init console=ttyS2,1500000 " 

此处根据不同的硬件环境自行更换,这里使用的是 rk3588 香橙派,文件存在 tf 卡中, 在 uboot 启动命令

mmc dev 0 &&load mmc 0:3 0x02080000 Image.gz &&load mmc 0:3 0x0a100000  rk3588-orangepi-5-plus.dtb&&setenv bootargs "root=/dev/mmcblk0p4 rw rootfstype=ext4 rootwait init=/sbin/init console=ttyS2,1500000 " && booti 0x02080000 - 0x0a100000 

而后就可进入系统

设置 ip,添加网关,DNS

ifconfig eth0 192.168.1.101
route add default gw 192.168.1.XX
echo nameserver 8.8.8.8 > /etc/resolv.conf

修改源

/etc/apk/repositories 文件中的源修改成 mirrors.aliyun.com

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

此时使用命令 apk 添加应用,会出现 Permission denied,如下:

alpine linux 之嵌入式搭建_第1张图片

alpine:~# apk add openrc
fetch https://mirrors.aliyun.com/alpine/v3.18/main/aarch64/APKINDEX.tar.gz
60C015877F000000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1889:
WARNING: updating and opening https://mirrors.aliyun.com/alpine/v3.18/main: Permission denied
fetch https://mirrors.aliyun.com/alpine/v3.18/community/aarch64/APKINDEX.tar.gz
60C015877F000000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1889:
WARNING: updating and opening https://mirrors.aliyun.com/alpine/v3.18/community: Permission denied
ERROR: unable to select packages:
  openrc (no such package):
    required by: world[openrc]

此处解决需要将 https 替换成 http 即可

sed -i 's/https/http/g' /etc/apk/repositories

修改后文件内容

http://mirrors.aliyun.com/alpine/v3.18/main
http://mirrors.aliyun.com/alpine/v3.18/community

此时即可安装所需程序

alpine linux 之嵌入式搭建_第2张图片

alpine 需先行安装 openrc, 系统需要但是不带

apk add openrc

安装 openssh

apk add openssh
rc-update add sshd default   //设置开机启动
ssh-keygen -A

修改 /etc/ssh/sshd_config 内容中的两个为 yes

PermitRootLogin yes
PasswordAuthentication yes

设置系统密码,使用 passwd 即可

设置开机网络 ip

新建 /etc/network/interfaces 文件,以下内容

auto eth0
iface eth0 inet static
        address 192.168.1.101
        netmask 255.255.255.0
        gateway 192.168.1.xx

添加开机启动

rc-update add networking default

重启后即可登录

alpine linux 之嵌入式搭建_第3张图片
若登录后无法显示界面,可查看 devpts 是否正常挂载。

参考

http://bbs.eeworld.com.cn/thread-1259967-1-1.html

你可能感兴趣的:(arm,linux,linux,嵌入式)