泰福 發表於 2024-4-30 19:26:00

Debian文件系统构建

<h3 align="left"><strong>1</strong><strong>、环境配置</strong></h3>
<p>  sudo apt install qemu-user-static -y</p>
<p>  sudo apt install debootstrap -y</p>
<p>  mkdir Debian_rootfs</p>
<h3>2、Debian文件系统构建</h3>
<h4><strong>  &nbsp; 第一阶段:</strong> 使用华为镜像源抽取根文件系统</h4>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sudo debootstrap –foreign --verbose --arch=armhf buster rootfs http://mirrors.huaweicloud.com/debian/</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数;<strong>arch</strong>代表架构,armhf (支持硬件浮点)、armel (软浮点);<strong>verbose</strong>表示不打印wget等包下载数据,进行静默安装;<strong>buster</strong>代表Debian发行版本代号。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<div align="center">
<table style="width: 500px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"><strong>版本号</strong></p>
</td>
<td>
<p align="center"><strong>代号</strong></p>
</td>
<td>
<p align="center"><strong>备注</strong></p>
</td>
</tr>
<tr>
<td>
<p align="center"><strong>Debian 11</strong></p>
</td>
<td>
<p align="center"><strong>bullseye</strong></p>
</td>
<td>
<p align="center"><strong>稳定版</strong></p>
</td>
</tr>
<tr>
<td>
<p align="center"><strong>Debian 10</strong></p>
</td>
<td>
<p align="center"><strong>buster</strong></p>
</td>
<td>
<p align="center"><strong>旧稳定版</strong></p>
</td>
</tr>
<tr>
<td>
<p align="center"><strong>Debian 9</strong></p>
</td>
<td>
<p align="center"><strong>stretch</strong></p>
</td>
<td>
<p align="center"><strong>旧稳定版</strong></p>
</td>
</tr>
</tbody>
</table>
</div>
<h4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>第二阶段:</strong> 使用<strong>qemu-user-static</strong><strong>模拟</strong><strong>ARM</strong><strong>系统</strong>运行所有程序包配置脚本</h4>
<p><strong>  1</strong><strong>)文件挂载:</strong></p>
<p>  cd rootfs</p>
<p>  sudo mount --bind /dev &nbsp;dev/</p>
<p>  sudo mount --bind /sys &nbsp;sys/</p>
<p>  sudo mount --bind /proc &nbsp;proc/</p>
<p>  sudo mount --bind /dev/pts &nbsp;dev/pts/</p>
<p><strong>  2</strong><strong>)</strong><strong>chroot</strong><strong>切换根目录:</strong></p>
<p>  sudo &nbsp;cp &nbsp;/usr/bin/qemu-arm-static&nbsp; usr/bin/</p>
<p>  然后<strong>在</strong><strong>Debian_rootfs</strong><strong>目录下</strong>执行下面的命令:</p>
<p>  sudo LC_ALL=C LANGUAGE=C LANG=C chroot rootfs /debootstrap/debootstrap --second-stage –verbose</p>
<h3>3、Debian文件系统配置</h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 使用下面的命令<strong>进入</strong><strong>qemu</strong><strong>虚拟器</strong></p>
<p>  sudo LC_ALL=C LANGUAGE=C LANG=C chroot rootfs</p>
<h4><strong>  1&gt;</strong><strong>更新源</strong></h4>
<p>    vi /etc/apt/sources.list</p>
<p>    #写入: deb http://mirrors.huaweicloud.com/debian buster main</p>
<p>    apt-get update</p>
<p>&nbsp;</p>
<h4><strong>  2&gt;</strong><strong>安装网络相关库</strong></h4>
<p>    apt-get install wpasupplicant&nbsp; &nbsp; &nbsp; &nbsp;   &nbsp; #安装WIFI配置相关的组件</p>
<p>    apt-get install net-tools&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #安装网络基础组件、如使用ifconfig等</p>
<p>    apt-get install udhcpc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     #当wifi连接成功后,需要用这个组件去获取IP地址</p>
<p>    apt-get install evtest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     #触摸屏测试</p>
<p>    apt-get install mplayer</p>
<p>    apt-get install alsa-utils&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   #音频测试</p>
<p>&nbsp;</p>
<p>  ## 其他组件</p>
<p>    apt-get install wireless-tools</p>
<p>    apt install sudo vim openssh-server htop</p>
<p>    apt install pciutils usbutils acpi &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #acpi我没有安装成功,换了其他的源也不可以</p>
<p>&nbsp;</p>
<h4><strong>  3&gt;</strong><strong>配置账号</strong></h4>
<p>    passwd root</p>
<h4><strong>  4&gt;</strong><strong>配置时区</strong></h4>
<p>    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</p>
<h4><strong>  5&gt;</strong><strong>配置SSH</strong></h4>
<p>    vi /etc/ssh/sshd_config</p>
<p>    PermitRootLogin &nbsp;yes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #写入sshd_config</p>
<p>&nbsp;</p>
<h4><strong>  6&gt;rootfs</strong><strong>打包</strong></h4>
<p>    apt clean&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#清理</p>
<p>    exit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #退出chroot</p>
<p>    rm rootfs/ usr/bin/qemu-arm-static &nbsp;&nbsp;&nbsp;&nbsp;   #删除之前拷贝的文件</p>
<p>&nbsp;</p>
<p>    cd rootfs</p>
<p>    sudo umount&nbsp;&nbsp; dev/pts/ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 一定要在/dev前面umount</p>
<p>    sudo umount&nbsp;&nbsp; dev/</p>
<p>    sudo umount&nbsp;&nbsp; sys/</p>
<p>    sudo umount&nbsp;&nbsp; proc/</p>
<h3><strong>4</strong><strong>、创建新用户</strong></h3>
<p align="left">  创建新用户:</p>
<p align="left">    sudo useradd demo</p>
<p align="left">  设置或更改用户密码:</p>
<p align="left">    sudo passwd demo</p>
<p align="left">  添加用户到特定用户组:sudo usermod -a -G group_name new_user</p>
<p align="left">    sudo usermod -a -G root demo</p>
<p align="left">  给用户添加sudo权限,以便能够执行管理员命令:</p>
<p align="left">    echo 'demo ALL=(ALL:ALL) ALL' | sudo tee /etc/sudoers.d/demo</p>
<p align="left">    sudo chmod 0440 /etc/sudoers.d/demo</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/linux-learn/p/18168589
頁: [1]
查看完整版本: Debian文件系统构建