Archive

Posts Tagged ‘Linux’

安装tftp,ftp,samba,nfs

November 24th, 2009 No comments

tftp,ftp和nfs是在嵌入式linux开发环境中经常要用到的传输工具,samba则是在linux和windows下的文件传输工具。

一. tftp安装

1.安装

sudo apt-get install tftpd tftp openbsd-inetd

2.建立tftp主目录
其中用户名和组是你平时使用的主要用户,请不要用root用户作为你的主要操作用户,因为那样很容易把系统搞乱。

sudo mkdir /tftpboot
sudo chown -R tan:tan /tftpboot

3.配置
修改文件:/etc/inetd.conf, 确认文件中包含有类似下面这一行内容:

#emacs /etc/inetd.conf
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot

4.启动tftp
可以重启动电脑,或者执行:

sudo /etc/init.d/openbsd-inetd reload

5.测试
测试从Tftp服务器传入/传出文件:

tftp localhost

二. ftp安装

1.安装

sudo apt-get install vsftpd

2.配置 修改文件“etc/vsftpd.conf”

#不允许匿名登录
anonymous_enable=NO

#本地用户可用
local_enable=YES

#可写
write_enable=YES

#不需要显示某目录下文件信息
#dirmessage_enable=YES

#登录消息
ftpd_banner=Hello~~

#最大连接用户数
max_clients=10

#限制每个IP的进程
max_per_ip=5

#最大传输速率(bit/s)
local_max_rate=256000

#隐藏帐号
hide_ids=YES

3.启动ftp

sudo /etc/init.d/vsftpd restart

4.安装ftp client
系统自带的ftp client中文乱码。

sudo apt-get install filezilla

三. samba安装

1.安装

sudo apt-get install samba smbfs

2.配置
修改文件“/etc/samba/smb.conf”
配置例子(建立一个共享名称为“share”的samba资源):

[share]
comment = linux share
#共享目录
path = /opt
guest ok = yes

#写权限用户名
write list = tan

printable = no
directory mask 0775
create mask 0775
wide links = no

3.写权限用户口令
如果定义了写特权用户,则该用户必须有samba口令,samba口令与系统用户口令是不同的。

smbpasswd -a 用户名

4.启动

sudo /etc/init.d/samba restart

5.在xp上的共享连接问题处理
在XP上连接samba资源时,出现以下提示的处理:

指定的网络文件夹目前是以其它用户名和密码进行映射的。
要用其他用户名和密码进行连接,首先请断开所有现有连接到该网络共享的映射。

处理:

  1. 断开连接
    找到该共享连接名称

    net use

    删除该连接(共享连接名可以是“\\”“开头的全名,也可以是映射的盘符)

    net use /delete <共享连接名>

    然后重新连接即可。

四. NFS

NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!

一般而言, 使用nfs能够方便地使各unix-like系统之间实现共享. 但如果需要在unix-like和windows系统之间共享, 就得使用samba了!

NFS运行在SUN的RPC(Remote Procedure Call, 远程过程调用)基础上, RPC定义了一种与系统无关的方法来实现进程间通信. 由此, NFS server也可以看作是RPC server.

正因为NFS是一个RPC服务程序, 所以在使用它之前, 先要映射好端口——通过portmap设定. 比如: 某个NFS client发起NFS服务请求时, 它需要先得到一个端口(port). 所以它先通过portmap得到port number. (不仅NFS, 所有的RPC服务程序启动之前, 都需要设定好portmap)

与NFS相关的几个文件, 命令:
1. /etc/exports

对NFS卷的访问是由exports来批准, 它枚举了若干有权访问NFS服务器上文件系统的主机名.

2. /sbin/exportfs

维护NFS的资源共享. 可以通过它重新设定 /etc/exports 的共享目录, 卸载NFS Server共享的目录或者重新共享等.

3. /usr/sbin/showmount

用在 NFS Server 端,而 showmount 则主要用在 Client 端. showmount 可以用來查看 NFS 共享的目录资源.

4. /var/lib/nfs/xtab

NFS的记录文档: 通过它可以查看有哪些Client 连接到NFS主机的记录.

下面这几个并不直接负责NFS, 实际上它们负责所有的RPC
5. /etc/default/portmap

