linux分区命令mtd的简单介绍

linux 中mtd设备一般用来干啥的? mtdblock呢,又是干啥的????

mtd是字符设备,mtdblock是块设备

在绵阳等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都网站制作 网站设计制作定制网站建设,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销,成都外贸网站建设,绵阳网站建设费用合理。

可以看看dd命令的实现,在busybox里有

补充:

/dev/mtd/* 或者 /dev/mtd* 这两种表示方式一般表示的是字符设备/dev/mtdblock/* 或者 /dev/mtdblock* 这两种是块设备的表示方式mount 的一般都是块设备貌似dd只对字符设备进行操作

举例:

The mtd0 is char device of mtdblock0.

Create char mtd devices

mknod /dev/mtd0 c 90 0

mknod /dev/mtd1 c 90 2

Linux系统中/dev/mtd与/dev/mtdblock的区别,即MTD字符设备和块设备的区别

1. /dev/mtdN 是Linux 中的MTD架构中,系统自己实现的mtd分区所对应的字符设备,其里面添加了一些ioctl,支持很多命令,如MEMGETINFO,MEMERASE等。而mtd-util中的flash_eraseall等工具,就是以这些ioctl为基础而实现的工具,实现一些关于Flash的操作。比如,mtd 工具中的 flash_eraseall中的:if (ioctl(fd, MEMGETINFO, meminfo) != 0) { fprintf(stderr, "%s: %s: unable to get MTD device info\n", exe_name, mtd_device); return 1;}其中,MEMGETINFO,就是Linux MTD中的drivers/mtd/nand/mtdchar.c中的:static int mtd_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long arg){。。。。。case MEMGETINFO: info.type = mtd-type; info.flags = mtd-flags; info.size = mtd-size; info.erasesize = mtd-erasesize; info.writesize = mtd-writesize; info.oobsize = mtd-oobsize; /* The below fields are obsolete */ info.ecctype = -1; info.eccsize = 0; if (copy_to_user(argp, info, sizeof(struct mtd_info_user))) return -EFAULT; break;。。。}而/dev/mtdblockN,是Nand Flash驱动中,驱动在用add_mtd_partitions()添加MTD设备分区,而生成的对应的块设备。根据以上内容,也就更加明白,为什么不能用nandwrite,flash_eraseall,flash_erase等工具去对/dev/mtdblockN去操作了。因为/dev/mtdblock中不包含对应的ioctl,不支持你这么操作。2. mtd char 设备的主设备号是90,而mtd block设备的主设备号是31:# ls /dev/mtd? -l crw-r----- 1 root root 90, 0 May 30 2007 /dev/mtd0crw-r----- 1 root root 90, 2 May 30 2007 /dev/mtd1crw-r----- 1 root root 90, 4 Jul 17 2009 /dev/mtd2crw-r----- 1 root root 90, 6 May 30 2007 /dev/mtd3crwxrwxrwx 1 root root 90, 8 May 30 2007 /dev/mtd4crwxrwxrwx 1 root root 90, 10 May 30 2007 /dev/mtd5crwxrwxrwx 1 root root 90, 12 May 30 2007 /dev/mtd6crwxrwxrwx 1 root root 90, 14 May 30 2007 /dev/mtd7crwxrwxrwx 1 root root 90, 16 May 30 2007 /dev/mtd8crwxrwxrwx 1 root root 90, 18 May 30 2007 /dev/mtd9# ls /dev/mtdblock? -lbrw-r----- 1 root root 31, 0 May 30 2007 /dev/mtdblock0brw-r----- 1 root root 31, 1 May 30 2007 /dev/mtdblock1brw-r----- 1 root root 31, 2 May 30 2007 /dev/mtdblock2brw-r----- 1 root root 31, 3 May 30 2007 /dev/mtdblock3brwxrwxrwx 1 root root 31, 4 May 30 2007 /dev/mtdblock4brwxrwxrwx 1 root root 31, 5 May 30 2007 /dev/mtdblock5brwxrwxrwx 1 root root 31, 6 May 30 2007 /dev/mtdblock6brwxrwxrwx 1 root root 31, 7 May 30 2007 /dev/mtdblock7brwxrwxrwx 1 root root 31, 8 May 30 2007 /dev/mtdblock8brwxrwxrwx 1 root root 31, 9 May 30 2007 /dev/mtdblock9此设备号,定义在/include/linux/mtd/mtd.h中 :#define MTD_CHAR_MAJOR 90#define MTD_BLOCK_MAJOR 313. 其中,mtd的块设备的大小,可以通过查看分区信息获得:# cat /proc/partitionsmajor minor #blocks name31 0 1024 mtdblock031 1 8192 mtdblock131 2 204800 mtdblock231 3 65536 mtdblock331 4 225280 mtdblock4上面中显示的块设备大小,是block的数目,每个block是1KB。而每个字符设备,其实就是对应着上面的每个块设备。即/dev/mtd0对应/dev/mtdblock0,其他以此类推。换句话说,mtdblockN的一些属性,也就是mtdN的属性,比如大小。4。对每个mtd字符设备的操作,比如利用nandwrite去对/dev/mtd0写数据,实际就是操作/dev/mtdblock0。而这些操作里面涉及到的偏移量offset,都指的是此mtd 分区内的偏移。比如向/dev/mtd1的offset为0的位置写入数据,实际操作的是物理偏移offset=/dev/mtd0的大小=1MB=0x100000。

