linux 块设备驱动(五)——块设备应用层的操作

一: 加载好sbull驱动

root@CarRadio:/# ls /dev/sbull -l brw-r--r-- 1 root root 254, 16 Mar 25 08:25 /dev/sbull root@CarRadio:/#

可以看到sbull文件属性是一个块设备, 主设备号是254,次设备号是16

 

二:对设备进行分区

root@CarRadio:/# 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.

 
 

查看分区:笔者做了两个分区

root@CarRadio:/# ls /dev/sbull*
/dev/sbull   /dev/sbull1  /dev/sbull2
root@CarRadio:/#

 

二:格式化文件系统

root@CarRadio:/# 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

三:挂在文件系统

root@CarRadio:/# mount /dev/sbull1 /tmp/mnt/sbull/ mount: mounting /dev/sbull1 on /tmp/mnt/sbull/ failed: Invalid argument root@CarRadio:/# 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) root@CarRadio:/# root@CarRadio:/#

以上完成了该块设备应用层的挂在操作,接下来就可以直接在/tmp/mnt/sbull目录里面操作了

posted @ 2016-03-31 10:36  夕相待  阅读(1236)  评论(0编辑  收藏  举报