本文说明利用shell脚本实现linux系统上电自动检测emmc的一种方法。不需要人工去配置emmc,提升工作效率。
该脚本已经在海思平台HI3516CV300验证可行。
#!/bin/sh
#1.Determines whether the /data directory is mounted
echo "Determines whether the /data directory is mounted"
if mountpoint -q /data
then
echo "The /data directory has been mounted,will exit the shell"
exit
else
echo "The /data directory not mounted"
fi
#2.Determine if /dev/mmcblk0p1 exists. If so, try mount it first
echo "Determine if /dev/mmcblk0p1 exists. If so, try mount it first"
if [ -e '/dev/mmcblk0p1' ]
then
echo "/dev/mmcblk0p1 already exist!"
echo "do- mount /dev/mmcblk0p1 /data"
mount /dev/mmcblk0p1 /data
if [ "$?" = 0 ]
then
echo "mount /dev/mmcblk0p1 /data successful!!!"
else
echo "first mount failed,then do- mkfs.vfat -I /dev/mmcblk0p1"
mkfs.vfat -I /dev/mmcblk0p1
echo "do- mount /dev/mmcblk0p1 /data"
mount /dev/mmcblk0p1 /data
fi
exit
fi
#3.Partition the disk at /dev/mmcblk0
echo "Partition the disk at /dev/mmcblk0"
echo "First enter: n"
echo "Second enter: p"
echo "Third enter: 1"
echo "Fourth enter: 1"
echo "Five enter 120832"
echo "Six enter w"
fdisk /dev/mmcblk0 << EOF
n
p
1
1
120832
w
EOF
if [ "$?" = 0 ]
then
if [ -e '/dev/mmcblk0p1' ]
then
echo "/dev/mmcblk0p1 exist!"
else
echo "/dev/mmcblk0p1 not exist!!!"
fi
else
echo "The fdisk command failed"
exit
fi
#4.Format the partition /dev/mmcblk0p1 and mount
echo "Format the partition /dev/mmcblk0p1 and mount"
echo "do-- mkfs.vfat -I /dev/mmcblk0p1"
mkfs.vfat -I /dev/mmcblk0p1
echo "do-- mount /dev/mmcblk0p1 /data"
mount /dev/mmcblk0p1 /data