Linux文件系统--UBI文件系统移植


文章摘要: 本文描述了UBI文件系统的移植与应用。

UBIFS (Unsorted Block Image File System)无排序区块镜像文件系统,由IBM与Nokia的工程师Thomas Gleixner,Artem Bityutskiy所设计,专门为了解决MTD(Memory Technology Device)设备所遇到的瓶颈,用于大容量固态存储设备。


1.添加MTD,NandFlash,UBI驱动支持(内核)

Device Drivers  ---> 
    <*> Memory Technology Device (MTD) support  --->  
        [*]   MTD partitioning support
        <*>   NAND Device Support  --->  
            <*>   NAND Flash support for Samsung S3C SoCs 
        <*>   Enable UBI - Unsorted block images  --->  

注意事项:
如果在配置选项中找不到选项,可先修改.config文件中的CONFIG_MTD_UBI=y,再重make menuconfig即可;
如果不添加这里的选项,则后续的配置中找不到UBIFS选项;


2.添加UBI文件系统支持(内核)

File systems  --->  
    [*]Miscellaneous filesystems  ---> 
        <*>   UBIFS file system support  

      

修改UBOOT添加UBI支持(未验证,主流模式是通过MTD工具)
1.制作根文件系统

#mkfs.ubifs -r root/ -m 2048 -e 129024 -c 2364 -o root-fs.img 

2.擦除 root 分区
[uboot]#nand erase root
3.对 root 分区进行 ubi 格式化
[uboot]#ubi part root
4.将文件系统下载到内存
[uboot]#tftp 0x30008000 ubifs.img
5.将文件系统烧写到 rootfs 中
[uboot]#ubi.write 0x30008000 rootfs 0x339600


利用MTD工具,直接在开发板上配置UBI文件系统
1.首先交叉编译MTD工具,得到mkfs.ubifs工具;
2.使用nfs启动系统,执行以下命令挂载ubifs:

#flash_eraseall /dev/mtd2
#ubiattach /dev/ubi_ctrl -m 2                  
#ubimkvol /dev/ubi0 -N rootfs -s 50 MiB
#mount -t ubifs ubi0_0 /mnt/ubifs 

或者

#mount -t ubifs ubi0:rootfs /mnt/ubifs

3.在开发板中执行命令,将文件系统复制至ubifs目录下即可(可以直接解压至此)。

注意事项:
flash_eraseall 擦除flash;
ubiattach 用来关联ubi;
ubimkvol 用来创建ubi文件系统,-N指定卷标的名称,挂载时候要用到;

如果只是挂载已存在的ubi文件系统,只需用ubiattach 和 mount即可(不用再擦除和创建文件系统了);

这里的/dev/mtd2和-m 2是根据分区表中配置的,
-s 50 MiB是指文件系统的大小,需要比分区小几M(用来保存ubifs信息);
-N rootfs是设置卷标(可任意),挂载时候可通过文件名来挂载ubi0:rootfs
这些参数需要调整的与实际相同

如果不能识别MiB参数,原因待查(没有空格??).


内核没有配置,选中如下选项即可

[*]  Extended attributes support 
[*]  Advanced compression options 
[*]  LZO compression support 
[*]  ZLIB compression support  

具体是哪个稍后再试(啥意思,时间长了我自己都忘记了)。


设置启动参数:

[uboot]#setenv bootargs 'ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs console=ttySAC0,115200 wvga calibration rw' 

常见问题:

[root@localhost /]# mount -t ubifs ubi0_0 /mnt/ubifs
UBIFS error (pid 961): init_constants_early: too few LEBs (1), min. is 17
mount: mounting ubi0_0 on /mnt/ubifs failed: Invalid argument

此问题是由于说明分区太小了,不足于容纳UBI文件系统,经过检测发现是由于ubimkvol不认识MiB单位,造成了文件系统实际只有50Byte.

- 阅读全文 -

uboot使用笔记


文章摘要: 本文是uboot使用笔记,主要描述了命令说明,参数说明,以及配置说明.


加载内核

通过tftp加载内核:

tftpboot 30008000 192.168.9.126:/zImage.img

