Created
March 24, 2017 07:47
-
-
Save jsfaint/9acee065b9e53f40b6eaf7f1213a7fdb to your computer and use it in GitHub Desktop.
Build a live usb disk from rootfs.tgz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash - | |
############################################################################### | |
# FILENAME: | |
# auto_sys_inst.sh | |
# | |
# DESCRIPTION: | |
# Build a live usb disk from rootfs.tgz | |
# | |
# REVISION(MM/DD/YYYY): | |
# 11/22/2011 jia.sui([email protected]) | |
# - Initial version | |
############################################################################### | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: $0 {dev_node} {rootfs}" | |
echo " dev_node: /dev/sda" | |
echo " rootfs: rootfs.tgz under current path." | |
echo "Example: $0 /dev/sda rootfs.tgz" | |
exit 2 | |
fi | |
dev_node=$1 | |
rootfs=$2 | |
#create partition | |
echo "Please delete the old partitions, and create a new partition on usb disk." | |
fdisk $dev_node | |
if [[ $? -ne 0 ]]; then | |
echo "Create partition on $dev_node failed." | |
exit 2 | |
fi | |
#if mounted ,umount first partition of $dev_node | |
mount | grep ${dev_node}1 | |
if [[ $? -eq 0 ]]; then | |
umount ${dev_node}1 | |
fi | |
#make file system | |
mkfs.ext3 ${dev_node}1 | |
if [[ $? -ne 0 ]]; then | |
echo "Format ${dev_node}1 as ext3 failed." | |
exit 2 | |
fi | |
#mount first partition of $dev_node | |
if [[ ! -d /mnt/tmp ]]; then | |
mkdir /mnt/tmp | |
fi | |
mount ${dev_node}1 /mnt/tmp | |
#install grub | |
grub-install --root-directory=/mnt/tmp ${dev_node}1 --no-floppy | |
#extract rootfs.tgz | |
rootfs_full=`pwd`$rootfs | |
cd /mnt/tmp | |
tar zxvf $rootfs_full | |
cd `dirname $rootfs_full` | |
#Change partition label | |
e2label ${dev_node}1 | |
#Disable selinux | |
if [[ -e /etc/selinux/config ]]; then | |
sed -r "s/^SELINUX=.*$/SELINUX=disabled/g" "/mnt/tmp/etc/selinux/config" > "/mnt/tmp/etc/selinux/config" | |
fi | |
#umount first partition of $dev_node and remove temp dir. | |
umount ${dev_node}1 | |
rmdir /mnt/tmp | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment