1. 程式人生 > >6、debian搭建nfs伺服器

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資訊:

[[email protected]: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%     

[
[email protected]
: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
[[email protected]]# 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
[[email protected]]# 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)
[[email protected]]# 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 ([email protected]) (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. 
[[email protected]/]#
[[email protected]/]#
[[email protected]/]#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
[[email protected]/]#

至此,困擾多天的問題終於得到解決,可以安心的使用新系統了,