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

Ubuntu10.04+mini2440下ARM-linux开发环境搭建(2)----NFS服务器的配置及通过NFS启动linux

2013-05-24 10:33 1116 查看
六、NFS服务器的配置

1、安装NFS客户端和服务器

Ubuntu上默认是没有安装Ubuntu nfs服务器的,因此我们首先安装Ubuntu nfs服务器端:

$sudo apt-get install nfs-kernel-server

在安装nfs-kernel-server时,apt会自动为我们安装好nfs的客户端nfs-common,以及端口映射器portmap。

2、配置/etc/exports

在根目录下新建nfs文件夹,并更改其权限777

打开文件加入下面内容

clx@think:~$ sudo gedit /etc/exports

#作为开发板的根文件系统通过nfs 挂接

/nfsboot/rootfs 192.168.1.* (rw,sync,no_root_squash) //*和(之间没有空格,否则跟文件系统将是只读的,会有很多麻烦

/nfsboot/kernel 192.168.1.* (rw,sync,no_root_squash)

#存放引用程序

/nfsboot/nfs 192.168.1.* (rw,sync,no_root_squash)

第一个 /nfsboot/rootfs 是你要共享的目录

第二个部分192.168.1..*是指在这个IP段内可以共享的目录

第三个部分: 第一个参数,rw:可以擦写的权限; ro:只读的权限

第二个参数:sync:资料同步写入到内存与硬盘当中,async:资料会暂时写入到内存中去

第三个参数:no_root_aquash: 登入NFS主机使用分享目录的使用者,如果是root的话,那么对于这个分享的目录来说,它就具有root的权限,这个项目很不安全。

很重要的一点,不要在最后一个客户端声明的后面留下任何空白或者没关闭括号,因为空白都被解释成客户端的分隔符。

3、启动nfs服务

(1)、首先把上面修改过的配置文件重新导入

clx@think:/etc$ sudo exportfs -rv

(2)、重新启动portmap服务(端口映射)

#sudo /etc/init.d/portmap restart

(3)、重新启动nfs服务:

clx@think:/$ sudo /etc/init.d/nfs-kernel-server restart

* Stopping NFS kernel daemon [ OK ]

* Unexporting directories for NFS kernel daemon... [ OK ]

* Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.*:/nfs".

Assuming default behaviour ('no_subtree_check').

NOTE: this default has changed since nfs-utils version 1.0.x

[ OK ]

* Starting NFS kernel daemon [ OK ]

4、NFS测试

(1)、手动挂载

使用mount命令来挂载其他机器共享的NFS目录。

格式:$ sudo mount [Server IP]:/[share dir] [local mount point]

clx@think:~$ sudo mount -t nfs 192.168.1.100:/nfs /home/clx/rootnfs

没有任何提示说明成功。

(2)、和开发板挂载测试

root@MINI2440:/# mount -o nolock -t nfs 192.168.1.100:/nfs /mnt

root@MINI2440:/mnt# ls

backlight_test

挂载成功。

七、通过NFS启动linux

1、配置虚拟机IP

虚拟机必须设置静态IP,并且虚拟机需设置为桥接方式,虚拟机与宿主机与目标机为同个网段。

这里设置虚拟机IP:192.168.1.100,开发板IP已自动设置为:192.168.1.250

2、配置mini2440开发板

在Supervivi模式下输入如下命令(参考mini2440光盘根目录下的nfs.txt文件)

Supervivi> param set linux_cmd_line "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"

其中 ,param set linux_cmd_line 是设置启动 linux 时的命令参数。其各参数的含义

console: console=tty 使用虚拟串口终端设备 。console=ttyS[,options] 使用特定的串口,options可以是这样的形式bbbb p n x,这里bbbb是指串口的波特率,p是奇偶位(从来没有看过使用过),n是指的bits。console=ttySAC[,options] 同上面。看你当前的环境,有时用ttyS,有时用ttySAC,网上有人说,这是跟内核的版本有关,2.4用ttyS,2.6用ttySAC,但实际情况是官方文档中也是使用ttyS,所以应该是跟内核版本没有关联的。可以查看Documentation/serial-console.txt找到相关描述。

root: 用来指定rootfs的位置, 常见的情况有:

root=/dev/ram rw

root=/dev/ram0 rw

请注意上面的这两种设置情况是通用的,我做过测试甚至root=/dev/ram1 rw和root=/dev/ram2 rw也是可以的,网上有人说在某些情况下是不通用的,即必须设置成ram或者ram0,但是目前还没有遇到,还需要进一步确认,遇到不行的时候可以逐一尝试。

root=/dev/mtdx rw

root=/dev/mtdblockx rw

root=/dev/mtdblock/x rw