linux硬盘分区命令

1.返回到Linux系统的命令终端,再次输入 fdisk -l 命令,就可以看到新添...

2.输入fdisk /dev/sdb 开始对新添加的硬盘进行分区操作。

3.输入n 按回车键,然后再输入 p ,按回车键。 n 表示新建一个分区,p ...

4.输入Partition number(即:分区号),按回车键。如果在 /dev/sdb ...

5.等待分区创建完成,输入 w 保存磁盘分区,并退出磁盘分区命令。

linux mtd 分区什么意思

日常用语

英文缩写:MTD

英文全称:Month To Days

中文解释:月初到今日

编程领域

MTD(memory technology device内存技术设备)是用于访问memory设备(ROM、flash)的Linux的子系统。MTD的主要目的是为了使新的memory设备的驱动更加简单,为此它在硬件和上层之间提供了一个抽象的接口。MTD的所有源代码在/drivers/mtd子目录下。我将CFI接口的MTD设备分为四层(从设备节点直到底层硬件驱动),这四层从上到下依次是:设备节点、MTD设备层、MTD原始设备层和硬件驱动层。

在LINUX系统中,分区与格式化硬盘的命令是什么?

Linux下常用的分区工具:

fdisk/sfdisk:命令行工具,各种版本和环境都能使用,包含在软件包util-linux中

diskdruid:图形化分区工具,只能在安装REDHAT系统时使用。

第一步:fdisk

[root@novice ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

[root@novice ~]# fdisk /dev/sdb

Command (m for help): #在输入上面的命令后会出现左边的提示,输入m就会得到一个帮助菜单,如下:

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)

#help虽然是英文的,可都很简单,在这里不再解释。

#现在,我们正式开始分区的操作:

Command (m for help): n #新建分区

Command action

e extended

p primary partition (1-4)

#e/p分别对应扩展分区 /主分区;我们先分四个主分区,每个50M;然后再来增加主分区或扩展分区,看会出现怎样的状况,嘿嘿。

p #分区类型为主分区

Partition number (1-4, default 1): 1 #分区号,在这里我们依次选择1、2、3、4

First sector (2048-496127, default 2048): #指定分区的起始扇区,一般默认,按enter键即可。

Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分区的终止扇区,根据前面的提示我们可以做出相应的选择+sectors 或 +size{K,M,G}

Command (m for help): p #用p打印出已建好的分区列表

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

#剩下的三个分区的建立操作同上

