#!/bin/bash
#导出rootfs
#tar -czvpf /mnt/rootfs.tar.gz --exclude=/tmp/* --exclude=/var/log/* --exclude=/dev/* --exclude=/sys/* --exclude=/proc/* --exclude=/userdata/* --exclude=/run/* --exclude=/oem/* --exclude=/media/* --exclude=/mnt/* /
ROOTFS_FILE=$1
TARGET_FILE="ubuntu.img"
SOURCE_FILE="ubuntu/"
if [[ $EUID -ne 0 ]]; then
echo "must be executed with root or sudo" 1>&2
exit 1
fi
if [[ ! -e $ROOTFS_FILE ]]; then
echo "file[$ROOTFS_FILE] not found."
exit 1;
fi
mkdir -p $SOURCE_FILE
tar -xzvf $ROOTFS_FILE -C $SOURCE_FILE
FILE_SIZE=$(du -sml ubuntu/ | awk '{print $1}')
FILE_SIZE=$((FILE_SIZE + 200))
echo "-------ubuntu $FILE_SIZE M--------"
if [ -e $TARGET_FILE ];then
rm -rf $TARGET_FILE
echo "-------remove file $TARGET_FILE !--------"
fi
dd of=$TARGET_FILE bs=1M seek=$FILE_SIZE count=0 2>&1 || fatal "Failed to dd image!"
mke2fs -t ext4 $TARGET_FILE
if [ -e /tmp_ext2 ];then
rm /tmp_ext2 -rf
echo "---------remove dir emp_ext2!------------"
fi
mkdir /tmp_ext2
echo "-------make dir tmp_ext2 for mount !-----"
mount $TARGET_FILE /tmp_ext2
cp -rp $SOURCE_FILE/* /tmp_ext2
umount /tmp_ext2
tune2fs -c 0 -i 0 $TARGET_FILE
echo "-------build compilete,remove tmp dir!-----"
rm /tmp_ext2 -rf
导入导出根文件系统脚本
最新推荐文章于 2024-04-26 16:44:25 发布