6、debian搭建nfs服务器

1、安装nfs服务器:

sudo apt-get install nfs-kernel-server

2、编辑/etc/exports文件,在该文件中增加NFS目录信息:

/xx/xxx/ *(rw,sync,no_root_squash)
说明:

/xx/xxx/是NFS的根目录

*可以是ip地址,表示允许挂载的客户机IP


3、需要注意的一个地方,debian9发布后马上升级了debian9系统,升级后发现以前在debian8中运行得好好的NFS突然不能挂载了,开发板启动到挂载根文件系统的时候由于挂载不上文件系统而panic了,此时ping开发板是可以ping通的,但是就是挂载不了。不知什么原因,信息如下:

random: fast init done
dm9000 dm9000 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
IP-Config: Guessing netmask 255.0.0.0
IP-Config: Complete:
     device=eth0, hwaddr=08:00:3e:26:0a:5b, ipaddr=10.0.0.3, mask=255.0.0.0, gw=255.255.255.255
     host=10.0.0.3, domain=, nis-domain=(none)
     bootserver=255.255.255.255, rootserver=10.0.0.2, rootpath=
ALSA device list:
  No soundcards found.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
0100           65536 ram0 
 (driver?)
0101           65536 ram1 
 (driver?)
0102           65536 ram2 
 (driver?)
0103           65536 ram3 
 (driver?)
0104           65536 ram4 
 (driver?)
0105           65536 ram5 
 (driver?)
0106           65536 ram6 
 (driver?)
0107           65536 ram7 
 (driver?)
0108           65536 ram8 
 (driver?)
0109           65536 ram9 
 (driver?)
010a           65536 ram10 
 (driver?)
010b           65536 ram11 
 (driver?)
010c           65536 ram12 
 (driver?)
010d           65536 ram13 
 (driver?)
010e           65536 ram14 
 (driver?)
010f           65536 ram15 
 (driver?)
1f00             256 mtdblock0 
 (driver?)
1f01             128 mtdblock1 
 (driver?)
1f02            5120 mtdblock2 
 (driver?)
1f03          256640 mtdblock3 
 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
CPU: 0 PID: 1 Comm: swapper Not tainted 4.10.15 #4
Hardware name: MINI2440
[<c000f740>] (unwind_backtrace) from [<c000d2bc>] (show_stack+0x10/0x14)
[<c000d2bc>] (show_stack) from [<c006915c>] (panic+0xb0/0x248)
[<c006915c>] (panic) from [<c05751d0>] (mount_block_root+0x198/0x280)
[<c05751d0>] (mount_block_root) from [<c05754a4>] (mount_root+0xf0/0x11c)
[<c05754a4>] (mount_root) from [<c057562c>] (prepare_namespace+0x15c/0x1b0)
[<c057562c>] (prepare_namespace) from [<c0574dd4>] (kernel_init_freeable+0x17c/0x1c8)
[<c0574dd4>] (kernel_init_freeable) from [<c0456040>] (kernel_init+0x8/0xf4)
[<c0456040>] (kernel_init) from [<c000a470>] (ret_from_fork+0x14/0x24)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

通过主机的日志发现有如下日志信息,说明系统已经检测到了开发板的挂载行为,但是不知什么原因就是挂载不上,也没有更多的其它日志信息,很无奈

Aug 11 20:23:21 debian rpc.mountd[599]: authenticated mount request from 10.0.0.3:1011 for /data/nfs/rootfs (/data/nfs/rootfs)
Aug 11 20:23:26 debian rpc.mountd[599]: authenticated mount request from 10.0.0.3:767 for /data/nfs/rootfs (/data/nfs/rootfs)
Aug 11 20:23:36 debian rpc.mountd[599]: authenticated mount request from 10.0.0.3:937 for /data/nfs/rootfs (/data/nfs/rootfs)
Aug 11 20:23:56 debian rpc.mountd[599]: authenticated mount request from 10.0.0.3:961 for /data/nfs/rootfs (/data/nfs/rootfs)

    后面经过多天的摸索,发现只要在开发板的内核配置中去掉NFS client support for NFS version 2选项后系统就不会再检测到开发板的挂载行为了,无论选择的是NFS client support for NFS version 3还是NFS client support for NFS version 4 都无济于事,宿主机没有任何反应了,同时开发板也没有任何能挂载上的迹象,经过多天折腾无效。

    既然发现了与NFS2客户端有关那还是得继续努力一下,通过sudo nfsstat命令查看宿主机的NFS信息:

[jiangxianxu@debian:linux-4.10.15]$sudo nfsstat 
Server rpc stats:
calls      badcalls   badfmt     badauth    badclnt
8196       11         11         0          0       

