您的位置:首页 > 运维架构 > Linux

BeagleBoneBlack上通过nfs/ramdisk加载linux

2014-10-02 16:19 603 查看
http://blog.csdn.net/goodwillyang/article/details/39736979

开发环境:ubuntu14.04 + BBB(电脑和BBB用网线直连)。主要的参考http://wiki.beyondlogic.or/index.php?title=BeagleBoneBlack_Building_Kernel,里面非常详细,照着做一遍就全能搞定,不得不佩服这个高人!

一.搭建Host需要的开发环境(tftp,nfs,ssh)

1.安装tftp-server

sudo apt-get install tftpd-hpa
sudo apt-get install tftp-hpa(如果不需要客户端可以不安装)


配置TFTP服务器

sudo vim /etc/default/tftpd-hpa


将原来的内容改为:我的配置:

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/yyang2/tftpboot"  #tftpboot就是我创建的TFTP server的根目录,设置权限为777,chomd 777
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"


重新启动TFTP服务

sudo service tftpd-hpa restart


2.安装nfs-server

sudo apt-get update
sudo apt-get install nfs-kernel-server

创建nfs目录

sudo mkdir /var/nfs
sudo chown nobody:nogroup /var/nfs

配置nfs服务器

nfs允许挂载的目录及权限在文件/etc/exports中进行定义

sudo vim /etc/exports
格式:共享目录路径
client(share_option1,...,share_optionN)

我的配置

/var/nfs  *(rw,no_root_squash,sync,no_subtree_check)
其中: /var/nfs 是要共享的目录,

*代表允许所有的网络段访问,

rw是可读写权限,sync是资料同步写入内存和硬盘,

no_root_squash是nfs客户端分享目录使用者的权限,如果客户端使用的是root用户,那么对于该共享目录而言,该客户端就具有root权限。

其它nfs常用的参数有:

ro 只读访问

rw 读写访问sync 所有数据在请求时写入共享

async nfs在写入数据前可以响应请求

secure nfs通过1024以下的安全TCP/IP端口发送

insecure nfs通过1024以上的端口发送

wdelay 如果多个用户要写入nfs目录,则归组写入(默认)

no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置。

hide 在nfs共享目录中不共享其子目录

no_hide 共享nfs目录的子目录

subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)

no_subtree_check 和上面相对,不检查父目录权限

all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。

no_all_squash 保留共享文件的UID和GID(默认)

root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)

no_root_squas root用户具有根目录的完全管理访问权限

anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID

anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID

打开所有共享目录(exportfs)

sudo exportfs -a
#export可以查看nfs路径


重启nfs服务

sudo service nfs-kernel-server start


测试nfs服务

showmount -e


参考的文章 NFS server

ubuntu14_NFS_server

3. 安装SSH,gftp,telnet(可选)

二.Image生成

按照上面的文档做下来的话,uImage,dtb都有了,rootfs在nfs章节。

mkdir rootfs
wget http://downloads.angstrom-distribution.org/demo/beaglebone/Angstrom-systemd-image-eglibc-ipk-v2012.12-beaglebone-2013.09.12.rootfs.tar.xz tar -xJf Angstrom-systemd-image-eglibc-ipk-v2012.12-beaglebone-2013.09.12.rootfs.tar.xz -C rootfs
把rootfs拷贝到nfs共享目录下:

