rk3568 定制Ubuntu根文件系统

rk3568 制作 Ubuntu20.04 系统

瑞芯微平台提供SDK支持buildroot、Debian、yocto,但Ubuntu需要自行定制文件系统。

作者:炭烤毛蛋 ,点击博主了解更多。


提示:操作过程注意仿真文件系统挂载、卸载。


前期准备

  • 下载Ubuntu核
    Ubuntu 基础镜像地址 https://cdimage.ubuntu.com/ubuntu-base/releases
    ubuntu20.04.5
    Ubuntu可以选择14.04.1–23.10版本作为基础镜像,本文选择 20.04.5 为基础版本。由于rk3568内核为arm64,需要为armhf 或者arm64,本文选择 arm64 64位为基础点。
#下载 Ubuntu20.04.5 基础镜像
# ubuntu-base-20.04.5-base-arm64.tar.gz
wget https://cdimage.ubuntu.com/ubuntu-base/releases/20.04.5/release/ubuntu-base-20.04.5-base-arm64.tar.gz
# ubuntu-base-20.04.5-base-arm64.tar.gz.zsync
wget https://cdimage.ubuntu.com/ubuntu-base/releases/20.04.5/release/ubuntu-base-20.04.5-base-arm64.tar.gz.zsync
  • 安装 qemu 模拟器
sudo apt install qemu-user-static
  • 编写 ch-mount
#!/bin/bash
function mnt() {
    echo "mounting filesystem"
    sudo mount -t proc /proc ${2}/proc
    sudo mount -t sysfs /sys ${2}/sys
    sudo mount -o bind /dev ${2}/dev
    #sudo mount -t devpts -o gid=5,mode=620 devpts ${2}dev/pts
    sudo mount -o bind /dev/pts ${2}/dev/pts
    sudo chroot ${2}
}

function umnt() {
    echo "unmounted filesystem"
    sudo umount ${2}/proc
    sudo umount ${2}/sys
    sudo umount ${2}/dev/pts
    sudo umount ${2}/dev
}

if [ "$1" == "-m" ] && [ -n "$2" ];
then
        mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
        umnt $1 $2
else
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with tralling '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : $[2]
fi

ch-mount 脚本需要增加执行权

#增加脚本执行权限
sudo chmod +x ch-mount

ch-mount 使用示例

#挂载根文件系统
./ch-mount -m ubuntu20.04.5/
#退出根文件系统
exit
#卸载根文件系统
./ch-mount -u ubuntu20.04.5/

注意:挂载和卸载文件系统需要成对操作,不可遗漏。

1. 进入根文件系统,预装软件

1.1 仿真运行 Ubuntu20.04.5 基础系统

  1. 解包基础镜像
mkdir -p ubuntu-20.04.5
tar -zxf ubuntu-base-20.04.5-base-arm64.tar.gz -C ubuntu-20.04.5/
  1. 仿真运行Ubuntu基础包
    Ubuntu 20.04.5增加仿真运行所需 qemu
sudo cp /usr/bin/qemu-aarch64-static ubuntu-20.04.5/usr/bin/

# 配置与宿主机相同网络,方便上网和接下来安装软件
cp /etc/resolv.conf ubuntu-20.04.5/etc/

挂载根文件系统
./mount.sh -m ubuntu-20.04.5/


