linux shell编写镜像制作工具

UCAS_INPUT_KERNEL_PATH=/ucas/input/kernel/
UCAS_INPUT_FS_PATH=/ucas/input/fs/
UCAS_INPUT_BOOTFS_PATH=/ucas/input/efi/
UCAS_INPUT_BOOTFS1_PATH=/ucas/input/grub/
UCAS_TMP=/tmp/rootfs/
UCAS_GRUB=boot/grub/grub.cfg


UCAS_IMAGE_PATH=$2
UCAS_IMAGE_VERSION=$3
UCAS_ENABLE_SUDO=$4


if [ -z "$UCAS_IMAGE_VERSION" ]; then
	echo "please input image version at arg[3]: normal, docker, ...."
	exit 1

elif [ $UCAS_IMAGE_VERSION == "normal" ]; then
	echo "make normal image....."
	UCAS_OUTPUT_KERNEL_PATH=$UCAS_IMAGE_PATH/normal/kernel
	UCAS_OUTPUT_FS_PATH=$UCAS_IMAGE_PATH/normal/fs

elif [ $UCAS_IMAGE_VERSION == "docker" ]; then
	echo "make docker image....."
	UCAS_OUTPUT_KERNEL_PATH=$UCAS_IMAGE_PATH/docker/kernel
        UCAS_OUTPUT_FS_PATH=$UCAS_IMAGE_PATH/docker/fs
else
	echo "version error!"
	exit 1
fi


UCAS_OUTPUT_BOOTFS_PATH=$UCAS_IMAGE_PATH/efi
UCAS_OUTPUT_BOOTFS1_PATH=$UCAS_IMAGE_PATH/grub

if [ $UCAS_ENABLE_SUDO == "--enable_sudo" ]; then
	echo "enable sudo "
	SUDO=sudo
else
	echo "disable sudo"
	SUDO=
fi


DEV_NAME=$1
NVMEFLAG=
index=1

if [ -z "$DEV_NAME" ]; then
	echo "please input devname: eg. ./mkimage.sh /dev/sdb"
	exit 1
	
fi

if [ -z "$UCAS_IMAGE_PATH" ]; then
	echo "please input image path: eg. ./mkimage.sh /dev/sdb /imagepath "
	exit 1
fi	


if [ -z "$UCAS_OUTPUT_KERNEL_PATH" ]; then
	echo "please input kernel path: eg. ./mkimage.sh /dev/sdb"
	exit 1
fi	

if [ -z "$UCAS_OUTPUT_FS_PATH" ]; then
	echo "please input fs path: eg. ./mkimage.sh /dev/sdb"
	exit 1
fi	

if [ -z "$UCAS_OUTPUT_BOOTFS_PATH" ]; then
	echo "please input efi path: eg. ./mkimage.sh /dev/sdb"
	exit 1
fi	

if [ -z "$UCAS_OUTPUT_BOOTFS1_PATH" ]; then
	echo "please input grub path: eg. ./mkimage.sh /dev/sdb"
	exit 1
fi	

echo "[**--------------- begin mkimage ---------------**]"
echo "y" | $SUDO mkfs.ext4 $DEV_NAME &> /dev/null

if [ $? -ne 0 ]; then
	echo "mkfs disk failed"
	exit 1
fi

echo " Make disk partition............"


$SUDO parted $DEV_NAME -s mktable gpt
$SUDO parted $DEV_NAME -s mkpart primary fat16 1M 100M

$SUDO parted $DEV_NAME -s set 1 msftdata on

$SUDO parted $DEV_NAME -s mkpart primary ext4 100M 200M

$SUDO parted $DEV_NAME -s mkpart primary ext4 200M 10G

$SUDO parted $DEV_NAME -s mkpart primary fat16 10G 11G

$SUDO parted $DEV_NAME -s set 4 boot on

$SUDO parted $DEV_NAME -s set 4 esp on


if [ $? -ne 0 ]; then
	echo "fdisk disk failed"
	exit 1
fi

$SUDO mkdir -p $UCAS_INPUT_KERNEL_PATH
if [ $? -ne 0 ]; then
        echo "mkdir kernel folder failed"
        exit 1
fi

$SUDO mkdir -p $UCAS_INPUT_FS_PATH
if [ $? -ne 0 ]; then
        echo "mkdir fs folder failed"
        exit 1
fi

$SUDO mkdir -p $UCAS_INPUT_BOOTFS_PATH
if [ $? -ne 0 ]; then
        echo "mkdir bootfs folder failed"
        exit 1
fi

$SUDO mkdir -p $UCAS_INPUT_BOOTFS1_PATH
if [ $? -ne 0 ]; then
        echo "mkdir bootfs1 folder failed"
        exit 1
fi


echo "format disk partition..................."
partprobe
sync


if [[ $DEV_NAME == *"nvme"* ]]; then
	NVMEFLAG=p
	DEV_NAME=$DEV_NAME$NVMEFLAG
        echo "have nvme"
