将sdcard插在读卡器中并插入工作电脑中,执行:
[lidq@localhost ~] ls /dev
sda
sda1
sda2
sda3
sda4
sdb
sdb1
sdb2
其中sdX表示你电脑上的大容量存储设备:sda表示第一个存储设备(硬盘);sdb表示第二块存储设备(sdcard)。
其中sdXN中的N表示这个存储设备的分区号:sda1表示第一个存储设备的第一个分区;sda2表示第一个存储设备的第二个分区;sda3表示第一个存储设备的第三个分区;sdb1表示第二个存储设备的第一个分区;sdb2表示第二个存储设备的第二个分区。
我们需要确定sdcard这个设备的设备名称是哪一个(在这里是sdb也有可能是sdc或sdd等),然后对这个sdcard进行分区,我们需要对其划分3个区:
sdb1:启动分区
sdb2:交换分区
sdb3:系统根分区
[lidq@localhost ~] sudo fdisk /dev/sdb
在fdisk命令中可以使用m显示帮助提示。
首先输入p显示目前此存储设备现有的分区:
Command (m for help): p
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 8390655 8388608 4G 83 Linux
/dev/sdb2 8390656 16777215 8386560 4G 83 Linux
可以看到这个sdcar上本来具有两个分区,我们需要输入d命令,并按提示将这两个分区全部删除:
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
然后创建sdb1、sdb2、sdb3三个分区,执行n命令创建一个新分区设定其大小为512MB:
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215): +512M
Created a new partition 1 of type 'Linux' and of size 512 MiB.
再次执行n命令创建一个新分区设定其大小为2GB:
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (1050624-16777215, default 1050624):
Last sector, +sectors or +size{K,M,G,T,P} (1050624-16777215, default 16777215): +2G
Created a new partition 2 of type 'Linux' and of size 2 GiB.
再次执行n命令创建一个新分区,将sdcard中剩余大小全部分配给此分区:
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (5244928-16777215, default 5244928):
Last sector, +sectors or +size{K,M,G,T,P} (5244928-16777215, default 16777215):
Created a new partition 3 of type 'Linux' and of size 5.5 GiB.
接下来执行p命令,查看我们已经创建好的新分区:
Command (m for help): p
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1050623 1048576 512M 83 Linux
/dev/sdb2 1050624 5244927 4194304 2G 83 Linux
/dev/sdb3 5244928 16777215 11532288 5.5G 83 Linux
执行t命令将sdb1分区的类型修改为b (WIN95 FAT32):
Command (m for help): t
Partition number (1-3, default 3): 1
Partition type (type L to list all types): b
Changed type of partition 'Linux' to 'W95 FAT32'.
执行t命令将sdb2分区的类型修改为82 (Linux swap / Solaris):
Command (m for help): t
Partition number (1-3, default 3): 2
Partition type (type L to list all types): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.
执行t命令将sdb3分区的类型修改为83 (Linux),由于我们的sdb3分区类型已经是Linux了所以无需再做额外修改。
执行a命令将sdb1分区的boot选项设置为* :
Command (m for help): a
Partition number (1-3, default 3): 1
The bootable flag on partition 1 is enabled now.
再次使用p命令查看分区信息:
Command (m for help): p
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 1050623 1048576 512M b W95 FAT32
/dev/sdb2 1050624 5244927 4194304 2G 82 Linux swap / Solaris
/dev/sdb3 5244928 16777215 11532288 5.5G 83 Linux
可以看到我们的sdcard已经被修改为3个分区分别是sdb1、sdb2、sdb3,其中sdb1是启动分区;sdb2是交换分区、sdb3是系统根分区。
最后执行w命令写入所有执行结果,即确定对存储设备做分区修改,执行成功后自动退出fdisk命令并返回命令行界面:
Command (m for help): w
The partition table has been altered.
Syncing disks.
[lidq@localhost ~]
接下我们还需使用mkfs.vfat和mkfs.ext4两个命令对sdb1和sdb3两个分区进行格式化操作(sdb2是swap分区不需要格式化):
[lidq@localhost ~]$ sudo mkfs.vfat /dev/sdb1
mkfs.fat 4.0 (2016-05-06)
[lidq@localhost ~]$ sudo mkfs.ext4 /dev/sdb3
mke2fs 1.43.1 (08-Jun-2016)
Creating filesystem with 1441536 4k blocks and 360448 inodes
Filesystem UUID: d05d026a-6177-4a7c-892a-a4a970cd155b
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
到此为止我们的sdcard的分区工作完成了。
Copyright © 2015-2023 问渠网 辽ICP备15013245号