`注意:退出qemu仿真运行环境需要卸载挂载。`
```bash
#退出根文件系统
exit
#卸载根文件系统
./mount.sh -u ubuntu-20.04.5/

1.2 安装Ubuntu基础软件

  • 根据需求安装基础软件
# 语言包
apt install language-pack-en-base language-pack-zh-han*
# 网络工具
apt install net-tools udhcpc netplan.io iputils-ping wireless-tools 
# 系统工具
apt install sudo vim udev ntp usbutils alsa-utils libmtp9 openssh-sftp-server

安装软件过程发现 temp目录缺少权限,致使无法软件安装失败。

Get:1 http://mirrors.aliyun.com/ubuntu-ports focal InRelease [265 kB]
Err:1 http://mirrors.aliyun.com/ubuntu-ports focal InRelease
  Couldn't create temporary file /tmp/apt.conf.nDpyRM for passing config to apt-key
Get:2 http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease [114 kB]
Err:2 http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease
  Couldn't create temporary file /tmp/apt.conf.mTSAKB for passing config to apt-key
Get:3 http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease [108 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports jammy InRelease [270 kB]
Err:3 http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease
  Couldn't create temporary file /tmp/apt.conf.JPezFp for passing config to apt-key
Get:5 http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease [114 kB]
Err:5 http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease
  Couldn't create temporary file /tmp/apt.conf.Dss2ix for passing config to apt-key
Err:4 http://ports.ubuntu.com/ubuntu-ports jammy InRelease
  Couldn't create temporary file /tmp/apt.conf.WdLihz for passing config to apt-key
Get:6 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease [119 kB]
Err:6 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
  Couldn't create temporary file /tmp/apt.conf.GzJb1z for passing config to apt-key
Get:7 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease [109 kB]
Err:7 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease
  Couldn't create temporary file /tmp/apt.conf.2ddPRd for passing config to apt-key
Get:8 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease [110 kB]
Err:8 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease
  Couldn't create temporary file /tmp/apt.conf.I9E63S for passing config to apt-key
Reading package lists... Done
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports focal InRelease: Couldn't create temporary file /tmp/apt.conf.nDpyRM for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports focal InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease: Couldn't create temporary file /tmp/apt.conf.mTSAKB for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease: Couldn't create temporary file /tmp/apt.conf.JPezFp for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease: Couldn't create temporary file /tmp/apt.conf.Dss2ix for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports jammy InRelease: Couldn't create temporary file /tmp/apt.conf.WdLihz for passing config to apt-key
E: The repository 'http://ports.ubuntu.com/ubuntu-ports jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease: Couldn't create temporary file /tmp/apt.conf.GzJb1z for passing config to apt-key
E: The repository 'http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease: Couldn't create temporary file /tmp/apt.conf.2ddPRd for passing config to apt-key
E: The repository 'http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease: Couldn't create temporary file /tmp/apt.conf.I9E63S for passing config to apt-key
E: The repository 'http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

日志提示: /tmp目录无法创建文件夹,需要为其增加相关权限。

# 省事可直接赋值
chmod 777 /tmp
  • 精简软件包(卸载非必须软件)
apt-get remove --purge lubuntu-update-notifier 
apt-get remove --purge libreoffice* 

如果无需桌面,Ubuntu系统基础软件安装已经结束。

1.2 安装Ubuntu桌面

安装桌面命令开始后,就是漫长下载资源包。。

apt-get install ubuntu-desktop

资源包下载完成则会进行基础系统设时区、键盘,根据提示自行选择即可。

Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities,
representing the time zones in which they are located.

  1. Africa  2. America  3. Antarctica  4. Australia  5. Arctic  6. Asia  7. Atlantic  8. Europe  9. Indian  10. Pacific  11. US  12. Etc

Geographic area: 6

Please select the city or region corresponding to your time zone.

  1. Aden      13. Barnaul     25. Dushanbe     37. Jerusalem     49. Macau         61. Pyongyang      73. Taipei         85. Vientiane
  2. Almaty    14. Beirut      26. Famagusta    38. Kabul         50. Magadan       62. Qatar          74. Tashkent       86. Vladivostok
  3. Amman     15. Bishkek     27. Gaza         39. Kamchatka     51. Makassar      63. Qostanay       75. Tbilisi        87. Yakutsk
  4. Anadyr    16. Brunei      28. Harbin       40. Karachi       52. Manila        64. Qyzylorda      76. Tehran         88. Yangon
  5. Aqtau     17. Chita       29. Hebron       41. Kashgar       53. Muscat        65. Rangoon        77. Tel_Aviv       89. Yekaterinburg
  6. Aqtobe    18. Choibalsan  30. Ho_Chi_Minh  42. Kathmandu     54. Nicosia       66. Riyadh         78. Thimphu        90. Yerevan
  7. Ashgabat  19. Chongqing   31. Hong_Kong    43. Khandyga      55. Novokuznetsk  67. Sakhalin       79. Tokyo
  8. Atyrau    20. Colombo     32. Hovd         44. Kolkata       56. Novosibirsk   68. Samarkand      80. Tomsk
  9. Baghdad   21. Damascus    33. Irkutsk      45. Krasnoyarsk   57. Omsk          69. Seoul          81. Ujung_Pandang
  10. Bahrain  22. Dhaka       34. Istanbul     46. Kuala_Lumpur  58. Oral          70. Shanghai       82. Ulaanbaatar
  11. Baku     23. Dili        35. Jakarta      47. Kuching       59. Phnom_Penh    71. Singapore      83. Urumqi
  12. Bangkok  24. Dubai       36. Jayapura     48. Kuwait        60. Pontianak     72. Srednekolymsk  84. Ust-Nera
Time zone: 70


debconf: falling back to frontend: Readline
Configuring keyboard-configuration
----------------------------------

The layout of keyboards varies per country, with some countries having multiple common layouts. Please select the country of origin for the
keyboard of this computer.

  1. Afghani                       35. Faroese                                    69. Mongolian
  2. Albanian                      36. Filipino                                   70. Montenegrin
  3. Amharic                       37. Finnish                                    71. Nepali
  4. Arabic                        38. French                                     72. NKo (AZERTY)
  5. Arabic (Morocco)              39. French (Canada)                            73. Norwegian
  6. Arabic (Syria)                40. French (Democratic Republic of the Congo)  74. Persian
  7. Armenian                      41. French (Togo)                              75. Polish
  8. A user-defined custom Layout  42. Georgian                                   76. Portuguese
  9. Azerbaijani                   43. German                                     77. Portuguese (Brazil)
  10. Bambara                      44. German (Austria)                           78. Romanian
  11. Bangla                       45. Greek                                      79. Russian
  12. Belarusian                   46. Hebrew                                     80. Serbian
  13. Belgian                      47. Hungarian                                  81. Sinhala (phonetic)
  14. Berber (Algeria, Latin)      48. Icelandic                                  82. Slovak
  15. Bosnian                      49. Indian                                     83. Slovenian
  16. Braille                      50. Indonesian (Javanese)                      84. Spanish
  17. Bulgarian                    51. Indonesian (Latin)                         85. Spanish (Latin American)
  18. Burmese                      52. Iraqi                                      86. Swahili (Kenya)
  19. Chinese                      53. Irish                                      87. Swahili (Tanzania)
  20. Croatian                     54. Italian                                    88. Swedish
  21. Czech                        55. Japanese                                   89. Switzerland
  22. Danish                       56. Japanese (PC-98)                           90. Taiwanese
  23. Dhivehi                      57. Kazakh                                     91. Tajik
  24. Dutch                        58. Khmer (Cambodia)                           92. Thai
  25. Dzongkha                     59. Korean                                     93. Tswana
  26. English (Australian)         60. Kyrgyz                                     94. Turkish
  27. English (Cameroon)           61. Lao                                        95. Turkmen
  28. English (Ghana)              62. Latvian                                    96. Ukrainian
  29. English (Nigeria)            63. Lithuanian                                 97. Urdu (Pakistan)
  30. English (South Africa)       64. Macedonian                                 98. Uzbek
  31. English (UK)                 65. Malay (Jawi, Arabic Keyboard)              99. Vietnamese
  32. English (US)                 66. Maltese                                    100. Wolof
  33. Esperanto                    67. Maori
  34. Estonian                     68. Moldavian
Country of origin for the keyboard: 7

lease select the layout matching the keyboard for this machine.

  1. Armenian                            3. Armenian - Armenian (alt. phonetic)  5. Armenian - Armenian (phonetic)
  2. Armenian - Armenian (alt. eastern)  4. Armenian - Armenian (eastern)        6. Armenian - Armenian (western)
Keyboard layout: 1

You will need a way to toggle the keyboard between the national layout and the standard Latin layout.

Right Alt or Caps Lock keys are often chosen for ergonomic reasons (in the latter case, use the combination Shift+Caps Lock for normal Caps
toggle). Alt+Shift is also a popular combination; it will however lose its usual behavior in Emacs and other programs that use it for specific
needs.

Not all listed keys are present on all keyboards.

  1. Caps Lock          4. Right Shift     7. Alt+Shift      10. Alt+Caps Lock            13. Left Control   16. Scroll Lock key
  2. Right Alt (AltGr)  5. Right Logo key  8. Control+Shift  11. Left Control+Left Shift  14. Left Shift     17. No toggling
  3. Right Control      6. Menu key        9. Control+Alt    12. Left Alt                 15. Left Logo key
Method for toggling between national and Latin mode: 17

1.3 系统建议修改选项

纯净系统安装完成后,会有部分定制化工作。如果喜欢默认登录用户为 Ubuntu,可以略某些设置。

1.3.1 修改主机名

echo "rk3568" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 rk3568" >> /etc/hosts

1.3.2 配置网卡DHCP

如果存在两个网口,希望同时使用则需要额外配置。

vim /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp

source-directory /etc/network/interfaces.d

根据实际情况选择网卡酌情选择开启网卡,系统启动后可自行修改。

1.3.3 配置网卡白名单

配置网卡:Network-Manager服务会自动配置网卡,但是其默认配置文件将Ethernet加入了黑名单,以至于以太网不能用,找不到网卡

vim /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf

+[keyfile]
+unmanaged-devices=*,except:type:ethernet,except:type:wifi,except:type:gsm,except:type:cdma

1.3.4 系统等待时间

  • 网络超时时间
    默认等待网络接入后才开机,无网络会等待5分钟网络连接超时才跳过该步骤。体验感非常差,建议改为5s。

vim /lib/systemd/system/networking.service

TimeoutStartSec=5min 修改为TimeoutStartSec=5sec。

-TimeoutStartSec=5min
+TimeoutStartSec=5sec
  • 开机等待时间
    此外还有系统默认等待时间90s,建议改为2s。方法解除相关注释,改为2秒。

vim /etc/systemd/system.conf

解除 DefaultTimeoutStopSec=90s 注释,改为DefaultTimeoutStopSec=2s。

-#DefaultTimeoutStopSec=90s
DefaultTimeoutStopSec=2s

1.3.5 禁用系统休眠

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

2. 系统属性设置

2.1 设置开机串口免密登录

修改自动登录配置文件,改为允许自动登录。
vim /etc/gdm3/custom.conf

[daemon]
# Uncomment the line below to force the login screen to use Xorg
#WaylandEnable=false

# Enabling automatic login
-#  AutomaticLoginEnable = true
-#  AutomaticLogin = user1
AutomaticLoginEnable=true
AutomaticLogin=ubuntu

# Enabling timed login
-#  TimedLoginEnable = true
-#  TimedLogin = user1
-#  TimedLoginDelay = 10
+TimedLoginEnable=true
+TimedLogin=root
+TimedLoginDelay=10

vim /etc/pam.d/gdm-password
注释:#auth required pam_succeed_if.so user != root quiet_success

#%PAM-1.0
auth    requisite       pam_nologin.so
-auth    required        pam_succeed_if.so user != root quiet_success
+#auth    required        pam_succeed_if.so user != root quiet_success
@include common-auth

vim /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf

[Seat:*]
user-session=ubuntu
+greeter-show-manual-login=true
+all-guest=false

vim /etc/pam.d/gdm-autologin

#%PAM-1.0
auth    requisite       pam_nologin.so
-auth    required        pam_succeed_if.so user != root quiet_success
+#auth    required        pam_succeed_if.so user != root quiet_success
auth    optional        pam_gdm.so

vi /root/.profile

  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

-# mesg n 2> /dev/null || true
+ tty -s && mesg n || true

2.2 串口自动登陆

vim /lib/systemd/system/serial-getty@.service
注释:ExecStart=-/sbin/agetty -o ‘-p – \u’ --keep-baud 115200,38400,9600 %I $TERM
修改:ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM

[Service]
# The '-o' option value tells agetty to replace 'login' arguments with an
# option to preserve environment (-p), followed by '--' for safety, and then
# the entered username.
-ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,57600,38400,9600 %I $TERM
+ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
Type=idle

2.3 根目录自动释放可用存储

默认是对/dev/mmcblk0p6分区进行扩充,创建一个脚本resizedata.sh和服务来扩充分区。需要删除rootfs分区之后其它分区。
vim etc/init.d/resizedata.sh

#!/bin/bash -e

# resize mmcblk0p6-->filesystem
if [ ! -e "/usr/local/first_boot_flag" ] ;
then
  echo "Resizing /dev/mmcblk0p6..."
  resize2fs /dev/mmcblk0p6
  touch /usr/local/first_boot_flag
fi

为 resizedata.sh 增加执行权限。

chmod +x etc/init.d/resizedata.sh

创建resizedata.service服务,并设置开机自动运行脚本。
vim lib/systemd/system/resizedata.service

#start
[Unit]
Description=Setup wmc-rockchip platform environment
Before=lightdm.service
After=resize-helper.service

[Service]
User=root
Group=root
Type=simple
ExecStart=/etc/init.d/resizedata.sh

[Install]
WantedBy=multi-user.target
#end

服务设置开机自启: systemctl enable resizedata.service。

resizedata服务脚本无法正常运行,会出现卡在登录界面或者开机logo。
此时系统可以正常登录,因文件系统无法正常加载,也就是界面无切换。自助重置 rootfs 分区即可解决。

resize2fs -p /dev/mmcblk0p6

3. 打包文件系统镜像

  • 创建文件系统镜像
# 创建镜像文件, 文件大小6G
dd if=/dev/zero of=ubuntu20.04.5.img bs=1M count=6144
# 格式化为 ext4
```bash
mkfs.ext4 ubuntu20.04.5.img
  • 转录文件系统
    镜像文件先挂载到一个空的文件夹rootfs,然后将ubuntu20.04.5的文件复制到该rootfs文件夹。
mkdir rootfs
sudo mount ubuntu20.04.5.img rootfs
sudo cp -rfp ubuntu20.04.5/* rootfs/
sudo umount rootfs/
  • 检测文件系统
    卸载后系统镜像文件需要用e2fsck修复及检测,以及缩减镜像。
e2fsck -p -f ubuntu20.04.5.img
resize2fs -M ubuntu20.04.5.img

制作完成的 Ubuntu20.04.5.img 可以直接刷到 rootfs.img 分区。

Tips

  1. 文件系统仅仅为基础软件,GPU、VPU需要根据芯片自行安装。
  2. 文件系统仅包含alsa基础设置声卡配置需要自行修改。
  3. 文件系统不包含蓝牙、WiFi的驱动,也需要自行处理。

结语

不枉博主详细讲解,欢迎订阅博主–炭烤毛蛋

  • 33
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值