Linux的设备和设备号是指啥
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux的设备和设备号是指啥相关的知识,希望对你有一定的参考价值。
参考技术A Linux中I/O设备分为两类:字符设备和块设备。两种设备本身没有严格限制,但是,基于不同的功能进行了分类。(1)字符设备:提供连续的数据流,应用程序可以顺序读取,通常不支持随机存取。相反,此类设备支持按字节/字符来读写数据。举例来说,键盘、串口、调制解调器都是典型的字符设备。(2)块设备:应用程序可以随机访问设备数据,程序可自行确定读取数据的位置。硬盘、软盘、CD-ROM驱动器和闪存都是典型的块设备,应用程序可以寻址磁盘上的任何位置,并由此读取数据。此外,数据的读写只能以块(通常是512B)的倍数进行。与字符设备不同,块设备并不支持基于字符的寻址。总结一下,这两种类型的设备的根本区别在于它们是否可以被随机访问。字符设备只能顺序读取,块设备可以随机读取。linux 块设备驱动——块设备应用层的操作
一: 加载好sbull驱动
[email protected]:/# ls /dev/sbull -l brw-r--r-- 1 root root 254, 16 Mar 25 08:25 /dev/sbull [email protected]:/#
可以看到sbull文件属性是一个块设备, 主设备号是254,次设备号是16
二:对设备进行分区
[email protected]:/# fdisk /dev/sbull [ 266.720648] sbull: unknown partition table Welcome to fdisk (util-linux 2.24.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xb90ed7e4. Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table Misc m print this menu u change display/entry units x extra functionality (experts only) Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table Command (m for help): n //输入n 添加一个新的分区Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p //主分区 Partition number (1-4, default 1): 1 //该分区NO.1 First sector (1-1023, default 1): 1 // 该分区起始扇区 Last sector, +sectors or +size{K,M,G,T,P} (1-1023, default 1023): 1023 //该分区结尾扇区 Created a new partition 1 of type ‘Linux‘ and of size 511.5 KiB. Command (m for help): w //保存并退出 The partition table has been altered. Calling ioctl() to re-read parti[ 303.589984] sbull: sbull1 tion table. Syncing disks.
查看分区:笔者做了两个分区
[email protected]:/# ls /dev/sbull*
/dev/sbull /dev/sbull1 /dev/sbull2
[email protected]:/#
二:格式化文件系统
[email protected]:/# mkfs.ext4 /dev/sbull2 mke2fs 1.42.4 (12-June-2012) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 64 inodes, 504 blocks 25 blocks (4.96%) reserved for the super user First data block=1 Maximum filesystem blocks=524288 1 block group 8192 blocks per group, 8192 fragments per group 64 inodes per group Allocating group tables: done Writing inode tables: done Filesystem too small for a journal Writing superblocks and filesystem accounting information: done
三:挂在文件系统
[email protected]:/# mount /dev/sbull1 /tmp/mnt/sbull/ mount: mounting /dev/sbull1 on /tmp/mnt/sbull/ failed: Invalid argument [email protected]:/# mount /dev/sbull2 /tmp/mnt/sbull/ [ 832.527053] EXT4-fs (sbull2): couldn‘t mount as ext3 due to feature incompatibilities [ 832.557133] EXT4-fs (sbull2): couldn‘t mount as ext2 due to feature incompatibilities [ 832.588127] EXT4-fs (sbull2): mounted filesystem without journal. Opts: (null) [email protected]:/# [email protected]:/#
以上完成了该块设备应用层的挂在操作,接下来就可以直接在/tmp/mnt/sbull目录里面操作了
以上是关于Linux的设备和设备号是指啥的主要内容,如果未能解决你的问题,请参考以下文章