实际上, portmap负责映射所有的RPC服务端口, 它的内容非常非常之简单(后面详述)

6. /etc/hosts.deny

设定拒绝portmap服务的主机

7. /etc/hosts.allow

设定允许portmap服务的主机

安装NFS
Debian/Ubuntu上默认是没有安装NFS服务器的,首先要安装NFS服务程序:

sudo apt-get install nfs-kernel-server

安装nfs-kernel-server时,apt会自动安装nfs-common和portmap,服务端和客户程序都一块安装了。

客户端需要安装客户端程序。如果是Debian/Ubuntu系统,客户端包名称是“nfs-common”:

sudo apt-get install nfs-commmon

nfs-common和nfs-kernel-server都依赖于portmap!

配置NFS
配置portmap

方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.

方法2: 执行

sudo dpkg-reconfigure portmap

对Should portmap be bound to the loopback address? 选N.

配置/etc/hosts.deny
(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:

### NFS DAEMONS
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

配 置/etc/hosts.allow
允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.2开头的主机(连 接到NFS服务器上),也可以指定特定的IP地址。参看man页 hosts_access(5), hosts_options(5)。加入:

### NFS DAEMONS
portmap: 192.168.2.
lockd: 192.168.2.
rquotad: 192.168.2.
mountd: 192.168.2.
statd: 192.168.2.

/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似”mask”的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问. 运行

sudo /etc/init.d/portmap restart

重启portmap daemon.

配置/etc/exports
NFS挂载目录及权限由/etc/exports文件定义

比如我要将将我的home目录中的/home/zp/share目录让192.168.2.*的IP共享, 则在该文件末尾添加下列语句:

/home/zp/share 192.168.2.*(rw,sync,no_root_squash)

或者:

/home/zp/share 192.168.2.0/24(rw,sync,no_root_squash)

192.168.2.* 网段内的NFS客户端能够共享NFS服务器/home/zp/share目录内容.且有读,写权限, 并且该用户进入/home/zp/share目录后的身份为root

最好加上sync, 否则 “sudo exportfs -r” 时会给出警告, sync是NFS的默认选项.

运行

showmount -e

查看NFS server的export list.

若更改了/etc/exports, 运行

sudo exportfs -r

更新

运行

sudo /etc/init.d/nfs-kernel-server restart

重启nfs服务

/etc/exports实际上就是nfs服务器的核心配置文件了.

测试NFS
可以尝试一下挂载本地磁盘(假设NFS服务器IP地址为:192.128.2.1,NFS目录为“/home/zp/share”)

sudo mount 192.168.2.1:/home/zp/share /mnt

运行

df

看看结果.

卸载NFS目录

sudo umount /mnt

注意被拷贝文件的读/写权限!
另外, 可以使用一定的参数:
使用加参数的办法:

mount -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.2.130:/tmp/ /tmp/

--EOF--
Categories: Embedded, Tech.Notes Tags: , , , , ,

[Kernel] Debian-ubuntu-kernel-install

November 18th, 2009 No comments

第一步 安装必要的工具

首先要安装必要的包。
包有:libncurses5-devmenuconfig需要的)和essential

sudo apt-get install build-essential kernel-package
sudo apt-get install make
sudo apt-get install gcc

另外,查看系统是否有这样的两个命令

mkinitramfs mkisofs

这两个工具在编译内核时用来生成 *.img文件的。如果没有就需安装。

第二步 下载内核

www.kernel.org下载新内核到/usr/src

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.5.tar.bz2

我下载的是linux-2.6.30.5.tar.bz2(原来的内核是2.6.24-24-generic)

第三步 编译前的准备

察看当前内核的版本

border@ubuntu:/usr/src$ uname -a
Linux ubuntu 2.6.24-24-generic #1 SMP Tue Jun 30 20:28:53 UTC 2009 i686 GNU/Linux

建议最好下载比当前已安装版本高的内核

解压linux-2.6.30.5.tar.gzlinux-2.6.30.5

cd /usr/src
sudo tar xjvf linux-2.6.30.5.tar.bz2
cd linux-2.6.30.5/


第四步 开始编译

cd /usr/src/linux-2.6.30.5/ //以下所有的工作都在/usr/src/linux-2.6.30.5/下完成