Server nfs v3:
null             getattr          setattr          lookup           access           
1         0%     24        3%     0         0%     52        7%     30        4%     
readlink         read             write            create           mkdir            
8         1%     623      84%     0         0%     0         0%     0         0%     
symlink          mknod            remove           rmdir            rename           
0         0%     0         0%     0         0%     0         0%     0         0%     
link             readdir          readdirplus      fsstat           fsinfo           
0         0%     0         0%     0         0%     0         0%     2         0%     
pathconf         commit           
1         0%     0         0%     

Server nfs v4:
null             compound         
12        0%     7443     99%     

Server nfs v4 operations:
op0-unused       op1-unused       op2-future       access           close            
0         0%     0         0%     0         0%     365       2%     126       0%     
commit           create           delegpurge       delegreturn      getattr          
0         0%     0         0%     0         0%     45        0%     1070      6%     
getfh            link             lock             lockt            locku            
455       2%     0         0%     16        0%     0         0%     16        0%     
lookup           lookup_root      nverify          open             openattr         
418       2%     0         0%     0         0%     254       1%     0         0%     
open_conf        open_dgrd        putfh            putpubfh         putrootfh        
10        0%     0         0%     7316     45%     0         0%     11        0%     
read             readdir          readlink         remove           rename           
5851     36%     10        0%     88        0%     0         0%     0         0%     
renew            restorefh        savefh           secinfo          setattr          
55        0%     0         0%     0         0%     0         0%     0         0%     
setcltid         setcltidconf     verify           write            rellockowner     
22        0%     21        0%     0         0%     7         0%     16        0%     
bc_ctl           bind_conn        exchange_id      create_ses       destroy_ses      
0         0%     0         0%     0         0%     0         0%     0         0%     
free_stateid     getdirdeleg      getdevinfo       getdevlist       layoutcommit     
0         0%     0         0%     0         0%     0         0%     0         0%     
layoutget        layoutreturn     secinfononam     sequence         set_ssv          
0         0%     0         0%     0         0%     0         0%     0         0%     
test_stateid     want_deleg       destroy_clid     reclaim_comp     allocate         
0         0%     0         0%     0         0%     0         0%     0         0%     
copy             copy_notify      deallocate       ioadvise         layouterror      
0         0%     0         0%     0         0%     0         0%     0         0%     
layoutstats      offloadcancel    offloadstatus    readplus         seek             
0         0%     0         0%     0         0%     0         0%     0         0%     
write_same       
0         0%     

[jiangxianxu@debian:linux-4.10.15]$

   通过信息发现宿主机安装的是NFSV3和NFSV4服务器,好像没有NFSV2!!!!!!,难道与这个有关?开发板用NFSV2挂载的时候宿主机的mount有反应,而V3和V4都没有反应,是不是哪里没有搞对,导致开发板没有正确的使用NFSV3和V4与宿主机通信,导致挂载不上。后面开始向这个方向努力,在网上搜索很久无果,还是无法解决。

    终于有一天与朋友交谈中得知可以通过开发板的bootargs指定启动时使用什么版本的NFS客户端,我去,这简直是雪中送炭啊,难道被困扰多时的问题可以就这么解决了吗?回来果断试了一把,在bootargs中加入指定NFS版本的信息:

setenv bootargs root=/dev/nfs rw nfsroot=10.0.0.2:/data/nfs/rootfs,nolock,proto=tcp,nfsvers=4 ip=10.0.0.3 console=ttySAC0,115200 ctp=1 console=ttySAC0,115200

其中nfsvers=4即为指定系统使用NFSV4客户端挂载,开机测试,果然启动成功,顿时喜悦之情无法言语......

U-Boot 2009.08 (Aug 11 2016 - 23:10:26)

modified by jiangxianxv ([email protected])
DRAM:  64 MB
Flash: 512 kB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
[uboot@mini2440]# print
bootdelay=3
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
netmask=255.255.255.0
ethact=dm9000
ipaddr=10.0.0.3
serverip=10.0.0.2
gatewayip=10.0.0.3
bootargs=root=/dev/nfs rw nfsroot=10.0.0.2:/data/nfs/rootfs,nolock,proto=tcp,nfsvers=4 ip=10.0.0.3 console=ttySAC0,115200 ctp=1 console=ttySAC0,115200
stdin=serial
stdout=serial
stderr=serial

