ubuntu根文件系統(tǒng)制作

1.準備工作

? ? 1.1下載最小文件系統(tǒng)

????????到ubuntu網(wǎng)址 下載相應(yīng)的最小系統(tǒng)(本文以 ubuntu-base-16.04.5-base-arm64.tar.gz?為例)

????1.2安裝模擬器工具

? ??????$sudo apt-get install qemu-user-static

?2.解壓最小系統(tǒng)

?????$mkdir ubuntu-rootfs

????$sudo tar -xvpf ubuntu-base-16.04.5-base-armhf.tar.gz?-C ubuntu-rootfs

3.復(fù)制模擬器工具到根文件系統(tǒng)

? ??(1) arm

????$sudo cp /usr/bin/qemu-arm-static ubuntu-rootfs/usr/bin/

? ? (2)arm64

????$sudo cp /usr/bin/qemu-aarch64-static?ubuntu-rootfs/usr/bin/

4.復(fù)制本地DNS配置到根文件系統(tǒng)

? ??$sudo cp /etc/resolv.conf ubuntu-rootfs/etc/resolv.conf

5.添加開機啟動腳本

? ??$sudo vim ubuntu-rootfs/etc/init.d/firstboot.sh

? ??#!/bin/bash -e

????# first boot configure

????#根據(jù)實際分區(qū)情況修改mmcblk2p3

????if [ ! -e "/usr/local/first_boot_flag" ] ;

????then

????echo "Resizing /dev/mmcblk2p3..."

????resize2fs /dev/mmcblk2p3

????touch /usr/local/first_boot_flag

????fi

? ??$sudo vim ubuntu-rootfs/lib/systemd/system/firstboot.service

????#start

????[Unit]

????Description=Setup rockchip platform environment

????Before=lightdm.service

? ? ?After=resize-helper.service

????[Service]

????Type=simple

????ExecStart=/etc/init.d/firstboot.sh

????[Install]

????WantedBy=multi-user.target

????#end

6.掛載根文件系統(tǒng),進入根文件系統(tǒng)

? ??$./mount.sh -m linux-rootfs

? ? mount.sh的內(nèi)容

? ??#!/bin/bash

????function mnt() {

? ? echo "MOUNTING"

? ? sudo mount -t proc /proc ${2}/proc

? ? sudo mount -t sysfs /sys ${2}/sys

? ? sudo mount -o bind /dev ${2}/dev

? ? sudo chroot ${2}

????}

????function umnt() {

? ? echo "UNMOUNTING"

? ? sudo umount ${2}/proc

? ? sudo umount ${2}/sys

? ? 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 trailing '/')"

? ? echo ""

? ? echo "For example: ch-mount -m /media/sdcard/"

? ? echo ""

? ? echo 1st parameter : ${1}

? ? echo 2nd parameter : ${2}

????fi

7.對根文件系統(tǒng)進行配置

? ?(1) 更新源

? ??????$apt update

????????ps:如果更新速度慢,可以修改/etc/apt/source.list文件的內(nèi)容,修改成國內(nèi)的更新源

? ??(2) 更新系統(tǒng)

????????$apt upgrade

? ? (3)安裝常用的工具

????????$apt install bash-completion // shell自動補全

????????$apt install net-tools ??????//沒有這個,ifconfig命令沒有

????????$apt install inetutils-ping ?//沒有這個,ping命令沒有

????????$apt install vim //vim編輯器

????(其它工具及軟件,請自行安裝)

? ? (4)安裝xubuntu桌面環(huán)境(耗時較長,耐心等待)

? ??????$apt install ubuntu-session xubuntu-desktop

? ? (5)設(shè)置桌面環(huán)境啟動選項

????????$update-alternatives --config x-session-manager ?// xubuntu選擇startxfce4

? ? (6)設(shè)置默認登錄方式

????????$dpkg-reconfigure lightdm

? ? (7)設(shè)置系統(tǒng)默認語言及編碼方式

????????$apt install locales?//系統(tǒng)語言及編碼格式

????????$dpkg-reconfigure locales ?//根據(jù)提示,空格鍵選擇"en_US.UTF-8 UTF-8" "zh_CN GB2312" "zh_CN.GB18030 GB18030" "zh_CN.GBK GBK" "zh_CN.UTF-8 UTF-8";

? ? (8)設(shè)置主機名

????????$echo "localhost" > /etc/hostname

????????$echo "127.0.0.1 localhost" > /etc/hosts

? ? (9)添加用戶并設(shè)置密碼

????????$useradd -s '/bin/bash' -m -G adm,sudo admin

????????$passwd admin

????????$passwd root

? ? (10)卸載一些沒用的軟件

????????$apt remove thunderbird ??????//郵箱客戶端

????????$apt remove gnome-mines ?????//游戲

????????$apt remove gnome-sudoku ????//游戲