sudo make menuconfig  //menuconfig的话还需要Ncurses,或者用
sudo make xconfig
sudo make menuconfig  //一般是用menuconfig

配置完以后保存(系统中保存的一份内核配置文件是在/usr/src/linux-2.6.30.5下名为.config,你也可以自己在别的地方另存一份)
也可以cp原来在/boot目录下的config-2.6.xx 到当前目录下,在make menuconfig是使用这个配置文件。

sudo make clean //清除旧数据 ,新解压的内核源码就不需要这一步了
sudo make –j4 可以分四个线程来进行编译工作
sudo make bzImage //编译内核,将保存到/usr/src/linux-2.6.30.5/arch/i386/boot/
sudo make modules //编译模块
sudo make modules_install //安装模块,执行完后会显示DEPMOD 2.6.30.5
sudo mkinitramfs -o /boot/initrd.img-2.6.30.5 2.6.30.5      // 2.6.30.5为modules_install 执行完成后显示的DEPMOD 2.6.30.5, 注意: 2.6.30.5 前面有空格
sudo make install //安装内核

如果你想把编译的结果打包为Deb包,可以参考这里 和 这里 .

sudo make-kpkg clean
sudo make-kpkg –revision eee701 kernel_image
sudo dpkg -i linux-image-2.6.30_eee701_i386.deb

安装完后/boot下将增加以下几个文件(用ls -l *30*查看)

border@ubuntu:/boot$ ls -l *30*
-rw-r–r– 1 root root   96237 2009-08-25 17:41 config-2.6.30.5
-rw-r–r– 1 root root 7896051 2009-08-25 17:38 initrd.img-2.6.30.5
-rw-r–r– 1 root root 1095789 2009-08-25 17:41 System.map-2.6.30.5
-rw-r–r– 1 root root 2324720 2009-08-25 17:41 vmlinuz-2.6.30.5

/boot/grub/menu.lst中添加一个新的启动项,如我的menu.lst增加了如下一段文字

title           Ubuntu kernel 2.6.30.5
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.30.5 vga=794 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.30.5
quiet


ps: 上面在kernel一行后面的 “
vga=794 root=/dev/sda1 ro” 是从你之前的启动项取得的。
重新启动即可。

参考:
1.   http://ubuntuforums.org/showthread.php?t=311158
2.   “creating a kernel 2.6.30 deb file” http://www.naumann.cc/?p=107


Bian Jiang
Blog:  http://www.wifihack.net/

Categories: Kernel Tags: , , ,

The Kernel Newbie Corner 系列文章 By: Robert P. J. Day

August 28th, 2009 2 comments

IGMPv3 Multicasting Linux MRouter with XORP How-to on Ubuntu

July 31st, 2009 5 comments

今天在wikipedia看IGMP的时候,无意中发现了XORP, 简单适用了一下非常好用,并且官方的资料真理的比较全,使用也比较方便,还提供了一个基本的shell xorpsh 来配置管理信息。刚好可以省去买支持IGMP的路由器,支持IGMP的路由器最少也要1.5W…

XORP, or Extensible Open Router Platform, is an open source routing software suite, aimed at being both stable and fully featured enough for production use and also extensible to support networking research.

Request:
OS: ubuntu 9.04 (Linux Kernel 2.6.28-11-generic) with GCC 4.3.3
SW: XORP (multicast routing daemon)
HW: PC with 2 or 3 ethernet card (default gw is itself) !

Step 1: Check Linux Kernel Functions!
CONFIG_IP_MULTICAST=y
CONFIG_IP_ADVANCED_ROUTER=y
CONFIG_IP_MROUTE=y
After this configurations, the linux kernel support IGMP, DVMRP and MOSPF. If want support PIM-SM , do below settings
CONFIG_IP_PIMSM_V2=y
PS: you can use vi view /boot/CONFIG-(kernel version) to confirm !

Step 2: edit /etc/sysctl.conf to enable ip_forward
net.ipv4.conf.default.forwarding=1
PS: reboot or use command “sysctl -p” to enable !

Step 3: Install XORP(To compile XORP requires nearly 1.4GB of free disk space)
Step 3.1: Download xorp-1.6.tar.gz
Step 3.2: untar the xorp-1.6.tar.gz
Step 3.3: ./configure
Step 3.4: make
Step 3.4-1: make check (just to check)(it is not necessary)

Step 4: run  rtrmgr/xorp_rtrmgr  rtrmgr/xorpsh (A sample xorp command shell)
Step 4.1: create user group named “xorp”

sudo addgroup xorp

Step 4.2: cp or edit config.boot in xorp-1.6/rtrmgr/config.boot
config.boot for our environment

protocols {
fib2mrib {
disable: false
}
igmp {
disable: false
interface eth0 {
vif eth0 {
disable: false
version: 3
enable-ip-router-alert-option-check: false
query-interval: 125
query-last-member-interval: 1
query-response-interval: 10
robust-count: 2
}
}
}
}
fea {
unicast-forwarding4 {
disable: false
}
}
interfaces {
restore-original-config-on-shutdown: false
interface eth0 {
disable: false
discard: false
description: “”
default-system-config {
}
}
}

Step 4.3: xorp-1.6/rtrmgr/xorp_rtrmgr -b xorp-1.6/rtrmgr/config.boot

Step 5: Check Mrouter work OK
Step 5.1: Connect eth0 to VLC Player server PC and connect eth1 to VLC Player client PC
Step 5.2: Use VLC Player server PC run multicast streaming
Step 5.3: Use VLC Player client PC to play multicast streaming by multicast URL

Step6: run rtrmgr/xorpsh (A sample xorp command shell)

xorp-1.6$ rtrmgr/xorpsh
Welcome to XORP on wifihack

border@wifihack> show igmp ?
Possible completions:
group                Display information about IGMP group membership
interface            Display information about IGMP interfaces

border@wifihack> show igmp group
Interface    Group           Source          LastReported Timeout V State
eth0         224.0.0.2       0.0.0.0         192.168.1.134     240 3     E
eth0         224.0.0.22      0.0.0.0         192.168.1.134     240 3     E
eth0         224.0.0.251     0.0.0.0         192.168.1.134     232 3     E
eth0         224.0.0.252     0.0.0.0         192.168.1.30     232 3     E
eth0         239.255.255.250 0.0.0.0         192.168.1.104     240 3     E

参考:
1. http://www.linuxdiyf.com/bbs/redirect.php?fid=55&tid=69157&goto=nextnewset
2. http://www.xorp.org/getting_started.html
3. “User Manual” http://www.xorp.org/releases/current/docs/user_manual/user_manual.pdf
4. http://en.wikipedia.org/wiki/XORP
5. http://en.wikipedia.org/wiki/IGMP

Categories: Kernel, OpenSource, Tech.Notes Tags: , , ,

linux-2.6.30 with gcc-3.4.6 compile error

July 20th, 2009 No comments

想通过codeviz看linux kernel的调用关系, 但是codeviz用的是gcc-3.4.6,

