fdisk命令对mmc分区格式化并shell脚本自动化

1. fdisk /dev/mmcblk0

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): 

2.输入n 增加一个分区,然后输入p,增加一个主要分区:

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p

3. 然后输入1,分区编号为1:

Partition number (1-4, default 1): 1

4.然后根据自己的需要设置开始扇区和结束扇区;

First sector (1-11926, default 2048): 
Using default value 1
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 5000

5. 同样方法然后增加第二个分区:

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): 2

First sector (5001-11926, default 2048):

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 5000

6. 最后输入w 保存退出;

7. 格式化分区:

mkfs.vfat /dev/mmcblk0p1

mkfs.vfat /dev/mmcblk0p2

二、shell自动化脚本

#! /bin/sh

check_emmc()
{
    if [ -e /dev/mmcblk0 ]; then
        return 1
    else
        return 0
    fi
}

do_partition()
{
echo "n
p
1
1
5000
n
p
2


w
" | fdisk /dev/mmcblk0
}

check_partition_and_init()
{
    check_emmc
    if [ $? -eq "1" ]; then
        if [ ! -e /dev/mmcblk0p1 ]; then 
            do_partition
            mkfs.vfat /dev/mmcblk0p1
            mkfs.vfat /dev/mmcblk0p2
            echo "Partitioning and initialization are complete"
        fi
        mount -o ro /dev/mmcblk0p1 /emmc/factory_data/
        mount /dev/mmcblk0p2 /user_data/
        echo "emmc mount complete"
        sync
    else
        echo " emmc faild "
    fi
}

echo " emmc start mount "
check_partition_and_init

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值