????????$apt remove pidgin ??????????//聊天客戶端

????????$apt remove transmission-* ???//下載工具

????????$apt remove gnome-software ??//軟件中心

????????$apt autoremove

????(11)安裝qt5支持

????????$apt install qt5-default

????(12)?[endif]重新配置時區(qū)

????????$dpkg-reconfigure tzdata ?//選擇亞洲、上海

????(13)禁止apport報錯

????????$vim etc/default/apport

????????設(shè)置enabled=0

????(14) 設(shè)置開機啟動腳本

? ???? $systemctl enable firstboot.service

????(15)設(shè)置藍牙

? ? ? ? $apt remove bluetooth* bluez* blueman*

? ? ? ? $apt autoremove

? ? ? ? $apt install?bluetooth* bluez* blueman*

? ? ? ? $vim /usr/bin/bt-attach

? ??????#!/usr/bin/env bash

????????start-stop-daemon --start --oknodo --pidfile /var/run/hciattach.pid --background --startas /usr/bin/hciattach -- -s 115200 -n /dev/ttyS0 ????????bcm43xx 1500000 -t 200

????????exit 0

? ? ? ? $vim /etc/systemd/system/bt-attach.service

? ??????[Unit]

????????Description=bluetooth-toggle

????????[Service]

????????Type=forking

????????ExecStart=/usr/bin/bt-attach

? ? ? ? $vim /lib/udev/rules.d/50-bluetooth.rules

? ??????SUBSYSTEM=="rfkill", ACTION=="change", ATTR{name}=="bt_default", ATTR{type}=="bluetooth", ATTRS{state}=="1", ????????RUN+="/bin/systemctl start bt-attach.service"

????????SUBSYSTEM=="rfkill", ACTION=="change", ATTR{name}=="bt_default", ATTR{type}=="bluetooth", ATTRS{state}=="0", ????????RUN+="/bin/systemctl stop bt-attach.service"

????(16)? ?清理工作

? ??????$apt clean

????????$rm -rf /var/lib/apt/lists/* ???//這里是更新源保存的臨時文件,可刪除

????(17)退出根文件系統(tǒng)

? ??????$exit

8.卸載根文件系統(tǒng)

? ??$./mount.sh -u ubuntu-rootfs

????(如果無法正常退出,請重啟電腦。)

9.打包鏡像

? ??$./mkimage.sh?ubuntu-rootfs system.img

? ? mkimage.sh的內(nèi)容:

? ??#!/bin/bash

????rootfs_dir=$1

????rootfs_file=$2

????rootfs_mnt="mnt"

????if [ ! $rootfs_dir ] || [ ! $rootfs_file ];

????then

? ? ? ? echo "Folder or target is empty."

? ? ? ? exit 0

????fi

????if [ -f "$rootfs_file" ]; then

? ? ????echo "-- Delete exist $rootfs_file ..."

? ? ????rm -f "$rootfs_file"

????fi

????echo "-- Create $rootfs_file ..."

????dd if=/dev/zero of="$rootfs_file" bs=1M count=4096

????sudo mkfs.ext4 -F -L linuxroot "$rootfs_file"

????if [ ! -d "$rootfs_mnt" ]; then

? ? ? ? mkdir $rootfs_mnt

????fi

????echo "-- Copy data to $rootfs_file ..."

????sudo mount $rootfs_file $rootfs_mnt

????sudo cp -rfp $rootfs_dir/* $rootfs_mnt

????sudo sync

????sudo umount $rootfs_mnt

????rm -r $rootfs_mnt

????echo "-- Resize $rootfs_file ..."

????/sbin/e2fsck -p -f "$rootfs_file"

????/sbin/resize2fs -M "$rootfs_file"

????echo "-- Done."

? ??????

? ??????


? ??

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、文件/文件夾管理 ls 列出當前目錄文件(不包括隱含文件) ls -a 列出當前目錄文件(包括隱含文件) ls...
    小杰的簡書閱讀 2,690評論 0 45
  • 第一章 1.Linux是一套免費使用和自由傳播的類UNIX操作系統(tǒng),它可以基于Intel x86系列處理器以及Cy...
    yansicing閱讀 5,566評論 0 9
  • 一、文件/文件夾管理 ls 列出當前目錄文件(不包括隱含文件)ls -a 列出當前目錄文件(包括隱含文件)l...
    路癡千行閱讀 2,618評論 0 5
  • 一、Python簡介和環(huán)境搭建以及pip的安裝 4課時實驗課主要內(nèi)容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 6,313評論 0 10
  • Ubuntu 常用命令大全 查看軟件 xxx 安裝內(nèi)容 #dpkg -L xxx 查找軟件 #apt-cache ...
    guiwuzhe閱讀 2,711評論 0 14

友情鏈接更多精彩內(nèi)容