linux下sd卡的操作(fdisk) 您所在的位置:网站首页 彻底删除sd卡内容 linux下sd卡的操作(fdisk)

linux下sd卡的操作(fdisk)

2023-08-19 00:28| 来源: 网络整理| 查看: 265

当你拿到一张sd卡,需要在linux环境下格式化、分区,修改参数的时候,请看过来。

ubuntu虚拟机环境下

1,插入,用力点,因为有可能接触不良,导致电脑不识别。

2,cat /proc/partions 或者fdisk -l    (有些可能需要进入获得管理员权限,deei~命令前+sudo就行)

  比如:cat /proc/partitions   major minor  #blocks  name

     2        0          4 fd0     8        0  167772160 sda     8        1  163576832 sda1     8        2          1 sda2     8        5    4192257 sda5     8       16  167772160 sdb     8       17  167771136 sdb1    11        0    1048575 sr0     8       32    7761920 sdc     8       33    7237664 sdc1

  可知我的sd卡被挂载到/dev/sdc----->它有1个分区sdc1.

3,输入sudo fdisk /dev/sdc

  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)

  好咧,这些命令简单,解释清楚。让我们来给sd卡分区吧。

  Command (m for help):d   //如果只有一个分区直接删除,如果多个分区,会出现个数字,自己选要删除的分区

  Command (m for help):n   //添加新分区

  Partition type:     p   primary (2 primary, 0 extended, 2 free)        e   extended

  Command (m for help):p   //一般选p

  Partition number (1-4, default 1): 1  //默认从第一个分区开始添加  First sector (2048-15523839, default 2048):  //这就是内存从什么地方开始分,比如8G内存,一共会有11523839个sector,从2048开始,那就是留出了2048*512=1M。这个是sd卡保存信息用的。

  Last sector, +sectors or +size{K,M,G} (2048-15523839, default 15523839): +3G   //我分配了3G大小,如果你只想分一个区,ok,直接回车,那就是分了8G-1M给第一个分区了。

  Command (m for help):t  //给分区选一个格式,是linux还是FAT32

  Selected partition 1  //选择第一个分区,设定格式  Hex code (type L to list codes): l  //显示可以设定的格式  很多这里不列 比如:FAT32-->b  Linux-->83

  Hex code (type L to list codes): b   //做FAT32

  

  Command (m for help): n    //接着分个linux系统的分区  Partition type:     p   primary (1 primary, 0 extended, 3 free)     e   extended  Select (default p): p  Partition number (1-4, default 2):   Using default value 2  First sector (6293504-15523839, default 6293504):   Using default value 6293504  Last sector, +sectors or +size{K,M,G} (6293504-15523839, default 15523839):     //大小都是直接回车,把剩余的都给linux分区   Using default value 15523839

  Command (m for help): t  Partition number (1-4): 2  Hex code (type L to list codes): 83   //这就是linux的设置

  Command (m for help): p    //ok,结束了,打印出来看看吧

  Disk /dev/sdc: 7948 MB, 7948206080 bytes  4 heads, 16 sectors/track, 242560 cylinders, total 15523840 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/sdc1            2048     6293503     3145728    b  W95 FAT32   //WINDOWS   /dev/sdc2         6293504    15523839     4615168   83  Linux  //LINUX

  Command (m for help): w    //好的,将其保存  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  WARNING: If you have created or modified any DOS 6.x  partitions, please see the fdisk manual page for additional  information.

  ok,基本上、、、、艾玛,不对,还没格式化呢。

  继续:

  sudo mkdosfs /dev/sdc1  //格式化FAT32

  sudo mkfs.ext3 /dev/sdc2   //格式化Linux

  OK,到此分区和格式化结束,可以根据自己需要,分一个还是两个,这里把分在window下和linux下的都说到了,大小这些也是根据自己的需要来。

  这时,如果将sd卡插在windows环境下,只会弹出一个移动设备,就是分的FAT32的那个的大小,在虚拟机上,则两个都会弹出来。

 

  这里再来个补充的操作:哥们我就死在这一天,我觉得我魔障了~一个问题搞不清楚,自己死都过不去,老是想着,影响工作,影响心情,这是为什么呢?艹,没脑子呗~~

说说我的情况,其实理解了sd卡分区的东西,根本也没必要这么纠结,能用就行,但是我就是魔障了~死脑子了~我非要将自己的sd卡的heads sectors cylinders弄得跟开发板上的卡一样,于是乎,sb被困了一天,工作没效率就是这个sb样。

  如何修改heads sectors这些呢。看到刚才fdisk的最后一个命令解释:x (expert only),好吧,sb也想当专家,尼玛,其实很简单。

  

  Command (m for help): d  //删掉所有分区

  Command (m for help):x  //进入编辑  

  Expert command (m for help): h  //可以键入m,看相关的命令,h表示heads  Number of heads (1-256, default 245): 4  //改为4个

  Expert command (m for help): s  //sectors  Number of sectors (1-63, default 62): 16

  Expert command (m for help): c  //cylinders  这几个数要注意,最终要相乘起来等于sd卡的容量,不然就浪费了,这个可以自己算算。  Number of cylinders (1-1048576, default 1021): 242560

  Expert command (m for help): r  //返回主菜单继续分区工作。

  那么简单的操作,我死在什么地方呢????就在这!!!我一心以为该了就ok了,确实,改完后,p一下是改了,但是w保存退出后,再次进入压根就没有保存。原因可能是,这样修改,不能触及到它的分区表吧,不知道对不对。只要回来接着分区的工作,后面再保存,就可以实现h s c的修改了。这就是一天,没脑子的人。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有