cp -r rootfs/* /var/nfs

三.启动linux via NFS

这里主要就是uboot的参数配置(参数bootargs,bootcmd)

暴力法:uboot上输入:

setenv serverip 128.224.158.241;setenv ipaddr 128.224.158.3;
tftp 80200000 uImage;tftp 815f0000 am335x-boneblack.dtb; #image放在主机tftpserver跟目录下
setenv bootargs console=ttyO0,115200n8 rw ip=128.224.158.3:::::eth0:off root=/dev/nfs nfsroot=128.224.158.241:/var/nfs
bootm 80200000 - 815f0000;


其中:nfsaddrs=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

四.启动linux via RAMDISK
ramdisk(RAMDISK)是rootfs的一种形式,将内存划分出固定大小影射成一个可读写的rootfs,由于ramdisk是把内存影射成一个块设备,所以ramdisk为一个块文件。制作方法如下:

mkdir ramdisk_temp
dd if=/dev/zero of=ramdisk bs=1M count=64 (64M的ramdisk)
mke2fs –F –v –m0 ramdisk
mount –o loop ramdisk ramdisk_temp
cp –av rootfs/* ramdisk_temp
umount ramdisk_temp
gzip ramdisk


其中:

-F : 迫使mke2fs在ramdisk上运行, 否则, mke2fs会抱怨ramdisk不是块设备.

-v : 以verbose模式运行

-m0 : 指定不必在文件系统上为"超级用户"保留任何block.(一般嵌入式Linux都是单用户系统).

注意,这个ramdisk.gz不能直接在uboot中运行,需要通过mkimage把它转出uboot可以识别的格式(mkimage)



# mkimage -l uImage
Image Name:   Linux-3.12.9-00110-g17a994a-dirt
Created:      Sun Oct  5 11:27:45 2014
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    4540600 Bytes = 4434.18 kB = 4.33 MB
Load Address: 80008000
Entry Point:  80008000


配置mkimage

The bootloader used on the BeagleBone black is
U-Boot. U-Boot has a special image format called uImage. It includes parameters such as descriptions, the machine/architecture type,compression type, load address, checksums etc. To make these images, you need to have a mkimage tool that comes part of the
U-Boot distribution. Download U-Boot, make and install the U-Boot tools:

wget ftp://ftp.denx.de/pub/u-boot/u-boot-latest.tar.bz2 tar -xjf u-boot-latest.tar.bz2
or
git clone  git://git.denx.de/u-boot.git

cd into u-boot directory
make tools-only
sudo install tools/mkimage /usr/local/bin

或者简单一点:

$ sudo apt-get install u-boot-tools


mkimage -A arm -T ramdisk -C gzip -n "Ramdisk" -d ramdisk.image.gz uramdisk.image.gz

uboot上输入:


setenv serverip 128.224.158.241;setenv ipaddr 128.224.158.3;
tftp 80200000 uImage;tftp 815f0000 am335x-boneblack.dtb;tftp 82000000 uRamdisk.gz;
setenv bootargs console=ttyO0,115200n8 rw root=/dev/ram ramdisk_size=65536;
bootm 80200000 82000000 815f0000;
注意:Linux内核配置中默认ramdisk大小为16M?,如果您的创建的ramdisk大于16M需要修改内核的配置,一种简单的方法:用u-boot的bootargs传递启动参数ramdisk_size(1024 per/block?)
五.其它
几种linux内核文件的区别:
1、vmlinux  编译出来的最原始的内核elf文件,未压缩。
2、zImage   是vmlinux经过objcopy gzip压缩后的文件, objcopy实现由vmlinux的elf文件拷贝成纯二进制数据文件。
3、bzImage bz表示“big zImage”,不是用bzip2压缩的。两者的不同之处在于,zImage解压缩内核到低端内存(第一个640K),bzImage解压缩内核到高端内存(1M以上)。如果内核比较小,那么采用zImage或bzImage都行,如果比较大应该用bzImage。
4、uImage   U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的tag。
5、vmlinuz  是bzImage/zImage文件的拷贝或指向bzImage/zImage的链接。
6、initrd   是“initial ramdisk”的简写。一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。
一般情况下都在生成 vmlinux 后,再对内核进行压缩成为 zImage,压缩的目录是  kernel/arch/arm/boot。

zImage由vmlinux objcopy出来的纯二进制文件以及解压缩程序组成,zImage自带了解压缩程序,大体结构如下:


uImage解压os到entry point,然后启动完全可以被bootz 命令来代替,直接把zImage load到启动地址即可,省去mkimage和decomporess的过程 参考链接
tftp 80008000 zImage
tftp 815f0000 am335x-boneblack.dtb
bootz 80008000 - 815f0000
[/code] http://blog.csdn.net/goodwillyang/article/details/39736979 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  beaglebone nfs ubuntu uboot
相关文章推荐