通过nfs加载内核:

nfs 30008000 192.168.9.126:/home/user/targetfs/zImage.img

通过NandFlash加载内核:

nand read 30008000 1f0000 200000

bootcmd命令
自动启动时(或boot命令)执行的命令.

从NandFlash启动时:

setenv bootcmd 'nand read 30008000 100000 200000;bootm 30008000'

1.从NandFlash读取数据至RAM中;
2.执行bootm启动操作(指明入口地址)。

从NFS启动时:

setenv bootcmd 'nfs 30008000 192.168.9.126:/home/user/targetfs/zImage.img;bootm 30008000'


bootm命令说明

命令格式: bootm [addr [arg ...]]

假设uImage的加载地址是0x20008000,ramdisk的加载地址是0x21000000,fdt的加载地址是0x22000000

只加载kernel的情况下

bootm 0x20008000

加载kernel和ramdisk

bootm 0x20008000 0x21000000

加载kernel和ramdisk并指明ramdisk大小

bootm 0x20008000 0x21000000:0x10000

加载kernel和fdt

bootm 0x20008000 - 0x22000000

用-替代中间省略的参数

加载kernel、ramdisk、fdt

bootm 0x20008000 0x21000000 0x22000000

bootargs
执行bootm命令时,传递给内核的参数.

NFS文件系统

console=ttyO0,115200n8 noinitrd board=0 root=/dev/nfs nfsroot=192.168.0.8:/opt/rootfs, nolock rw ip=192.168.0.251:192.168.0.8:192.168.0.1:255.255.255.0:X:eth0:off eth=00:01:02:03:04:05 

UBI文件系统

setenv bootargs 'console=ttySAC0,115200n8 noinitrd mem=512M rootwait=1 rw ubi.mtd=3,2048 rootfstype=ubifs root=ubi0:rootfs'

或者:

setenv bootargs noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200 

稍后加入其他的.

注意事项:

console:指定终端串口名称及数据格式,ttySx,ttySACx(三星),ttyOx(TI);

root:指明根文件系统;
/dev/nfs, 如果是nfs文件系统,需指明路径 nfsroot= (挂载参数及本机IP)
/dev/ram

rootfstype - 指明文件系统类型

mem:指定内存大小,需要与实际相符;

init: 指明系统入口,对应的是noinitrd

board - 指明开发板

ip - 本机IP:宿主机IP:网关:子网掩码:主机名称:网卡:off 网卡MAC地址


run命令

#将程序加载至内存后,从指定位置运行    
run 30008000

#也可以将命令写成一个参数,当做脚本用run命令执行
setenv loaduimage 'load mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
run loaduimage

setenv bootnfs 'run loaduimage;run loadfdt;bootm ${loadaddr} - ${fdtldaddr};'
run bootnfs

制作内核映像:
Linux命令,mkimage命令位于内核树tools目录下.

 $mkimage -n 'dsc2410' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img

-n 是指定启动时显示的Image Name.


常用宏定义(源码)

添加PING命令:

#define CONFIG_CMD_PING

添加NandFlash操作命令:

#define CONFIG_CMD_NAND

添加命令修改及历史命令支持:

#define CONFIG_CMDLINE_EDITING

命令补齐:

#define CONFIG_AUTO_COMPLETE

两个重要的宏定义:

// 如果不定义的话,无法从Bootloader传参数至内核
#define CONFIG_CMDLINE_TAG
#define CONFIG_SETUP_MEMORY_TAGS

- 阅读全文 -

Linux磁盘分区及格式化命令


本文摘要:
本文通过对U盘的分区实例,描述了fdisk命令的用法及格式化命令。


分区示例:
将U盘分为两个区,一个为FAT格式,一个为EXT格式。

#fdisk /dev/sdb 

注意事项:
对磁盘进行分区操作之前,需要先卸载该磁盘。


『显示当前分区情况的命令』

Command (m for help): p 

『删除分区:』

Command (m for help): d 
Selected partition 1  

『修改磁盘参数:』

Command (m for help): x 

Expert command (m for help): c 
Number of cylinders (1-1048576, default 1021): 239