root=31:0x

上面的这几个在一定情况下是通用的,当然这要看你当前的系统是否支持,不过mtd是字符设备,而mtdblock是块设备,有时候你得挨个的试到底当前的系统支持上面那种情况下,不过root=/dev/mtdblockx rw比较通用。此外,如果直接指定设备名可以的话,那么使用此设备的设备号也是可以的。

root=/dev/nfs,并非真的设备,而是一个告诉内核经由网络取得根文件系统的旗标。

在文件系统为基于nfs的文件系统的时候使用。当然指定root=/dev/nfs之后,还需要指定nfsroot。

nfsroot:参数告诉内核以哪一台机器,哪个目录以及哪个网络文件系统选项作为根文件系统使用。

nfsroot 是自己开发主机的IP 地址。

“ip=”后面:

第一项(192.168.1.230)是目标板的临时IP(注意不要和局域网内其他IP 冲突);

第二项(192.168.1.112)是开发主机的IP;

第三项(192.168.1.1)是目标板上网关(GW)的设置;

第四项(255.255.255.0)是子网掩码;

第五项是开发主机的名字(一般无关紧要,可随便填写)

eth0 是网卡设备的名称。

内核配置确保选中了[*] Root file system on NFS

从NandFlash启动开发板,上电时同时按下开发板上任意一个按键,进入BIOS,在超级终端输入 q [q] Goto shell of vivi,进入命令行

把之前写好的命令粘贴进去,回车。

输入boot,回车就从NFS启动系统了。

要想每次启动都通过NFS启动系统,在输入boot前,输入menu,然后输入s,再输入w,输入q,回到BIOS菜单。这样以后每次就自动从NFS启动了

Supervivi> param set linux_cmd_line "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"

Change linux command line to "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"

Supervivi> menu

##### FriendlyARM BIOS 2.0 for 2440 #####

[x] format NAND FLASH for Linux

[v] Download vivi

[k] Download linux kernel

[y] Download root_yaffs image

[a] Absolute User Application

Download Nboot for WinCE

[l] Download WinCE boot-logo

[w] Download WinCE NK.bin

[d] Download & Run

[z] Download zImage into RAM

[g] Boot linux from RAM

[f] Format the nand flash

[b] Boot the system

[s] Set the boot parameters

[u] Backup NAND Flash to HOST through USB(upload)

[r] Restore NAND Flash from HOST through USB

[q] Goto shell of vivi

[i] Version: 1026-2K

Enter your selection: s

##### Parameter Menu #####

[r] Reset parameter table to default table

[s] Set parameter

[v] View the parameter table

[w] Write the parameter table to flash memeory

[q] Quit

Enter your selection: w

Found block size = 0x00020000

Erasing... ... done

Writing... ... done

Written 49152 bytes

Saved vivi private data

##### Parameter Menu #####

[r] Reset parameter table to default table

[s] Set parameter

[v] View the parameter table

[w] Write the parameter table to flash memeory

[q] Quit

Enter your selection: q

##### FriendlyARM BIOS 2.0 for 2440 #####

[x] format NAND FLASH for Linux

[v] Download vivi

[k] Download linux kernel

[y] Download root_yaffs image

[a] Absolute User Application

Download Nboot for WinCE

[l] Download WinCE boot-logo

[w] Download WinCE NK.bin

[d] Download & Run

[z] Download zImage into RAM

[g] Boot linux from RAM

[f] Format the nand flash

[b] Boot the system

[s] Set the boot parameters

[u] Backup NAND Flash to HOST through USB(upload)

[r] Restore NAND Flash from HOST through USB

[q] Goto shell of vivi

[i] Version: 1026-2K

Enter your selection: b

........................................................................

eth0: link down

IP-Config: Complete:

device=eth0, addr=192.168.1.250, mask=255.255.255.0, gw=192.168.1.1,

host=MINI2440, domain=, nis-domain=DreamCatcher,

bootserver=192.168.1.100, rootserver=192.168.1.100, rootpath=

Looking up port of RPC 100003/2 on 192.168.1.100

eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1

Looking up port of RPC 100005/1 on 192.168.1.100

VFS: Mounted root (nfs filesystem) on device 0:14.

Freeing init memory: 132K

Processing /etc/rc.local

get hostname

Starting mdev

ifconfig eth0 192.168.1.250

DeramCatcher

Date:2013.5.14

update the time from RTC

Mon Jan 9 12:42:10 UTC 2012

Please press Enter to activate this console.

Processing /etc/profile

set user path

set search library path

set PS1

root@MINI2440:/# ls

bin dev home linuxrc proc sbin tmp var

boot etc lib mnt root sys usr

至此用NFS挂载根文件系统启动成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