linux下sd卡的操作(fdisk)


當你拿到一張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的修改了。這就是一天,沒腦子的人。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM