I made a live environment for ubuntu19.04 on a U disk, and then I entered the live environment, executed Burning.sh, and burned grub.cfg
, bzImage
, roootfs.tar.gz
from another U disk to the hard drive /dev/sda
. Why did I restart my computer and enter the efi shell
through the following actions?
Complete Burning.sh
#!/usr/bin/bash
######################################################################
# Author: madship_xk
######################################################################
current_path=$(pwd)
#root_path=/tmp/newOS
root_path=/mnt
boot_path=${root_path}/boot
grub_path=${boot_path}/grub
#clear
execute_command() {
local command=$1
eval "$command"
local status=$?
if [ $status -eq 0 ]; then
echo "run the cmd:$command success"
else
echo "failed to run the cmd:$command"
exit 1
fi
}
foo(){
sudo mkdir -p ${root_path}
#clear
ls /dev/sda > ./tmp.txt
hdstr=`awk 'NR==1 {print}' ./tmp.txt`
echo "hdstr="${hdstr}
rm ./tmp.txt
echo "**************************************************************************"
echo "********** 1st Command: FDISK ***********"
echo "********** Plese Follow the Introduction! ***********"
echo "**************************************************************************"
sudo fdisk ${hdstr} <<EOT 1>/dev/null 2>/dev/null || exit 1
d
1
d
2
d
3
d
4
n
1
34
+8G
n
2
w
EOT
echo ""
echo "**************************************************************************"
echo "********** 2nd Command: PARTX ***********"
echo "********** Please Follow the Introduction! ***********"
echo "**************************************************************************"
execute_command "sudo partx ${hdstr} 1>/dev/null"
execute_command "sudo parted ${hdstr} set 1 boot off"
execute_command "sudo parted ${hdstr} set 1 bios_grub on"
sleep 1
#clear
echo "**************************************************************************"
echo "********** 3rd Command: FORMAT SDA1 ***********"
echo "********** Please Follow the Introduction! ***********"
echo "**************************************************************************"
hdstr1=`printf "%s1" ${hdstr}`
echo ${hdstr1}
sleep 5
execute_command "sudo /sbin/mkfs.ext4 ${hdstr1} 1>/dev/null"
sleep 1
#clear
echo "**************************************************************************"
echo "********** 4th Command: FORMAT SDA2 ***********"
echo "********** Please Follow the Introduction! ***********"
echo "**************************************************************************"
hdstr2=`printf "%s2" ${hdstr}`
echo ${hdstr2}
sleep 5
execute_command "sudo /sbin/mkfs.ext4 ${hdstr2} 1>/dev/null"
sleep 1
#clear
echo " "
echo "**************************************************************************"
echo "********** 5th Command: MIRROR IMAGE FOR SDA1 ***********"
echo "********** Please Follow the Introduction! ***********"
echo "**************************************************************************"
execute_command "sudo mkdir ${boot_path} -p"
echo ${hdstr1}
execute_command "sudo mount ${hdstr1} ${boot_path} 1>/dev/null"
sleep 5
execute_command "sudo mkdir -p ${grub_path}"
echo "*********************Generate grub.cfg***************************************"
execute_command "sudo cp ${current_path}/grub.cfg ${grub_path}/grub.cfg"
# sudo cat > ${grub_path}/grub.cfg <<EOF 1>/dev/null || exit 1
# #Begin cfg
# set default=0
# set timeout=5
# set root=(hd0,1)
# menuentry "GNU/Linux, Test-6.4.0-rt" {
# linux /bzImage rw root=/dev/sda2
# }
# EOF
execute_command "sudo grub-install --target=i386-pc --root-directory=${root_path} --boot-directory=${boot_path} ${hdstr} --force --recheck"
execute_command "sudo chroot ${boot_path}"
execute_command "sudo update-grub2 ${hdstr}"
execute_command "sudo umount ${boot_path}"
sleep 1
#clear
echo "**************************************************************************"
echo "********** 6th Command: MIRROR IMAGE FOR SDB2 ***********"
echo "********** Please Follow the Introduction! ***********"
echo "**************************************************************************"
sleep 2
execute_command "sudo mount ${hdstr2} ${root_path}"
execute_command "sudo cp \"${current_path}/bzImage\" ${root_path}"
execute_command "sudo cp \"${current_path}/rootfs.tar.gz\" ${root_path}"
cd ${root_path}
execute_command "sudo tar -vxf rootfs.tar.gz"
execute_command "echo \"y\" | sudo rm rootfs.tar.gz"
cd ~
execute_command "sudo umount ${root_path}"
execute_command "sync"
}
jumpa(){
echo "Please input \"BURN\" to go to start point"
read INP
#echo $INP
if [[ $INP = 'BURN' ]] ; then
echo "Going to Start POINT......"
sleep 2
echo
foo
else
echo
jumpa
fi
}
#jumpa
foo
grub.cfg:
#Begin cfg
set default=0
set timeout=4
set root=(hd0,1)
menuentry "GNU/Linux, Test-6.4.0-rt" {
linux /bzImage rw root=/dev/sda2
}