本文主要是介绍Linux系统git漏提空目录导致根文件系统rootfs启动时挂载失败,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题
从git服务器下载SDK代码,自编译出大包文件,在进行烧写后发现启动时挂载rootfs根文件系统失败,打印如下:
[ 4.500157] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 161
[ 4.556092] UBIFS (ubi0:0): recovery needed
[ 4.599850] UBIFS (ubi0:0): recovery completed
[ 4.603390] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
[ 4.610680] UBIFS (ubi0:0): LEB size: 253952 bytes (248 KiB), min./max. I/O unit sizes: 4096 bytes/4096 bytes
[ 4.620569] UBIFS (ubi0:0): FS size: 76439552 bytes (72 MiB, 301 LEBs), journal size 9404416 bytes (8 MiB, 38 LEBs)
[ 4.630979] UBIFS (ubi0:0): reserved for root: 0 bytes (0 KiB)
[ 4.636771] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID FF904CF4-E7E5-4D45-8522-B0458FBC0218, small LPT model
[ 4.650529] VFS: Mounted root (ubifs filesystem) on device 0:12.
[ 4.655939] Freeing unused kernel memory: 312K (c0ad8000 - c0b26000)
[ 4.661881] @RamosKernel command line: noinitrd rw console=ttyHSL0,115200,n8 androidboot.hardware=qcom ehci-hcd.park=3 msm_rtb.filter=0x37 lpm_levels.sleep_disabled=1 earlycon=msm_hsl_uart,0x78b3000 androidboot.serialno=a37185f5 androidboot.authorized_kernel=true androidboot.baseband=msm rootfstype=ubifs rootflags=bulk_read root=ubi0:rootfs ubi.mtd=19 ubi.mtd=13
[ 4.694665] quectel_mount failed 挂载失败
[ 4.697420] @Ramos set restore modem flag here 444444
[ 4.702685] @Ramos :mtdsize:500000, mtd->writesize =4096, mtd->erasesize:262144 blockcount
[ 4.711091] @Ramos qfirst_goodblock_addr=-1610612461
[ 4.716387] @Ramos set partition(modem) restore, offset=440000,print magic1=0,magic2=78e5d4c2
[ 4.725205] @Ramos g_fota_upgradedFlag_goodblock=-1 fota_upgradedFlag=3670016
[ 4.731834] @Ramos set partition magic right !!!!!
[ 4.739764] @Ramos set partition(modem) flag=1,successd restore times=246 !!!
[ 4.745892] Going down for restart now 【这里重启了】
[ 4.750241] Calling SCM to disable SPMI PMI
使用发布版本启动挂载正常打印如下:
[ 4.500157] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 161
[ 4.556092] UBIFS (ubi0:0): recovery needed
[ 4.599850] UBIFS (ubi0:0): recovery completed
[ 4.603390] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
[ 4.610680] UBIFS (ubi0:0): LEB size: 253952 bytes (248 KiB), min./max. I/O unit sizes: 4096 bytes/4096 bytes
[ 4.620569] UBIFS (ubi0:0): FS size: 76439552 bytes (72 MiB, 301 LEBs), journal size 9404416 bytes (8 MiB, 38 LEBs)
[ 4.630979] UBIFS (ubi0:0): reserved for root: 0 bytes (0 KiB)
[ 4.636771] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID FF904CF4-E7E5-4D45-8522-B0458FBC0218, small LPT model
[ 4.650529] VFS: Mounted root (ubifs filesystem) on device 0:12.
[ 4.714335] Freeing unused kernel memory: 312K (c0ad8000 - c0b26000)
[ 4.720271] @RamosKernel command line: noinitrd rw console=ttyHSL0,115200,n8 androidboot.hardware=qcom ehci-hcd.park=3 msm_rtb.filter=0x37 lpm_levels.sleep_disabled=1 earlycon=msm_hsl_uart,0x78b3000 androidboot.serialno=588c78b androidboot.authorized_kernel=true androidboot.baseband=msm rootfstype=ubifs rootflags=bulk_read root=ubi0:rootfs ubi.mtd=19 ubi.mtd=13
[ 4.855481] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "modem", R/O mode
[ 4.862686] UBIFS (ubi1:0): LEB size: 253952 bytes (248 KiB), min./max. I/O unit sizes: 4096 bytes/4096 bytes
[ 4.872559] UBIFS (ubi1:0): FS size: 47235072 bytes (45 MiB, 186 LEBs), journal size 9404416 bytes (8 MiB, 38 LEBs)
[ 4.882971] UBIFS (ubi1:0): reserved for root: 0 bytes (0 KiB)
[ 4.888754] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID 43E7EFF3-32C9-48F0-8476-F22950783580, small LPT model
[ 4.906146] quectel_mount_success
分析
1、首先怀疑是编译环境问题,通过对比提交原始代码的服务器,没有发现差异;
2、怀疑是提交原始代码的服务器漏提交文件,通过对比发现漏提交了很多空目录,对比结果如下;
bin build.prop dev etc lib linuxrc sbin share system target usr var WEBSERVER www
bin boot build.prop cache data dev etc firmware home lib linuxrc media mnt proc run sbin share sys system target tmp usr var WEBSERVER www
3、通过上面对比得知缺少目录,那到底是缺少哪个目录呢?来查看一下内核挂载失败的打印:quectel_mount failed,通过搜索内核代码如下:
pr_notice("@RamosKernel command line: %s\n", temp_cmdLine);//if(strstr(temp_cmdLine, "ubi.mtd=19")) //this condition will replace last,if ( system_mode_flag == QUECTEL_SYSTEM_NORMAL_MODE ){extern void *subsystem_get_with_fwname(const char *name, const char *fw_name);if( sys_mount("ubi1:modem", "/firmware", rootfstype, MS_RDONLY, rootflags)&& sys_mount("/dev/ubi1_0", "/firmware", rootfstype, MS_RDONLY, rootflags)){printk("quectel_mount failed \n");printk("@Ramos set restore modem flag here 444444 \r\n");Quectel_Set_Partition_RestoreFlag("modem",4); // modem أлԭ}else{printk("quectel_mount_success \n");subsystem_get_with_fwname("modem", "modem");}}
可以看到是挂载modem分区到/firmware目录下失败,不是前面分析出的挂载rootfs跟文件系统失败;modem分区文件NON-HLOS.ubi我们没有修改,不会有问题的;查看得知是firmware目录不存在导致,使用系统调用mount挂载时目录必须存在是基本的常识,在用户层会提示“No such file or directory”,但是sys_mount为何没有提示呢?
sys_mount在ext4文件系统学习的时候应该是看过代码实现了的,再回去复习一下,看内核代码检查后确实没有提示;
挂载失败后,设置分区参数重启使用recovery进行恢复,这里不是分区文件问题,而是没有这个目录,所以导致的结果就是循环的挂载失败并一直重启。
原因
git会自动忽略空目录,导致在使用git status命令不能发现漏提交的空目录,这样在提交SDK源码文件时漏提交空目录,这样的话其他人通过git下载文件后缺少跟文件系统必须的目录,导致启动挂载失败;
解决
在空目录下增加.gitkeep文件,这样就可以让git追踪空目录,这也是最通用的方式(注:.gitigonre中不要忽略.gitkeep文件否则会失效);
搜索空目录结果如下:
[yubo.wang@localhost ql-ol-rootfs]$ find ./ -type d -empty
./mnt
./proc
./run
./sys
./tmp
。。。
在每个空目录下增加.gitkeep文件:
find ./ -type d -empty | xargs -I {} touch {}/.gitkeep
增加.gitkeep文件后就能使用git status查看差异了:
最后把空目录提交上去然后下载编译烧写验证OK。
总结
提交git代码文件时,需要注意空目录的处理,防止出现上面的类似问题。遇到此类问题也可逐一排查环境和代码来定位。
这篇关于Linux系统git漏提空目录导致根文件系统rootfs启动时挂载失败的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!