ubuntu16.04最小根文件系統製作及集成安裝ros-kinetic-ros-base及遇到的各種坑

創建 Ubuntu 根文件系統

準備工作

安裝qemu

在Linux PC主機上安裝模擬器:

sudo apt-get install qemu-user-static

下載和解壓 ubuntu-core

Firefly-rk3399 ubuntu根文件系統是基於Ubuntu base 16.04來創建的。用戶可以到ubuntu cdimg 下載,選擇下載ubuntu-base-16.04.1-base-arm64.tar.gz 。

下載完之後,創建臨時文件夾並解壓根文件系統:

mkdir ubuntu
sudo tar -xpf ubuntu-base-16.04.1-base-arm64.tar.gz -C temp

修改根文件系統

準備工作

準備網絡:

sudo cp -b /etc/resolv.conf ubuntu/etc/resolv.conf

準備qemu

sudo cp /usr/bin/qemu-aarch64-static ubuntu/usr/bin/

進入根文件系統進行操作:

sudo chroot ubuntu

更新及安裝

更新:

apt update 
apt upgrade

安裝自己需要的功能

apt install vim git ....(根據自己需求添加)

可能出現錯誤:

E: Unable to locate package xxxx

安裝包的源沒有添加到/etc/apt/source.list中,導致無法識別安裝包,可以自行添加源,也可以使用下面給出的source.list覆蓋原來的/etc/apt/source.list文件:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ xenial universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial universe
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted

deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse

添加用戶及設置密碼

添加用戶

useradd -s '/bin/bash' -m -G adm,sudo firefly

給用戶設置密碼:

passwd firefly

給root用戶設置密碼:

passwd root

修改完自己的根文件系統就可以退出了。

exit

安裝ros-kinetic-ros-base(sources.list建議寫入上面的官方源,不然容易出問題)

進入根文件系統

sudo chroot ubuntu

設置etc/apt/sources.list.d/ros-latest.list

sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

但會失敗,不如直接寫

deb http://packages.ros.org/ros/ubuntu xenial main

設置key

apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

更新package

apt-get update

安裝ros-kinetic-ros-base

apt-get install ros-kinetic-ros-base

可能會出現如下錯誤

root@mynt-xmi:/# apt-get install ros-kinetic-ros-base
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-kinetic-ros-base : Depends: ros-kinetic-actionlib but it is not going to be installed
                        Depends: ros-kinetic-bond-core but it is not going to be installed
                        Depends: ros-kinetic-class-loader but it is not going to be installed
                        Depends: ros-kinetic-dynamic-reconfigure but it is not going to be installed
                        Depends: ros-kinetic-nodelet-core but it is not going to be installed
                        Depends: ros-kinetic-pluginlib but it is not going to be installed
                        Depends: ros-kinetic-ros-core but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

這種是屬於sources.list源問題,無法找到部分依賴,不建議使用國內源,雖然安裝軟件快,但是可能有殘缺或者無法連接的源存在,用上述官方源。出現問題建議重新配置源和修復,必須保證apt-get update不出現無法定位或者鏈接錯誤的error。檢查網絡問題等。

apt-get clean
apt-get update
apt-get upgrade
apt-get install -f

再次安裝ros-kinetic-ros-base

安裝完畢後初始化rosdep

注意:在使用ROS之前需要初始化rosdep

rosdep init

這個時候可能就會出錯

錯誤1:

64位系統下:Some packages could not be installed. 錯誤
在很多64位機器上如果安裝 ros-kinetic-desktop-full 會出現如下錯誤:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
ros-kinetic-desktop-full : Depends: ros-kinetic-desktop but it is not going to be installed
Depends: ros-kinetic-simulators but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

解決這一問題的方法一個是隻安裝核心庫 ros-kinetic-desktop 或者可以嘗試先卸載下面的組件:
apt-get remove gazebo-* sdformat-*

錯誤2:

default sources list file already exists
在運行  rosdep init 時可能出現如下錯誤:
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
通常這是因爲你之前曾經安裝過 ROS 系統的某個版本,只需按照提示刪除已經存在的初始化文件即可:
rm /etc/ros/rosdep/sources.list.d/20-default.list


然後再重新運行 rosdep init 就沒有問題了。

錯誤3:也是我遇到的錯誤

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

修復辦法簡單粗暴直接創建etc/ros/rosdep/sources.list.d/20-default.list這個文件,進入這個文件目錄

wget https://raw.github.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list

繼續初始化rosdep注意:之前都是root用戶所以沒有加sudo,之前的ros安裝命令都是需要root權限的,但rosdep update

必須在普通用戶下執行,目前的系統不支持sudo,需要在root用戶下apt-get install sudo

su mynt
rosdep update

不順利的話又會出錯如果是錯誤碼110就是網絡問題,自己想辦法解決網絡問題

如果錯誤碼是111,訪問被拒絕有可能是域名服務器問題推薦使用

解決方法:

sudo vim /etc/resolv.conf

改成下面兩句:

nameserver 8.8.8.8 #google域名服務器

nameserver 8.8.4.4 #google域名服務器

多試幾次,我的後來就成功了

配置ROS環境

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

安裝依賴項

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

測試ROS是否安裝成功

roscore

報錯

解決方法

  以上問題是由於ROS環境變量ROS_MASTER_URI設置錯誤導致的,重新設置該變量即可。

  打開~/.bashrc文件,添加或修改環境變量ROS_HOSTNAME和ROS_MASTER,即改爲:

export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311

修改並保存~/.bashrc文件後,再重新啓動下該文件source ~/.bashrc,再運行roscore即可正常運行

至此ros已安裝完畢,退出文件系統exit

製作根文件系統

製作自己的根文件系統,大小依據自己的根文件系統而定,注意依據temp文件夾的大小來修改count值

mkdir  rootfs
dd if=/dev/zero of=linuxroot.img bs=1M count=4000
mkfs.ext4 linuxroot.img
sudo mount linuxroot.img rootfs/
sudo cp -rfp temp/*  rootfs/
sudo umount rootfs/
e2fsck -p -f linuxroot.img
resize2fs  -M linuxroot.img

這樣 linuxroot.img 就是最終的根文件系統映像文件了。

FAQs

根文件系統加載後,大小不正常,未佔滿整個分區:

在系統正確加載後執行擴展文件系統命令:

 resize2fs /dev/mmcblk1p6    --> rootfs 分區
查看 parameter文件中,root= 節點設備

 

發佈了23 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章