导入导出根文件系统脚本

#!/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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值