11.构建Ubuntu系统

rootfs系列文章:

  1. 构建最小根文件系统
  2. 根文件系统构建(2)
  3. 构建Ubuntu系统
下载根文件系统

ubuntu的rootfs一般去官网下载就好:http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/
也可以用debootstrap去制作,我比较懒,还是自己下载吧。如果是32位的cpu就下载带armhf的,如果是64位的cpu就下载带有arm64的包体。

解压
mkdir rootfs
#创建文件夹
sudo tar -zxvf ubuntu-base-16.04.1-base-amd64.tar.gz -C rootfs
#需要使用root权限去解压
拷贝qemu
sudo apt-get install qemu-user-static
#安装qemu
sudo cp /usr/bin/qemu-arm-static rootfs/usr/bin/
sudo cp /usr/bin/qemu-aarch64-static rootfs/usr/bin/
替换软件源
cp rootfs/etc/apt/sources.list rootfs/etc/apt/sources.list.bak
#备份一下主站源
nano rootfs/etc/apt/sources.list
#替换位如下内容
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial main
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial universe
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe
拷贝dns配置

拷贝一下DNS配置,不然等下chroot进去没法上网

cp /etc/resolv.conf rootfs/etc/
添加挂载脚本

来自网络,我做了点修改,推出后自动umount
ch-mount.sh

#!/bin/bash

function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc ${1}/proc
    sudo mount -t sysfs /sys ${1}/sys    
    sudo mount -o bind /dev ${1}/dev
    sudo mount -o bind /run ${1}/run 
    sudo chroot ${1}
}

function umnt() {
    echo "UNMOUNTING"
    sudo umount ${1}/proc
    sudo umount ${1}/sys
    sudo umount ${1}/dev
    sudo umount ${1}/run
}


if [ -n "$1" ] ;
then
    mnt $1
    umnt $1
else
    echo ""
    echo "Either 1'st parameters were missing"
    echo ""
    echo "1'st parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount /media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
fi
添加OLDPWD环境变量

OLDPWD环境变量保存了上一次的路径,不设置会导致cd -无法使用,出现-bash:cd:OLDPWD not set错误,下面来设置一下。

nano /etc/bash.bashrc
#末尾添加以下内容
export OLDPWD="/"
进入系统

使用上面的脚本一键挂载chroot进入新系统

ch-mount.sh rootfs
#进入后显示下面这样说明成功了
root@ubuntu:/# 
修改机器名
nano /etc/hostname
#自己发挥吧
修改root密码
passwd
添加用户
adduser xxx
#自行发挥
添加中文支持
apt install language-pack-zh-hans
nano /etc/defaults/locale
#末尾添加
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
LC_NUMERIC="zh_CN"
LC_TIME="zh_CN"
LC_MONETARY="zh_CN"
LC_PAPER="zh_CN"
LC_NAME="zh_CN"
LC_ADDRESS="zh_CN"
LC_TELEPHONE="zh_CN"
LC_MEASUREMENT="zh_CN"
LC_IDENTIFICATION="zh_CN"
LC_ALL="zh_CN.UTF-8"

nano /etc/environment
#末尾添加
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
LC_NUMERIC="zh_CN"
LC_TIME="zh_CN"
LC_MONETARY="zh_CN"
LC_PAPER="zh_CN"
LC_NAME="zh_CN"
LC_ADDRESS="zh_CN"
LC_TELEPHONE="zh_CN"
LC_MEASUREMENT="zh_CN"
LC_IDENTIFICATION="zh_CN"
LC_ALL="zh_CN.UTF-8"
切换到root用户

语言配置好后必须要切换到一个用户才有效,以免以后安装软件遇到一些莫名其妙的错误。

su root
#先切换到root用户,后面安装软件才不会出现语言问题
locale
#执行上面的命令不会报错就可以了
配置挂载点
nano /etc/fstab
#一共六列:设备 挂接点 文件系统(auto) 参数(defaults) dunp备份(0) 是否检查(根目录为1,其他为0)
/dev/mmcblk0p7 / auto defaults 0 1
安装必要命令 sudo ethtool net-tools wireless-tools inetutils-ping ssh
apt update
apt install sudo			# sudo
apt install ethtool			# 网卡管理工具
apt install net-tools		# ifconfig等
apt install wireless-tools	# wifi配置工具
apt install inetutils-ping	# ping
apt install ssh				# ssh
配置网络接口

上一步安装了ethtool会在etc目录下生成network文件夹,安装了inetutils-ping 会在network下面创建基本的interfaces网卡配置文件,这个时候才可以配置网卡

nano /etc/network/interfaces
#末尾插入,eth0是我的网卡,配置成dhcp
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
安装sudo 配置/etc/sudoers

安装了sudo还需要吧自己创建的用户加到sudoers里面才可以使用sudo

nano /etc/sudoers
#照着root写一份自己的就行
安装桌面环境

桌面系统按需安装

apt install ubuntu-mate-desktop
制作固件,分盘封装

最后需要制作固件的可以将etc,usr,home等文件夹分到不同分区,剩下的做成ramrootfs,启动的时候挂载

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值