linux下對SD卡分區

來源:互聯網
上載者:User

最近做機頂盒GUI開發需要將SD卡分成若干個分區,現將如何分區總結如下

一 使用linux下的磁碟管理工具fdisk

sudo fdisk /dev/sdc

使用fdisk開啟你的SD卡裝置名稱,我的sd卡裝置名稱是sdc

二進入fdisk管理工具

開啟後進入如下介面

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)

Command (m for help):

我們只需要使用到fdisk的的幾個主要命令

m:使用協助

n: 建立一個分區

d: 刪除一個分區

p:列印分區資訊

t:修改分區ID,通過修改ID我們可以改變分區格式,例如windows的fat32格式id為6和linux下ext3格式id為83

w:儲存分區資訊並退出

 

三:建立分區

1,列印顯示已有分區

輸入p

Command (m for help): p

Disk /dev/sdc: 1967 MB, 1967128576 bytes

57 heads, 56 sectors/track, 1203 cylinders

Units = cylinders of 3192 * 512 = 1634304 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               1          23       36680   83  Linux

/dev/sdc2              24          34       17556   83  Linux

 

2,刪除已有分區

輸入d之後選擇分區編號

Command (m for help): d

Partition number (1-4): 1

Command (m for help): d

Selected partition 2

 

3,建立分區

3.1建立主要磁碟分割

輸入n

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-1203, default 1): 1

Last cylinder, +cylinders or +size{K,M,G} (1-1203, default 1203): 23

輸入n後選擇p建立一個主要磁碟分割,選擇分區編號為1,分區起始柱面位置(first cylinder)選擇1,末端位置(last cylinder)選擇23

 

3.2建立擴充分區

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

e

Partition number (1-4): 2

First cylinder (24-1203, default 24):

Using default value 24

Last cylinder, +cylinders or +size{K,M,G} (24-1203, default 1203):

Using default value 1203

輸入n後選擇e建立一個擴充分區,選擇編號2,起始位置和末端選擇預設的24~1023

 

3.3建立邏輯分區

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (24-1203, default 24):

Using default value 24

Last cylinder, +cylinders or +size{K,M,G} (24-1203, default 1203): 43

輸入n後選擇l建立一個邏輯分區,選選擇起始和末端位置為24~43

 

建立第二個邏輯分區

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (44-1203, default 44):

Using default value 44

Last cylinder, +cylinders or +size{K,M,G} (44-1203, default 1203):

Using default value 1203

 

三修改分區ID

輸入t

Command (m for help): t

Partition number (1-6): 1

Hex code (type L to list codes): 6

Changed system type of partition 1 to 6 (FAT16)

選擇編號為1的分區,這裡我將id設為6(FAT16格式,ext32格式的id為83)

同理修改其他分區的id

 

四,儲存退出

Command (m for help): p

Disk /dev/sdb: 1967 MB, 1967128576 bytes

57 heads, 56 sectors/track, 1203 cylinders

Units = cylinders of 3192 * 512 = 1634304 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               1          23       36680    6  FAT16

/dev/sdb2              24        1203     1883280    5  Extended

/dev/sdb5              24          43       31892   83  Linux

/dev/sdb6              44        1203     1851332   83  Linux

這裡可以看見我剛剛建立的分區

輸入w

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 裝置或資源忙.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

WARNING: If you have created or modified any DOS 6.x

partitions, please see the fdisk manual page for additional

information.

Syncing disks.

儲存退出,之前我以為到這一步就完事來,其實不然還有下面的

 

四:格式化分區

在第三步之後你會發現你的sd卡絲毫反應,這是因為第三步僅僅是寫入分區表資訊而沒有完成格式化

FAT格式分區格式化命令 mkfs.vfat /dev/sdb1

ext3格式分區的格式化命令 mkfs.ext3 /dev/sdb5

這裡要注意,如果你緊接著就使用這兩個命令進行格式化會提示

yang@yang-pc:~$ sudo mkfs.ext3 /dev/sdb3

mke2fs 1.41.12 (17-May-2010)

無法對 /dev/sdb3 進行 stat 調用 --- 沒有那個檔案或目錄

這是因為我們寫進去的分區表還未生效,把SD卡取下,再插入就OK了,這下你可以在/dev/sd*看到你建立的分區

然後使用格式化命令分區格式化對應格式的分區,如果你SD卡原先有東西,再格式化後面加 -I 參數,覆蓋掉裡面的內容

 

五,修改分區名字

在第四步完成之後就可以看見我們剛在建立的分區被自動掛載到/media/下了。可是這些分區的名字還是一串難看的字元

因此們需要修改分區的名字也就是Label

修改ext3格式的label命令 e2label /dev/sdb labelname

修改fat格式的我目前還未找到好的方法,只能在windows下重名的方法解決

 

ps:如有疑問,可以給我留言,如有哪位仁兄找到更好的方法命名FAT格式分區名字,希望告知,感激不盡

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.