但在用gcc-3.4.6编译linux-2.6.30的时候报错:

 drivers/net/igb/igb_main.c: In function `igb_up':
 drivers/net/igb/igb_main.c:130: sorry, unimplemented: inlining failed
 in call to 'igb_set_rah_pool': function body not available
 drivers/net/igb/igb_main.c:938: sorry, unimplemented: called from here
 drivers/net/igb/igb_main.c:133: sorry, unimplemented: inlining failed
 in call to 'igb_set_vmolr': function body not available
 drivers/net/igb/igb_main.c:939: sorry, unimplemented: called from here
 make[3]: *** [drivers/net/igb/igb_main.o] Error 1
 make[2]: *** [drivers/net/igb] Error 2
 make[1]: *** [drivers/net] Error 2
 make: *** [drivers] Error 2
 
 This is CentOS 4.x system.  While using same configuration to compile
 in CentOS 5.x systems with gcc-4.1.2 do not encounter such error and
 my guess is gcc version issue?  Any idea?

Linux-2.6.30 Linux-2.6.30.1使用gcc-3.4.6编译错误补丁:

diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index be48029..adb09d3 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -127,14 +127,48 @@  static void igb_restore_vlan(struct igb_adapter *);
 static void igb_ping_all_vfs(struct igb_adapter *);
 static void igb_msg_task(struct igb_adapter *);
 static int igb_rcv_msg_from_vf(struct igb_adapter *, u32);
-static inline void igb_set_rah_pool(struct e1000_hw *, int , int);
 static void igb_set_mc_list_pools(struct igb_adapter *, int, u16);
 static void igb_vmm_control(struct igb_adapter *);
-static inline void igb_set_vmolr(struct e1000_hw *, int);
-static inline int igb_set_vf_rlpml(struct igb_adapter *, int, int);
 static int igb_set_vf_mac(struct igb_adapter *adapter, int, unsigned char *);
 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);

+static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn)
+{
+	u32 reg_data;
+
+	reg_data = rd32(E1000_VMOLR(vfn));
+	reg_data |= E1000_VMOLR_BAM |	 /* Accept broadcast */
+	            E1000_VMOLR_ROPE |   /* Accept packets matched in UTA */
+	            E1000_VMOLR_ROMPE |  /* Accept packets matched in MTA */
+	            E1000_VMOLR_AUPE |   /* Accept untagged packets */
+	            E1000_VMOLR_STRVLAN; /* Strip vlan tags */
+	wr32(E1000_VMOLR(vfn), reg_data);
+}
+
+static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
+                                 int vfn)
+{
+	struct e1000_hw *hw = &adapter->hw;
+	u32 vmolr;
+
+	vmolr = rd32(E1000_VMOLR(vfn));
+	vmolr &= ~E1000_VMOLR_RLPML_MASK;
+	vmolr |= size | E1000_VMOLR_LPE;
+	wr32(E1000_VMOLR(vfn), vmolr);
+
+	return 0;
+}
+
+static inline void igb_set_rah_pool(struct e1000_hw *hw, int pool, int entry)
+{
+	u32 reg_data;
+
+	reg_data = rd32(E1000_RAH(entry));
+	reg_data &= ~E1000_RAH_POOL_MASK;
+	reg_data |= E1000_RAH_POOL_1 << pool;;
+	wr32(E1000_RAH(entry), reg_data);
+}
+
 #ifdef CONFIG_PM
 static int igb_suspend(struct pci_dev *, pm_message_t);
 static int igb_resume(struct pci_dev *);
@@ -5418,43 +5452,6 @@  static void igb_io_resume(struct pci_dev *pdev)
 	igb_get_hw_control(adapter);
 }

-static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn)
-{
-	u32 reg_data;
-
-	reg_data = rd32(E1000_VMOLR(vfn));
-	reg_data |= E1000_VMOLR_BAM |	 /* Accept broadcast */
-	            E1000_VMOLR_ROPE |   /* Accept packets matched in UTA */
-	            E1000_VMOLR_ROMPE |  /* Accept packets matched in MTA */
-	            E1000_VMOLR_AUPE |   /* Accept untagged packets */
-	            E1000_VMOLR_STRVLAN; /* Strip vlan tags */
-	wr32(E1000_VMOLR(vfn), reg_data);
-}
-
-static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
-                                 int vfn)
-{
-	struct e1000_hw *hw = &adapter->hw;
-	u32 vmolr;
-
-	vmolr = rd32(E1000_VMOLR(vfn));
-	vmolr &= ~E1000_VMOLR_RLPML_MASK;
-	vmolr |= size | E1000_VMOLR_LPE;
-	wr32(E1000_VMOLR(vfn), vmolr);
-
-	return 0;
-}
-
-static inline void igb_set_rah_pool(struct e1000_hw *hw, int pool, int entry)
-{
-	u32 reg_data;
-
-	reg_data = rd32(E1000_RAH(entry));
-	reg_data &= ~E1000_RAH_POOL_MASK;
-	reg_data |= E1000_RAH_POOL_1 << pool;;
-	wr32(E1000_RAH(entry), reg_data);
-}
-
 static void igb_set_mc_list_pools(struct igb_adapter *adapter,
 				  int entry_count, u16 total_rar_filters)
 {

参考:
1. linux-2.6.30.1 with gcc-3.4.6 compile error http://patchwork.kernel.org/patch/35402/
2. codeviz http://www.csn.ul.ie/~mel/projects/codeviz/
Categories: Kernel Tags: , , ,