extract_initramfs.sh


#!/bin/bash
INITRAMFS_DIR="initramfs_cpio_dir"
#INITRAMFS_FILE="$(pwd)/x86_64_iso_rootfs/boot/initramfs-linux-fallback.img"
INITRAMFS_FILE="/tmp/iso/boot/initramfs-linux-fallback.img"
CPIO_FILE="initramfs.cpio.gz"
if [ ! -d ${INITRAMFS_DIR} ] ; then
    mkdir -pv ${INITRAMFS_DIR}
fi
cd ${INITRAMFS_DIR}
if [ -e $CPIO_FILE ] ; then
    rm -f $CPIO_FILE
fi
cp  -f $INITRAMFS_FILE  $CPIO_FILE
gzip -f -d $CPIO_FILE
sudo cpio -idmv --no-absolute-filenames < ${CPIO_FILE/.gz}



fast_install_usb_disk.sh

#!/bin/bash
format_en="0"
#dev_name="/dev/sdd"
root_label="usb_root"
mydisk_label="usb_mydisk"
install_dir="/tmp/usb_linux_install"
root_src_dir="/home/lvarchroot/quickinstall/install_dir_i686"
START_SEC=$(date +%s)
function die()
{
    echo -e "error: $@"
    sudo beep -r 3
    exit 1
}
function usage()
{
    echo "$0 -d /dev/sdb"
    exit 0
}
# 检测、配置输入的命令
while getopts 'd:fh' arg; do
   case "${arg}" in
    h) usage 0;;
    f) format_en="1" ;;
    d) dev_name="${OPTARG}" ; echo $dev_name ;;
    *) error "无效参数 '${arg}'"; usage 1 ;;
   esac
done
if [ -z $dev_name ] ; then
    echo "请设置目标设备 -d /dev/sdX"
    usage
    exit 1
fi
if [ ${format_en} = "1" ] ; then
    dialog --defaultno --yesno "是否格式化 ${dev_name}1"  15 20
    if [ $? -eq 0 ] ; then
        mkfs.ext4 ${dev_name}1
        boot_flag=$(fdisk -l ${dev_name} | grep ${dev_name}1 | awk '{print $2}')
        if [ "x${boot_flag}" = "x*" ] ; then
            echo "已是引导状态!!"
        else
            echo "不是引导状态@@"
            fdisk ${dev_name} <<< EOF
            a
            1
            w
            EOF
        fi
    fi
    if [ -b ${dev_name}2 ] ; then
        dialog --defaultno --yesno "是否格式化 ${dev_name}2"  15 20
        if [ $? -eq 0 ] ; then
            mkfs.ext4 ${dev_name}2
        fi
    fi
fi
if [ ! -b ${dev_name}1 ] ; then
    die "${dev_name}1 不是块设备"
fi
if [ ! -b ${dev_name}2 ] ; then
    die "${dev_name}2 不是块设备"
fi
dialog --defaultno --yesno "是否使用${dev_name}做为安装目标设备"  15 20
if [ $? -eq 1 ] ; then
    echo "退出安装过程!!!"
    exit 1
fi
#   target_part="${dev_name}1"
#   fstype=$(blkid -u filesystem -o value -s TYPE -p ${target_part})
#   if [ "x$fstype" != "xvfat" ] ; then
#       echo "${target_part}  不是合法的FAT分区"
#   fi
#
#   target_part="${dev_name}2"
#   fstype=$(blkid -u filesystem -o value -s TYPE -p ${target_part})
#   if [ "x$fstype" != "xext2" ] ; then
#       echo "${target_part}  不是合法的EXT2分区"
#   fi
for i in $(seq 1 2) ; do
    target_part="${dev_name}$i"
    fstype=$(sudo blkid -u filesystem -o value -s TYPE -p ${target_part})
    if [ "x$fstype" != "xext4" ] ; then
        die "${target_part}  不是合法的EXT4分区"
    fi
done
if [ ! -d $install_dir ] ; then
    mkdir -pv $install_dir
else
   echo " install dir = $install_dir "
fi
echo "开始挂载  ${dev_name}1  到  $install_dir "
sudo mount ${dev_name}1 $install_dir || die "挂载失败"
echo "挂载完毕"
#exit 1
echo "开始制作标签"
sudo e2label ${dev_name}1 $root_label    || die "set ${dev_name}1 $root_label"
sudo e2label ${dev_name}2 $mydisk_label || die "set ${dev_name}2 $mydisk_label "
echo "制作完毕"
echo "开始时间 $(date +%H:%M:%S)"
echo "开始拷贝系统, 所花时间比较长"
sudo cp -af ${root_src_dir}/*  ${install_dir} || die "安装失败"
echo "拷贝完毕"
echo "开始制作启动grub"
sudo grub-install --boot-directory=${install_dir}/boot --force ${dev_name} > /dev/null 2>&1 ||  \
    die "设置grub ${dev_name} 出错"
echo "grub启动制作完成!"
for i in $(seq 1 2) ; do
    target_part="${dev_name}$i"
    sudo blkid ${target_part}
done
sudo umount ${dev_name}1 || die "卸载失败"
echo "结束时间 $(date +%H:%M:%S)"
END_SEC=$(date +%s)
TOTAL_SEC=$((${END_SEC} - $START_SEC))
SEC=$((TOTAL_SEC%60))
MIN=$((TOTAL_SEC/60))
echo "花费 ${MIN} 分 ${SEC} 秒"
echo "操作已完成"
sudo beep