前言

在学习 ARM S5PV210 开发板的时候, SD 卡烧录时总是失败,报错信息:

dev/sdb is NOT identified.

经过实践,发现格式化 SD 卡可以解决该问题;或者使用命令 ls /dev/sdb 发现 sdb 块设备的文件类型不是 b(块设备),此时 rm -rf /dev/sdb 删除,然后重新插入 SD 卡,也能解决问题。


一、准备工作

1. 转换成 root 身份:

ubuntu:~$ sudo su
# 之后输入 root 用户密码
# 如果没有 root 用户/密码,可以使用下面的命令添加 root 用户/密码
ubuntu:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
ubuntu:~$

2. 查看当前系统的磁盘数据

root@ubuntu:/home# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x000e00c0Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    33554431    16776192   83  Linux
/dev/sda2        33556478    41940991     4192257    5  Extended
/dev/sda5        33556480    41940991     4192256   82  Linux swap / Solaris
root@ubuntu:/home#

一般的,sda 盘就是 Linux 操作系统文件所在的那个盘。

我们可以验证下,sda 一个扇区是 512 bytes,总共 41943040 sectors 扇区,因此 sda 硬盘的总空间就是: 512 x 41943040 = 21,474,836,480 bytes,刚好和 fdisk -l 命令统计的数据一样。

底部的 device 信息详解:

  • /dev/sda :第 a 块硬盘。
  • /dev/sda1 :第 a 块硬盘设备的第 1 个分区。
  • Boot:是不是启动分区。
  • Start:起始的扇区号。
  • End:最终的扇区号。
  • ID:分区类型的编号(83 对应 Linux)。
  • System:分区类型编号对应的文字描述。

3. 关闭虚拟机,在虚拟机控制台增加一个硬盘。


4. 重启虚拟机,再利用 fdisk -l 命令观察数据变化。


二、MBR 分区

1. 为了消除 “Disk /dev/sdb doesn’t contain a valid partition table” 的警告,我们需要为 /dev/sdb 硬盘创建一个分区表。

将 /dev/sdb 硬盘设置为 MBR 分区(disklable type),并创建一个分区。


2. 使用 fdisk /dev/sdb 命令,对该硬盘做操作;输入 “m” 可以看到命令帮助信息。

输入"l" 列出支持的分区类型。

输入 “p”, 打印当前已有的分区表。


输入 “n”,新建一个分区。


最后输入 “w”,保存信息到硬盘。


以后输入 fdisk -l 命令,就没有那个 “Disk /dev/sdb doesn’t contain a valid partition table” 的警告了。


3. 为了系统地分析硬盘分区表,我们重新对 /dev/sdb 硬盘重新新建一个分区。

分区的起始扇区号为 2048,前面 0 ~ 2047 扇区为保留扇区,第 0 号扇区为 MBR。

先输入 w,保存我们设置的硬盘分区信息。


观察 /dev/sdb 是否符合 MBR 的特征:主引导记录(MBR)是硬盘驱动器上的第一个扇区,MBR 包含引导程序代码(440字节),可能还包含其他一些信息,紧接着是 64 字节的分区表和一个 2 字节的引导签名。64 字节的分区表有 4 个 16 字节的条目,从偏移量(446,即 1BEh )开始。下表给出了每个 16 字节条目的布局。

偏移量(十六进制) 长度 描述
0h 1 状态。80h表示活动(或可引导)的分区。
1h 3 分区中第一个绝对扇区的CHS(柱面-磁头-扇区)地址
4h 1 分区类型。
5h 3 分区中最后一个绝对扇区的CHS(柱面-磁头-扇区)地址
8h 4 分区中第一个绝对扇区的逻辑块地址(LBA)。
Ch 4 分区中的扇区数量
root@ubuntu:/home/aston# # 通过下面的命令,将MBR以16进制形式打印出来
root@ubuntu:/home/aston# dd if=/dev/sdb bs=512 count=1 2>/dev/null | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  2a dd 85 80 00 00 00 3a  |........*......:|
000001c0  13 00 83 40 52 be 00 08  00 00 00 f8 7f 00 00 00  |...@R...........|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
root@ubuntu:/home/aston#


为什么我们在新建分区的时候,最多只能选择 1~4分区?原因就是一个分区表 16 字节,在第 0 扇区总共只有 64 字节的分区表,所以只能有 4 个分区。





使用下面的命令,只显示 64 字节的分区表信息:

由于只有1个扇区,所以除了第一行 16 字节,其他都是 0。


三、GPT 分区

1.


2.

扇区按 LBA 模式编排,第 0 号扇区存放一个叫 Protective MBR 的数据结构,是为了兼容 MBR 分区,里面的分区类型为 0xEE,不支持 GPT 的系统读到这个标志就会报错。


3.

每个分区信息占用 128 字节,因此 1 个扇区可以存放 4 个分区信息,从 2~33号扇区都是存放分区信息的,故 GPT 可以支持最大 128 个分区。


4.

扇区号使用 8 字节进行编制,因此每个分区最大支持容量为:2^64 * 512 bytes = 8 Zbytes。(注:TB->PB->ZB->YB->BB->NB->DB)