#分好四个主分区后的情况如下

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 309298 25+ 83 Linux

#已经建好四个主分区啦,现在我们来看看如果再建主分区或是扩展分区的话会出现怎样的情况:

Command (m for help): n

You must delete some partition and add an extended partition first

#看到了吧,不能再建分区啦!要再建分区的话必须删除some分区,再新建一个扩展分区才行。

#现在,我们删掉一个主分区,来新建扩展分区

Command (m for help): d #删除分区

Partition number (1-4): 4 #选择要删除分区的分区号,我们选第四个

Command (m for help): p #打印,如下,四个分区变成了三个!

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

#新建一个扩展分区

#如果在没有建满三个主分的区的情况下建立扩展分区,相关选项会有些不同。

Command (m for help): n

Command action

e extended

p primary partition (1-4)

e

Selected partition 4

First sector (309248-496127, default 309248): #enter,默认

Using default value 309248

Last sector, +sectors or +size{K,M,G} (309248-496127, default 496127): #enter,默认,使用剩余空间

Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

#接下来,我们在新建的扩展分区里再新建两个逻辑分区,因为已经有了三个主分区,这里不会再显示是建立逻辑分区还是主分区的提示!

Command (m for help): n

First sector (311296-496127, default 311296): #enter

Using default value 311296

Last sector, +sectors or +size{K,M,G} (311296-496127, default 496127): +50M

Command (m for help): n

First sector (415744-496127, default 415744): #enter

Using default value 415744

Last sector, +sectors or +size{K,M,G} (415744-496127, default 496127): #enter

Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

/dev/sdb5 311296 413695 51200 83 Linux

/dev/sdb6 415744 496127 40192 83 Linux

#上面的列表,就是我们今天分区的成果啦!接下来保存退出,重启计算机,就可以进行下一步的mkfs操作啦!如果忘记了相关的操作命令,记得按m!!!

Command (m for help): w #保存

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

另:在建好分区后,我们还可以更改相关分区的文件系统类型

#如,我们要把第二个主分区改成Linux下的交换分区,操作如下

Command (m for help): t #更改文件系统类型

Partition number (1-6): 2 #选择第二个分区

Hex code (type L to list codes): L #选择要更改的文件系统编码,可以按L来查看相关编码信息。

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-

2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-

3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

............

16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS

17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE

18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto

1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep

1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT

1e Hidden W95 FAT1

Hex code (type L to list codes): 82 #查找到linux swap的编码为82

Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p

..............

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 82 Linux swap / Solaris

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

/dev/sdb5 311296 413695 51200 83 Linux

/dev/sdb6 415744 496127 40192 83 Linux

#最后别忘了保存!如果你须要的话!

#扩展分区不能直接使用,逻辑分区只能建立在扩展分区上!

第二步:mkfs(mkfs时分区的格式最好与fdisk设定的分区格式一致,不然.......)

mkfs支持ext2 ext3 vfa msdos jfs reiserfs等文件系统。

用法1:mkfs -t

例: mkfs -t ext3 /dev/sdb2

用法2:mkfs.

例:mkfs,vfat /dev/sdb3

mke2fs支持ext2/ext3文件系统

用法:mke2fs [-j]

例:mke2fs -j /dev/sdb5

# 更多更具体的用法请参照相关命令的man手册

下面,接着实验:

例一

[root@novice ~]# mkfs -t ext3 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

12824 inodes, 51200 blocks

2560 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=52428800

7 block groups

8192 blocks per group, 8192 fragments per group

1832 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

第三部:挂载

挂载:mount

例:mount /dev/sdb1 /mnt /sdb1

卸载:umonut

例:umount /dev/sdb1

网站名称:linux分区命令mtd的简单介绍
分享URL:https://www.cdcxhl.com/article0/ddgsiio.html

成都网站建设公司_创新互联,为您提供品牌网站制作Google微信小程序网站维护响应式网站网站导航

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站托管运营