fi


echo "y" | $SUDO mkfs.vfat -F 16 $DEV_NAME$index #&> /dev/null
if [ $? -ne 0 ]; then
	echo "mkfs.vfat failed1"
	exit 1
fi
$SUDO mount $DEV_NAME$index $UCAS_INPUT_BOOTFS_PATH
if [ $? -ne 0 ]; then
        echo "mount bootfs failed"
        exit 1
fi
let index+=1


echo "y" | $SUDO mkfs.ext4 $DEV_NAME$index &> /dev/null
if [ $? -ne 0 ]; then
        echo "mkfs kernel folder failed"
        exit 1
fi

$SUDO mount $DEV_NAME$index $UCAS_INPUT_KERNEL_PATH
if [ $? -ne 0 ]; then
        echo "mount kernel failed"
        exit 1
fi
let index+=1

echo "y" | $SUDO mkfs.ext4 $DEV_NAME$index &> /dev/null
if [ $? -ne 0 ]; then
        echo "mkfs fs folder failed"
        exit 1
fi

$SUDO mount $DEV_NAME$index $UCAS_INPUT_FS_PATH
if [ $? -ne 0 ]; then
        echo "mount fs failed"
        exit 1
fi
let index+=1

echo "y" | $SUDO mkfs.vfat -F 16  $DEV_NAME$index &> /dev/null
if [ $? -ne 0 ]; then
	echo "mkfs.vfat failed2"
	exit 1
fi

$SUDO mount $DEV_NAME$index $UCAS_INPUT_BOOTFS1_PATH
if [ $? -ne 0 ]; then
        echo "mount bootfs1 failed"
        exit 1
fi


echo "copy fs kernel to disk....................."
$SUDO cp -rf $UCAS_OUTPUT_KERNEL_PATH/* $UCAS_INPUT_KERNEL_PATH
if [ $? -ne 0 ]; then
        echo "cp kernel failed"
        exit 1
fi


$SUDO tar -xvf $UCAS_OUTPUT_FS_PATH/* -C $UCAS_INPUT_FS_PATH &> /dev/null
if [ $? -ne 0 ]; then
        echo "tar tmp  failed"
        exit 1
fi


$SUDO cp -rf $UCAS_OUTPUT_BOOTFS_PATH/*  $UCAS_INPUT_BOOTFS_PATH
if [ $? -ne 0 ]; then
        echo "mount bootfs failed"
        exit 1
fi


$SUDO cp -rf $UCAS_OUTPUT_BOOTFS1_PATH/*  $UCAS_INPUT_BOOTFS1_PATH
if [ $? -ne 0 ]; then
        echo "mount bootfs1 failed"
        exit 1
fi

let index=2
KERNELUUID=$( $SUDO blkid $DEV_NAME$index |  sed "s/\" TYPE=.*$//g" | sed "s/^.*UUID=\"//g" )

let index=3
ROOTFSUUID=$( $SUDO blkid $DEV_NAME$index | sed "s/^.*PARTUUID=\"//g" | sed "s/\".*$//g" )

$SUDO sed -i "s/ucas-kernel-part/$KERNELUUID/g" $UCAS_INPUT_BOOTFS1_PATH$UCAS_GRUB

$SUDO sed -i "s/ucas-rootfs-part/$ROOTFSUUID/g" $UCAS_INPUT_BOOTFS1_PATH$UCAS_GRUB

sync


echo "[**--------------- finish mkimage ---------------**]"
类似UltraISO的系统镜像制作U盘启动工具。 Installing an operating system from a USB drive is much more convenient than from a disc, and a bootable drive even enables you to work from a system that does not have an OS installed. Rufus is a small-sized app that enables users to format USB flash disks and create bootable drives rapidly. It provides standard and advanced options alike, to suit the preferences of all skill levels. Format to the desired file system The tool is wrapped in a user-friendly interface that resembles the Format panel found in Windows built-in features. You can select a device, partition scheme and target system type, file system type (FAT32, NTFS, UDF, exFAT), cluster size, and new volume label. Connected devices are detected and selected from a drop-down menu. Be sure to save all important data, because the USB drive is formatted and everything is removed in the process. Compatibility options for old BIOS Basic formatting options enable you to check the device for bad blocks and select the algorithm type (from 1 to 4 passes). Plus, you can set the quick format mode, create an extended label and icon files, as well as create a bootable disk using an ISO or various other disc image types. Advanced tweaks can make Rufus list fixed (non-flash) or unpartitioned USB flash disks, add fixes for old BIOS (e.g. extra partition), and you may use Rufus MBR with a selected BIOS ID. To conclude The program records all activity to a separate panel, and it can be saved to a LOG file. It carries out a formatting task rapidly and error-free, using low system resources. We have not come across any issues during our tests since the utility did not cause Windows to hang or crash. To sum it up, Rufus is a straightforward solution to formatting and creating bootable USB drive, providing users with a series of useful features.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值