Expert command (m for help): h 
Number of heads (1-256, default 61): 255

Expert command (m for help): s
Number of sectors (1-63, default 62): 63 
Warning: setting sector offset for DOS compatiblity

Expert command (m for help): r 

注意事项:
修改磁盘参数操作为非必须操作,可跳过此步骤,按照默认参数。


『新建分区』
主分区1,指定分区大小为10;

Command (m for help): n 
Command action 
      e      extended 
      p      primary partition (1-4) 
p 
Partition number (1-4): 1
First cylinder (1-239, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-239, default 239): +10 

『新建分区』
主分区2,全部可用空间

Command (m for help): n
Command action 
      e      extended 
      p      primary partition (1-4) 
p 
Partition number (1-4): 2 
First cylinder (12-239, default 12): 
Using default value 12 
Last cylinder or +size or +sizeM or +sizeK (12-239, default 239): 
Using default value 239 

注意事项
1.指定分区类型(主分区/逻辑分区)和分区号;
2.指定启始扇区号(一般采用默认值);
3.指定结束扇区号(决定分区大小);


『设置分区类型』

Command (m for help): t 
Selected partition 1 
Hex code (type L to list codes): 6 
Changed system type of partition 1 to 6 (FAT16)

『激活启动分区』

Command (m for help): a 
Partition number (1-4): 1  

『保存并退出』

Command (m for help): w 

格式化命令:
1.格式化为FAT16格式

#mkfs.msdos -F 16 /dev/sdb1 -n FAT16

-F 指定FAT格式(FAT16/FAT32)
-n 指定卷标名称

2.格式化为ext3格式

#mkfs.ext3 /dev/sdb2 -L EXT3

-L 表示指定卷标名称

注意事项:

不同格式的格式化命令不同,所指定的参数也不同,具体命令具体分析。


磁盘分区(fdisk)命令说明

基本命令:

Command (m for help): m
Command action
   a toggle a bootable flag (激活启动分区)
   b edit bsd disklabel
   c toggle the dos compatibility flag
   d delete a partition (删除分区)
   l list known partition types
   m print this menu (查看命令清单)
   n add a new partition (新建分区)
   o create a new empty DOS partition table
   p print the partition table (显示当前分区情况)
   q quit without saving changes (不保存退出)
   s create a new empty Sun disklabel
   t change a partition's system id (设置分区类型)
   u change display/entry units
   v verify the partition table
   w write table to disk and exit (保存并退出)
   x extra functionality (experts only)(扩展命令)

扩展命令:

Command (m for help): x
Expert command (m for help): m
Command action
   b move beginning of data in a partition
   c change number of cylinders (修改柱面信息)
   d print the raw data in the partition table
   e list extended partitions
   f fix partition order
   g create an IRIX (SGI) partition table
   h change number of heads (修改柱头信息)
   m print this menu(查看命令清单)
   p print the partition table(打印分区表)
   q quit without saving changes(不保存退出)
   r return to main menu (返回主菜单)
   s change number of sectors/track (修改磁道扇区数)
   v verify the partition table
   w write table to disk and exit(保存并退出)

无损分区软件

sudo apt-get install gparted

- 阅读全文 -

Linux连接VPN服务器


文章摘要: 本文描述了Linux系统连接VPN服务器的方法。
测试平台: debian 8.0


1.安装client

$sudo apt-get install pptp-linux

2.创建连接

$sudo pptpsetup --create myvpn --server x.x.x.x --username user --password password --encrypt --start

- 阅读全文 -

基于mysql的vsftpd虚拟用户管理


文章摘要: 本文介绍了基于Mysql数据库的FTP虚拟用户管理;
测试平台: debian 8.0(测试正常)


添加libpam-mysql支持

# apt-get install libpam-mysql

或者下载pam-mysql源码安装,生成pam_mysql.so文件;


建立PAM认证信息

创建/etc/pam.d/vsftpd_db文件:

auth    required /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0
account required /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0

- 阅读全文 -


Copyright©2025 春天花会开, All Rights Reserved. Email: webmaster@oroct.com