树莓派俱乐部 树莓派俱乐部
  • 首页
  • 树莓派
  • OpenWrt
  • Python
  • Linux
  • 注册
    登录
现在登录。
  • 首页
  • 树莓派
  • OpenWrt
  • Python
  • Linux
首页 Linux 如何构建树莓派64位系统(1)构建根目录

如何构建树莓派64位系统(1)构建根目录

chainsx 5 年 前

构建根目录这里推荐在ubuntu-18.04上进行构建。

第一步,安装所需软件包

sudo apt install debootstrap debian-keyring qemu-user-static

第二步,使用debootstrap创建根目录,如果你觉得debootstrap太慢的话你可以换成cdebootstrap

mkdir rootfs
sudo debootstrap --arch=arm64 --foreign --no-check-gpg buster ./rootfs http://mirrors.tuna.tsinghua.edu.cn/debian
cp /usr/bin/qemu-aarch64-static rootfs/usr/bin/
cd rootfs
LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stage
LC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a

这里使用清华镜像源,默认构建Debian10(buster),如果你需要Debian9(stretch)就换成stretch,类似的8就是jessie,7是wheezy

或者是,你想要32位的你就把arm64换成armhf,或者,换成armel。。。

等一会如果没有报错的话,就进入下一步。

第三步,安装自己所需软件

然后安装自己所需的软件包

LC_ALL=C LANGUAGE=C LANG=C chroot rootfs apt-get install -y sudo ssh net-tools ethtool wireless-tools network-manager iputils-ping rsyslog alsa-utils bash-completion gnupg busybox kmod --no-install-recommends

这里提供了一些最基本的软件包

后面我们会讲如何安装64位pixel桌面。

然后为此系统添加用户,假设系统用户名为pi

chroot rootfs adduser pi && addgroup pi adm && addgroup pi sudo && addgroup pi audio

然后需要输入一些信息,前面的你可以随便填,但是到了密码就别乱填了,想好再填。

然后呢,我们需要开启对于armhf的兼容(可选)

chroot rootfs dpkg --add-architecture armhf
chroot rootfs apt-get install libc6:armhf

甚至,你可以开启armel的兼容(有点没必要)

chroot rootfs dpkg --add-architecture armel
chroot rootfs apt-get install libc6:armel

以上完成之后,根目录的构建就完成一大半了,这时你需要清理安装缓存

chroot rootfs apt clean

别忘了删掉qemu

rm rootfs/usr/bin/qemu-aarch64-static

接下来就开始配置根目录

添加hosts

echo '127.0.0.1	raspberrypi' >> rootfs/etc/hosts

编辑主机名为raspberrypi

cat /dev/null > $ROOTFS/etc/hostname
echo 'raspberrypi' >> $ROOTFS/etc/hostname

编辑fstab挂载信息

cat <<EOF >> $ROOTFS/etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p2  /boot           ext4    defaults          0       0
/dev/mmcblk0p1  /boot/efi       vfat    defaults          0       2
/dev/mmcblk0p3  /               f2fs    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
tmpfs /var/run tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0
tmpfs /var/spool/mqueue tmpfs defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0
EOF

这里为了更好的性能,添加了tmpfs,如果你的树莓派24h做下载机的,这样会很有用,如果你不需要你也可以删掉所有tmpfs开头的行。

然后下载一些设备的firmware

cd root/lib
git clone https://github.com/rpi-distro/firmware-nonfree
mv firmware-nonfree firmware
rm -rf firmware/.git

到了这里,一个根目录就构建好了,我们以后还会讲下一步该怎么做。

#64位#arm64#树莓派#系统构建
11
等 11 人赞过
chainsx
嗷?
评论 (8)
返回
  • nan

    操作目录太不清晰了,容易导致错误

    2 年 前 回复
    • nan

      @nan 建议在各命令前注释一下当前目录位置

      2 年 前 回复
  • a

    sudo: unable to stat /etc/sudoers: Permission denied
    sudo: no valid sudoers sources found, quitting
    sudo: unable to initialize policy plugin
    这个错误怎么解决呢

    5 年 前 回复
  • 158633416852

    手头就一台MacBook pro 2012的,想在docker ubuntu镜像里搞,搞不起来

    5 年 前 回复
  • 158633416852

    强烈建议出一期 视频 教程啊...有up或者头条之类的不大大

    5 年 前 回复
  • 林大大

    如果在x86电脑上,使用“sudo debootstrap --arch=arm64 buster ./rootfs http://mirrors.tuna.tsinghua.edu.cn/debian”时,报错
    ”E: Unable to execute target architecture“
    可以先“sudo apt-get install -y bc build-essential gcc-aarch64-linux-gnu flex libncurses5-dev”
    然后用“sudo debootstrap --foreign --include linux-image-arm64 --arch=arm64 buster ./rootfs http://mirrors.tuna.tsinghua.edu.cn/debian”

    5 年 前 回复
    • 林大大

      @林大大 但这样的话,这步“chroot rootfs apt-get install -y sudo ssh net-tools ethtool wireless-tools network-manager iputils-ping rsyslog alsa-utils bash-completion gnupg busybox kmod --no-install-recommends”又会报错“Err:1 http://debootstrap.invalid buster/main arm64 libbluetooth3 arm64 5.50-1
      Could not resolve 'debootstrap.invalid'
      ”
      尴尬。。。。。。

      5 年 前 回复
    • chainsx

      @林大大 如果在执行debootstrap出错的话要把原来的rootfs删掉再新建,再重新执行命令,在没有任何报错的情况下再执行chroot,如果觉得debootstrap速度太慢的话可以换用cdebootstrap。

      5 年 前 回复
猜你喜欢
  • 树莓派4B安装Windows10桌面版
  • 在树莓派上使用RaspAP开启热点
  • 树莓派3B Windows 10桌面版安装GPU驱动
  • 树莓派3B安装Windows10桌面版
chainsx
嗷?
23
文章
16
评论
324
获赞
文章聚合
自定义树莓派分辨率
6 年 前
树莓派 Ubuntu 18.04.2 设置DNS
6 年 前
树莓派Ubuntu 19.04安装PHP7.3
6 年 前
如何在 Raspberry Pi 上安装 Xrdp Server (远程桌面)
5 年 前
树莓派俱乐部官方 Debian 系统镜像 支持UEFI
5 年 前
  • 首页
Copyright © 2018-2025 树莓派俱乐部. Designed by nicetheme.