6.format
前言
在使用樹莓派利用SD卡啟動系統的過程中,如何配置一張新買的空SD卡也是一個必不可少的技能。本文主要是介紹如何將SD卡分成boot和root兩個分區,操作流程主要分為分區、格式化兩步
操作流程
分區
查看插入的SD卡情況,可以看出目前插入了一張32G(29G)的SD卡,系統分配給其的名字是/dev/sdb,目前存在1個分區,名字分別為/dev/sdb1,格式是W95 FAT32 (LBA)
hsq@ares:~$ sudo fdisk -l Disk /dev/sdb: 29 GiB, 31104958464 bytes, 60751872 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 Disklabel type: dos Disk identifier: 0x9c2d2e7a Device Boot Start End Sectors Size Id Type /dev/sdb1 * 8192 60751871 60743680 29G c W95 FAT32 (LBA)
1
2
3
4
5
6
7
8
9
10
操作分區信息前先卸載掉系統對SD卡的自動掛載
hsq@ares:~$ umount /media/hsq/kingston
然後利用fdisk命令進行分區操作
hsq@ares:~$ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p #这里也可以查看SD卡分区情况 Disk /dev/sdb: 29 GiB, 31104958464 bytes, 60751872 sectors Units: sectors of 1 * 512 = 512 bytes #默认每个扇区0.5KB Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x9c2d2e7a Device Boot Start End Sectors Size Id Type /dev/sdb1 * 8192 60751871 60743680 29G c W95 FAT32 (LBA) Command (m for help): d#删除当前的分区,有几个分区就要运行几次d Selected partition 1 Partition 1 has been deleted. Command (m for help): n #创建一个新的分区作为boot分区 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): #一般用默认的主分区即可 Using default response p. Partition number (1-4, default 1): #分区号默认按序即可 First sector (2048-60751871, default 2048): #起始扇区序号默认即可 Last sector, +sectors or +size{K,M,G,T,P} (2048-60751871, default 60751871): 205824 #终止扇区序号,2000个扇区是1MB,这里与初始扇区差值约为100MB Created a new partition 1 of type 'Linux' and of size 99.5 MiB. Command (m for help): t #改变分区类型 Partition type (type L to list all types): L #打印所有的支持类型,很长这里省略 ······ ······ ······ Partition type (type L to list all types): c #选择类型c,即W95 FAT32 (LBA)作为boot类型 Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'. Command (m for help): n #再创建一个分区作为root分区 Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): #默认 Using default response p. Partition number (2-4, default 2): #默认 First sector (205825-60751871, default 206848): #默认 Last sector, +sectors or +size{K,M,G,T,P} (206848-60751871, default 60751871): #默认把剩下所有的空间都分配给root Created a new partition 2 of type 'Linux' and of size 28.9 GiB. Command (m for help): p #查看一下重新分区后的信息 Disk /dev/sdb: 29 GiB, 31104958464 bytes, 60751872 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 Disklabel type: dos Disk identifier: 0x9c2d2e7a Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 205824 203777 99.5M c W95 FAT32 (LBA) /dev/sdb2 206848 60751871 60545024 28.9G 83 Linux Command (m for help): w #保存分区信息,注意需要之前卸载掉系统对SD卡的自动挂载,否则这里会有一个警告 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
格式化
分區後還要對SD卡的各個分區進行格式化和重命名
hsq@ares:~$ sudo mkfs.msdos /dev/sdb1 -n boot #将第一个分区sdb1格式化为fat类型,并重命名为boot mkfs.fat 3.0.28 (2015-05-16) mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows hsq@ares:~$ sudo mkfs.ext4 /dev/sdb2 -L root #将第二个分区sdb2格式化为ext4类型,并重命名为root mke2fs 1.42.13 (17-May-2015) Creating filesystem with 7568128 4k blocks and 1892352 inodes Filesystem UUID: 9702d479-9bc1-4c72-9398-70d018b9fbd5 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
問題解決
問題:用fdisk命令分區結束後w保存時出現警告
錯誤提示:Re-reading the partition table failed.:Device or resource busy
原因分析:因為用fdisk命令前沒有卸載系統自動掛載的SD
解決:umount /media /hsq/kingston
問題:掛載分區雖然成功但是有報警告
錯誤提示:Volume was not properly unmounted
原因分析:多次意外掉電造成的。據說可以把分區文件夾的權限設置為只讀而避免這個問題,沒驗證過
解決:在ubuntu主機上用以下命令修復。參考
fsck.fat -V /dev/mmcblk0p1
問題:
錯誤提示:
原因分析:
解決:
1