linux分区挂载到内存,ubuntu下SD卡分区与挂载

本来只是想借SD卡来做一个OK6410的升级。

但笔记本上只装了ubuntu,一开始是可以识别sd卡的,但按照网上的教程不小心将/dev/sdb1删除了,导致ubuntu不能识别sd卡了。

记录一下解决过程:

1.sd的设备节点/dev/sdb还有,说明驱动没有问题,按照网上执行了这些步骤,但并没有作用

sudo modprobe usb-storage

sudo modprobe sdhci

sudo modprobe mmc_core

sudo modprobe mmc_block

2.这里再说一下我对设备,分区,内核分区表的理解,欢迎拍砖

首先看到的/dev/sdb这个就是sd的设备,是驱动创建的

通过fdisk -l 看到的就是实际的物理分区,可以看到有那些存储设备以及设备上的分区情况

内核分区表是通过获取物理分区生成的,通过df可以看到

比如,我目前的情况是有/dev/sdb,说明驱动没问题设备还是有的,没有/dev/sdb1也就是没有进行分区

/dev/sdb指的是U盘设备,/dev/sdb1指U盘上的第一个分区,这两个都是设备控制节点,可以直接向这两个节点写数据,但应该遵循一些约定(比如用hexedit直接写16进制数)。一般用法是通过控制节点进行挂载,利用文件系统简化过程

通过fdisk -l 可以看到,但是没有分区,感受一下:

kevin@magic:~/tmp$ sudo fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes

255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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: 0x0005d645

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048   620959743   310478848   83  Linux

/dev/sda2       620961790   625141759     2089985    5  Extended

/dev/sda5       620961792   625141759     2089984   82  Linux swap / Solaris

Disk /dev/sdb: 3904 MB, 3904897024 bytes

77 heads, 8 sectors/track, 12381 cylinders, total 7626752 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/sda空间已经用完了,/dev/sdb没有使用。

下面我们对/dev/sdb 进行分区

[root@bogon 桌面]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0xfaa2aa49.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

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)

fdisk选中/dev/sdb 输入m所有基本选项都出现,输入n新建分区

Command (m for help): n

Command action

e  extended

p  primary partition (1-4)

有扩展分区和主分区,逻辑分区在扩展分区中建立。注意到括号中的1-4,最多只能建四个主分区(包括扩展分区)。先建一个主分区:

Command (m for help): n

Command action

e  extended

p  primary partition (1-4)

p #建主分区

Partition number (1-4): 1 #分区号为1

First cylinder (1-2610, default 1): #直接回车默认从第一个柱面开始划分

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G #加空间大小,这里有很多种选择:+后面单位可以接M,G,K(记得要大写)表示划分你所加的空间,也可以是柱面数。不管怎样都不能超过该磁盘剩余的空间否则无效。

Command (m for help): p #分好后查看分区信息,刚所做的所有一目了然。

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0xfaa2aa49

Device Boot      Start        End      Blocks  Id  System

/dev/sdb1              1        262    2104483+  83  Linux

同上所述建立扩展分区,在此简单使用sd,所以就创建了一个主分区

Command (m for help): w #保存退出

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

再次查看就看到了/dev/sdb的分区信息,虽然现在我们看到进行分区了,但是内核kenel还没有识别为了不要重启将分区表写入kenel我们要用到partprobe工具:使kenel重新读取分区表。

kevin@magic:~/tmp$ sudo fdisk -l

Disk /dev/sdb: 3904 MB, 3904897024 bytes

77 heads, 8 sectors/track, 12381 cylinders, total 7626752 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     7626751     3812352   83  Linux

kevin@magic:~/tmp$ sudo partprobe

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙).  As a result, it may not reflect all of your changes until after reboot.

kenel识别分区表后,我们还不能使用它要对其进行格式化。mkfs.加文件系统格式,扩展分区是不能格式化的。

kevin@magic:~/tmp$mkfs.vfat /dev/sdb1 #格式化成fat32文件格式(要分区格式化,不能将整个硬盘格式化)

最后就是挂载了。

mkdir /bak

sudo mount -o loop /dev/sdb1 /bak #挂载该分区到/bak

kevin@magic:~/Documents$ df

Filesystem     1K-blocks     Used Available Use% Mounted on

/dev/sda1      310126448 69465996 225136512  24% /

udev             1020924        4   1020920   1% /dev

tmpfs             411280     1164    410116   1% /run

none                5120        0      5120   0% /run/lock

none             1028192       76   1028116   1% /run/shm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值