Environment size: 335/131068 bytes
[uboot@mini2440]# tftp 0x30008000 uImage
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 10.0.0.2; our IP address is 10.0.0.3
Filename 'uImage'.
Load address: 0x30008000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ################
done
Bytes transferred = 3074400 (2ee960 hex)
[uboot@mini2440]# bootm 0x30008000
MACH_TYPE = 1999
bootargs = root=/dev/nfs rw nfsroot=10.0.0.2:/data/nfs/rootfs,nolock,proto=tcp,nfsvers=4 ip=10.0.0.3 console=ttySAC0,115200 ctp=1 console=ttySAC0,115200
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   linux-4.10.15
   Created:      2017-08-11  13:57:27 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3074336 Bytes =  2.9 MB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.10.15 (jiangxianxu@debian) (gcc version 6.3.0 20170516 (Debian 6.3.0-18) ) #4 Fri Aug 11 21:51:48 CST 2017
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=0000717f
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
Memory policy: Data cache writeback
CPU S3C2440A (id 0x32440001)
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: root=/dev/nfs rw nfsroot=10.0.0.2:/data/nfs/rootfs,nolock,proto=tcp,nfsvers=4 ip=10.0.0.3 console=ttySAC0,115200 ctp=1 console=ttySAC0,115200
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 58728K/65536K available (4423K kernel code, 185K rwdata, 992K rodata, 176K init, 258K bss, 6808K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xc4800000 - 0xff800000   ( 944 MB)
    lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .text : 0xc0008000 - 0xc045a100   (4425 kB)
      .init : 0xc0574000 - 0xc05a0000   ( 176 kB)
      .data : 0xc05a0000 - 0xc05ce4e0   ( 186 kB)
       .bss : 0xc05ce4e0 - 0xc060eef8   ( 259 kB)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:103
S3C2440: IRQ Support
irq: clearing pending status 00000003
irq: clearing pending status 00000002
sched_clock: 16 bits at 1012kHz, resolution 987ns, wraps every 32362962ns
clocksource: samsung_clocksource_timer: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 28803037 ns
Console: colour dummy device 80x30
Calibrating delay loop... 50.38 BogoMIPS (lpj=251904)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x300081e0 - 0x30008238
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: -1, 3072 bytes)
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
MINI2440: Option string mini2440=0tb
MINI2440: 't' ignored, touchscreen not compiled in
MINI2440: LCD
 [0:240x320]
 1:800x480
 2:1024x768
 3:320x240

S3C2440: Initialising architecture
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c.0: slave address 0x10
s3c-i2c s3c2440-i2c.0: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c.0: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource samsung_clocksource_timer
NET: Registered protocol family 2
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
workingset: timestamp_bits=30 max_order=14 bucket_order=0
NFS: Registering the id_resolver key type
Key type id_resolver registered
Key type id_legacy registered
nfs4filelayout_init: NFSv4 File Layout Driver Registering...
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
s3c2410-lcd s3c2410-lcd: fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 74, base_baud = 0) is a S3C2440
console [ttySAC0] enabled
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 77, base_baud = 0) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 80, base_baud = 0) is a S3C2440
brd: module loaded
at24 0-0050: 1024 byte 24c08 EEPROM, writable, 16 bytes/write
nand: device found, Manufacturer ID: 0xec, Chip ID: 0xda
nand: Samsung NAND 256MiB 3,3V 8-bit
nand: 256 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
s3c24xx-nand s3c2440-nand: soft ECC
Creating 4 MTD partitions on "nand":
0x000000000000-0x000000040000 : "u-boot"
__nand_correct_data: uncorrectable ECC error
0x000000040000-0x000000060000 : "u-boot-env"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "kernel"
ftl_cs: FTL header not found.
0x000000560000-0x000010000000 : "root"
ftl_cs: FTL header not found.
s3c24xx-nand s3c2440-nand: Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns
eth0: dm9000e at c4a5b300,c4a5d304 IRQ 55 MAC: 08:00:3e:26:0a:5b (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci-s3c2410: OHCI S3C2410 driver
s3c2410-ohci s3c2410-ohci: OHCI Host Controller
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq disabled
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
hidraw: raw HID events driver (C) Jiri Kosina
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
NET: Registered protocol family 17
Key type dns_resolver registered
input: gpio-keys as /devices/platform/gpio-keys/input/input0
hctosys: unable to open rtc device (rtc0)
lingd2440_dm9000_init
dm9000 dm9000 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
random: fast init done
IP-Config: Guessing netmask 255.0.0.0
IP-Config: Complete:
     device=eth0, hwaddr=08:00:3e:26:0a:5b, ipaddr=10.0.0.3, mask=255.0.0.0, gw=255.255.255.255
     host=10.0.0.3, domain=, nis-domain=(none)
     bootserver=255.255.255.255, rootserver=10.0.0.2, rootpath=
ALSA device list:
  No soundcards found.
VFS: Mounted root (nfs4 filesystem) on device 0:13.
Freeing unused kernel memory: 176K
This architecture does not have kernel memory protection.
----------munt all----------------
****************Studying ARM*********************
Kernel version:linux-4.10.15
Auth:jiangxianxu
Date:2017-08-11
***********************************************
mini2440_leds: loading out-of-tree module taints kernel.
leds    initialized

Please press Enter to activate this console. 
[root@JIANG-/]#
[root@JIANG-/]#
[root@JIANG-/]#ls
bin              home             proc             try_var.sh
boot             lib              root             unixbench-5.1.2
dev              linuxrc          sbin             usr
etc              mnt              sys              var
ethtool          modules          tmp
[root@JIANG-/]#

至此,困扰多天的问题终于得到解决,可以安心的使用新系统了,


猜你喜欢

转载自blog.csdn.net/u013451404/article/details/77103871