5.

实践演练。

输入 fdisk /dev/sdb ,对 sdb 硬盘做改动。

输入 g, 表示创建 GPT 分区。


这里 sdb 硬盘是 4G大小,我将该硬盘分为两部分,每部分都是 2 G。


现在,我改变第 2 个分区为 Windows 类型分区。

查找分区类型的编码,选择 11 类型的分区。


最后,打印分区信息,并写入到硬盘。


四、格式化

1. 任务:构建文件系统(高级格式化)

2. 命令 mkfs

当前 sdb 硬盘有两个分区,sdb1 和 sdb2。mkfs 命令支持多种文件系统的创建。



五、挂载

1. 目的:为了让分区可用

2. 命令: mount

一般挂载的地方有两个,一个是 /mnt 下,另一个是 /media 下。

root@backvm-virtual-machine:backvm# ls /mnt/
hgfs
root@backvm-virtual-machine:backvm# ls /media/
backvm  guest-ana787  guest-mpypdy  guest-x8d6jn  root
root@backvm-virtual-machine:backvm#


3. 分区挂载情况

命令: lsblk -f



可以看到,挂载后的分区能够正常使用了。


六、 Linux 文件系统

1. 树型目录结构


2. 文件占用空间的大小

疑问:text 文件大小只有 12 字节,但是却占用了 4k 字节的磁盘空间。

Cluster:簇。文件系统是以簇为单位进行空间分配的。簇的大小是可以调节的。


3. 查看文件的目录项

root@backvm-virtual-machine:linux# stat text 文件:'text'
#  实际大小       占用的扇区数量    簇的大小  大小:12         块:8          IO 块:4096   普通文件
#                Inode 编号         链接数
设备:811h/2065d     Inode:12          硬链接:1
#                       用户编号                 组编号
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2023-03-27 00:56:52.096207237 +0800
最近更改:2023-03-27 00:19:35.808679449 +0800
最近改动:2023-03-27 00:19:35.808679449 +0800
创建时间:-


4. 使用 debugfs 观察文件的扇区内容。

root@backvm-virtual-machine:linux# debugfs /dev/sdb1
debugfs 1.42.13 (17-May-2015)
debugfs:  help
Available debugfs requests:show_debugfs_params, paramsShow debugfs parameters
open_filesys, open       Open a filesystem
close_filesys, close     Close the filesystem
freefrag, e2freefrag     Report free space fragmentation
feature, features        Set/print superblock features
dirty_filesys, dirty     Mark the filesystem as dirty
init_filesys             Initialize a filesystem (DESTROYS DATA)
show_super_stats, stats  Show superblock statistics
ncheck                   Do inode->name translation
icheck                   Do block->inode translation
change_root_directory, chrootChange root directory
change_working_directory, cdChange working directory
list_directory, ls       List directory
show_inode_info, stat    Show inode information
dump_extents, extents, exDump extents information
blocks                   Dump blocks used by an inode
filefrag                 Report fragmentation information for an inode
link, ln                 Create directory link
unlink                   Delete a directory link
mkdir                    Create a directory
rmdir                    Remove a directory
rm                       Remove a file (unlink and kill_file, if appropriate)
kill_file                Deallocate an inode and its blocks
clri                     Clear an inode's contents
freei                    Clear an inode's in-use flag
seti                     Set an inode's in-use flag
testi                    Test an inode's in-use flag
freeb                    Clear a block's in-use flag
setb                     Set a block's in-use flag
testb                    Test a block's in-use flag
modify_inode, mi         Modify an inode by structure
find_free_block, ffb     Find free block(s)
find_free_inode, ffi     Find free inode(s)
print_working_directory, pwdPrint current working directory
expand_dir, expand       Expand directory
mknod                    Create a special file
list_deleted_inodes, lsdelList deleted inodes
undelete, undel          Undelete file
write                    Copy a file from your native filesystem
dump_inode, dump         Dump an inode out to a file
cat                      Dump an inode out to stdout
lcd                      Change the current directory on your native filesystem
rdump                    Recursively dump a directory to the native filesystem
set_super_value, ssv     Set superblock value
set_inode_field, sif     Set inode field
set_block_group, set_bg  Set block group descriptor field
logdump                  Dump the contents of the journal
htree_dump, htree        Dump a hash-indexed directory
dx_hash, hash            Calculate the directory hash of a filename
dirsearch                Search a directory for a particular filename
bmap                     Calculate the logical->physical block mapping for an inode
punch, truncate          Punch (or truncate) blocks from an inode by deallocating them
symlink                  Create a symbolic link
imap                     Calculate the location of an inode
dump_unused              Dump unused blocks
set_current_time         Set current time to use when setting filesystem fields
supported_features       Print features supported by this version of e2fsprogs
dump_mmp                 Dump MMP information
set_mmp_value, smmp      Set MMP value
extent_open, eo          Open inode for extent manipulation
zap_block, zap           Zap block: fill with 0, pattern, flip bits etc.
block_dump, bdump, bd    Dump contents of a block
list_quota, lq           List quota
get_quota, gq            Get quota
inode_dump, idump, id    Dump the inode structure in hex
help                     Display info on command or topic.
list_requests, lr, ?     List available commands.
quit, q                  Leave the subsystem.
debugfs:
debugfs:
debugfs:



Linux 格式化磁盘,制作文件系统 => 报错: dev/sdb is NOT identified.相关推荐

  1. 解决只读模式U盘保护格式化或者dd写报错:ERROR: failed to open ‘/dev/sdb‘ in read-write mode: Read-only file system.

    解决只读模式U盘保护格式化或者dd写报错:ERROR: failed to open '/dev/sdb' in read-write mode: Read-only file system. 或者: ...

  2. linux管理磁盘和文件系统

    linux管理磁盘和文件系统 >管理磁盘及分区     在linux的服务器中,当现有硬盘的分区规划不能满足要求时,就需要对硬盘中的分区进行重新规划和调整,有时候还需要添加新的硬盘设备来扩展存储 ...

  3. Linux 格式化磁盘命令mkfs

    linux格式化磁盘命令        mkfs 指令:mkfs 使用权限 : 超级使用者 使用方式 : mkfs [-V] [-t fstype] [fs-options] filesys [blo ...

  4. linux格式化磁盘命令(磁盘分区及格式化)

    Ubuntu下挂载一个新硬盘的基本步骤是: 给硬盘创建分区; 给硬盘创建文件系统; 挂载移动硬盘. 需要用到的命令: lsblk #查看所有硬盘情况 df -lh #查看硬盘占用情况,以及挂载位置 s ...

  5. linux格式化磁盘命令

    转载地址:http://blog.sina.com.cn/s/blog_6fe60daa0101418c.html linux格式化磁盘命令        linux mkfs        指令:m ...

  6. Linux格式化磁盘-自动化脚本执行

    Linux格式化磁盘-自动化脚本执行 脚本内容 脚本内容 #!/bin/bashdevs=`fdisk -l|grep '/dev/sd'|grep -v '/dev/sda'|awk '{split ...

  7. linux下unzip解压报错“symlink error: File name too long”怎么办?提供解决方案。

    点击上方↑↑↑蓝字[协议分析与还原]关注我们 " 分享unzip工具的一个bug." 最近在研究菠菜站,中间用到了Spidermonkey,碰到一些小波折,在这里分享出来,以便大家 ...

  8. linux下编译make文件报错“/bin/bash^M: 坏的解释器,使用grep快速定位代码位置

    一.linux下编译make文件报错"/bin/bash^M: 坏的解释器 参考文章:http://blog.csdn.net/liuqiyao_01/article/details/415 ...

  9. Linux中使用gcp拷贝报错:dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported:

    1 在linux中使用gcp拷贝的时候报错 Linux中使用gcp拷贝报错:dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotS ...

最新文章

  1. Vivado各个过程产生的文件与ISE的对比
  2. 项目经理面试中可能遇到的问题
  3. SpringBoot高级-任务-邮件任务
  4. 修正discuz发帖首次换行无效的问题
  5. C语言,C#语言求100-999内的水仙花数源程序
  6. 配置oracle网络连接命令,配置oracle网络环境
  7. Linux tee的花式用法和pee
  8. linux date输出到文件,Linux常用命令--ls、cd、date用法
  9. 华为root工具_华为手机EMUI9 ROOT通用操作方法
  10. 简述什么是图灵机_什么是图灵机
  11. 【转】测试用例设计——WEB通用测试用例
  12. 浙江大学黄杨思博计算机学院,浙江大学节能减排社会实践与科技竞赛成功-浙江大学本科生院.DOC...
  13. 软件可靠性测试意义,软件可靠性测试方法与目的
  14. SPA的原理及其实现
  15. java抖音字符视频_代码生成抖音文字视频
  16. 利用sqlmap注入获取网址管理员账号密码
  17. 极限中0除以常数_第六讲 极限的运算法则
  18. linux搭建wordpress运行环境,Centos 6.x配置基于nginx的wordpress运行环境 | 旺旺知识库...
  19. 基于Sip的P2P设计和原理分析
  20. C语言递归及经典例题详解

热门文章

  1. unity 导出的项目导入androidstudio 老报indexoutofrange的错的问题
  2. Nginx正向代理和反向代理配置 1
  3. 索尼EX280摄像机MP4损坏修复4音轨还原内录声音
  4. 公钥加密,私钥解密;私钥签名,公钥验签
  5. 关于如何计算地址线和数据线问题
  6. PHP处理苹果APP内购后到服务端的二次验证(项目经验)
  7. 杨老师教你学会使用富文本编辑器KindEditor之添加页面设计
  8. 带栩字的优美古诗句_栩开头的句子(有关"栩"字的名诗名句)
  9. 鸿蒙 手机 发布时间 2021,2021下半年新机发布时间表_2021下半年新机发布日期
  10. asp php微信支付,Asp微信支付接口代码 微信中生成订单后可以直接调出微信钱包直接付款_随便下源码网...