在ubuntu14.04系统下对SD卡进行分区分为3步:
注意:进行SD卡分区时,用户操作权限为root权限!
(1) umount SD卡
查看SD卡挂载目录,一般在/media目录下:
sudo mount
操作结果如下:
/dev/sdb on /media/marvin/H type vfat (rw,nosuid,nodev,uid=1000,gid=1000,
shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)
H为SD卡卷符,在分区之前先umount SD 卡。
sudo umount /dev/sdb
(2)创建分区
为了不用每次都输入sudo,直接将权限切换为root权限:
sudo -i
格式化sd 卡,如下:
fdisk /dev/sdb
此操作后,终端会出现如下提示,输入m查看各个操作选项:
root@acer-Aspire-4741:~# fdisk /dev/sdb
Command (m for help): p
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)
Device Boot Start End Blocks Id System
分区之前,先查看原有分区,操作选项为p,操作结果如下:
Command (m for help): p
Disk /dev/sdb: 31.9 GB, 31914983424 bytes
64 heads, 32 sectors/track, 30436 cylinders, total 62333952 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
本次操作原来是没有分区的。如果有分区,d选项表示删除分区,n表示新建分区,t表示设置分区类型,w表示将分区信息写入SD卡并退出分区菜单。这几个选项是比较常用的。下面为操作过程:
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62333951, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G}
(2048-62333951, default 62333951): +512M
该段操作为新建一分区,分区类型为主分区且为第一分区(默认4个分区),分区大小为512M。Last sector 行”+512M”表示分区为512M.
下面对分区进行格式化:
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
操作选项t表示格式化类型,Hex code:L表示显示所有可以格式化的所有格式。现将新建分区格式成FAT16格式:
Hex code (type L to list codes): 6
Changed system type of partition 1 to 6 (FAT16)
此处表示将第一分区格式化为FAT16格式,如果新建分区有多个,则可以选择相应的分区进行格式化。
再新建ext的格式,步骤和新建FAT16格式相同:
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (1050624-62333951, default 1050624):
Using default value 1050624
Last sector, +sectors or +size{K,M,G} (1050624-62333951, default 62333951):
Using default value 62333951
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 83
此处格式选项Hex code为83,为linux格式,分区号为2.
接着,将格式化信息写入SD卡,
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.
Syncing disks.
此时选择p选项查看分区,结果如下:
Command (m for help): p
Disk /dev/sdb: 31.9 GB, 31914983424 bytes
64 heads, 32 sectors/track, 30436 cylinders, total 62333952 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 1050623 524288 6 FAT16
/dev/sdb2 1050624 62333951 30641664 83 Linux
注:实验中SD卡为32G.其中FAT16分区为512M,其余为linux分区。
(3)利用格式化命令对分区进行格式化
root@acer-Aspire-4741:~# mkfs.vfat -F 16 /dev/sdb1 -n I
mkfs.fat 3.0.26 (2014-03-07)
root@acer-Aspire-4741:~# mkfs.ext3 -L H /dev/sdb2
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=H
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1916928 inodes, 7660416 blocks
383020 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
234 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
至此,SD卡分区已经完成。
补充:以下为参照g446868263的博客所写。因为觉得这篇博客与上面的分区的知识很接近,很值得参考。
注意:所有操作均在root权限下进行,且每次格式化之前需要先umount!
(1)格式化分区:
FAT格式:
#F为FAT格式,F后面的参数可以为12,16,32分别表示
#FAT12,FAT16,FAT32. n后面的参数为卷标。
mkfs.vfat -F 16 /dev/sdb1 -n I
(2)EXT格式:
#格式化ext2,L后参数为卷标
mkfs.ext2 -L H1 /dev/sdb2
#格式化ext3
mkfs.ext3 -L H1 /dev/sdb2
#格式化ext4
mkfs.ext4 -L H1 /dev/sdb2
(3) NTFS格式
格式化为 NTFS 分区,先要安装ntfsprogs
mkfs.ntfs /dev/sdb
由于ext系列的分区都有一个给super user的保留空间,必须占用一定的百分比,默认5%
解决方法:
(1) 针对将要格式化的分区,以ext3为例:
#/dev/sdb为需要格式化的区域
umount /dev/sdb
mkfs.ext3 -m 0.05 /dev/sdb
注意:-m后的参数,设定的已经是百分位,这里设定为0.05,是0.05%,也就是万分之5!
以1T的分区为例,1T=1024GB=1048576MB(都是乘以1024的关系),1048576MB*0.0005=524.288MB。
也就是说设定-m参数之后,保留区大概是524MB。当然可以根据自行设定。
二、对已经格式化完毕的分区,并且不想擦出分区中的数据,可以使用tune2fs -m的方法:
tune2fs -m 0.05 /dev/sda2
super user保留区,设定为0.05,再次提醒一次,是0.05%,也就是万分之5。
参考文章:
[1] http://blog.csdn.net/g446868263/article/details/693777
[2] http://blog.sina.com.cn/s/blog_68e596750100jx9m.html