GRUB만 잘 쪼물딱거려도 할 수 있는게 정말 많습니다.
참고하시라고, 아래 소스를 올려봅니다.
이것은 자동으로, /ubuntu-cd를 검색해서, ISO목록을 서브메뉴로 보여주고, 최신 버전의 iso이미지를 디폴트로 선택해줍니다.
또한 /boot-images를 검색해, ISO목록을 서브메뉴로 보여줍니다. 여기 들어가는 ISO파일은 grub4dos를 사용해서 부팅하기에,
리눅스 부팅이미지가 아닌, ghost나 trueimage등의 부팅이미지로도 부팅이 가능합니다.
그리고, 하드디스크의 boot 파티션을 검색해서, 최신의 커널로 자동부팅할 수 있게 해줍니다.
저는 이런식으로, USB를 만들어 놓고, 그안에 각종 ISO이미지를 넣어놓아 복구용 USB로 사용합니다.
AcronisTrueImage.iso
Ghost.15.iso
Hirens.BootCD.iso
MiniTool.PartionWizard.HomeEdition.BootCD.iso
NTBOOT.iso
SystemRescueCD.iso
WIN7.UserPE.2.iso
snoopy.Ghost.iso
win7pe.iso
win8re.iso
이런 이미지들을 사용합니다. ^^
[code:ifjxsdcx]
####################################################################
Define Variables
####################################################################
set bootopts="boot=casper locale=ko_KR.utf8 file=/cdrom/preseed/ubuntu.seed quiet splash noprompt noeject –"
set instopts="locale=ko_KR only-ubiquity"
set ramdopts="toram root=/dev/shm"
set iso_dir=/boot-images
set ubuntu_iso_dir=/ubuntu-cd
set grub4dos_dir=/grub4dos
####################################################################
Initialize
####################################################################
function pause {
echo $*
read
}
insmod normal
insmod regexp
set pager=1
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set arch=i386
set use_amd64=
if cpuid -l; then
set arch=amd64
set use_amd64=amd64
fi
export arch
function searchex {
search $*
clear
}
function load_gfx {
insmod all_video
set gfxmode="auto"
set gfxplayload="keep"
loadfont $prefix/fonts/unicode.pf2
terminal_output gfxterm
}
#load_gfx
function load_fs_driver {
insmod extcmd
insmod part_msdos
insmod ext2
insmod fat
insmod ntfs
insmod loopback
}
export ubuntu_iso_dir
export grub4dos_dir
export iso_dir
function detect_ubuntu_iso_dev {
insmod regexp
set ubuntu_iso_dev=
if [ -n "${ubuntu_iso_dir}" ]; then
for dev in (*,*); do
if [ -d "${dev}${ubuntu_iso_dir}" ]; then
set ubuntu_iso_dev=$dev
export ubuntu_iso_dev
return 0
fi
done
fi
set ubuntu_iso_dir=
export ubuntu_iso_dir
export ubuntu_iso_dev
return 1
}
function select_ubuntu_iso {
insmod regexp
#loopback -d tmp_iso
#loopback tmp_iso "$1"
set ubuntu_iso_selected=""
set selected_ubuntu_iso_tag=""
if [ -n "$1" ]; then
set ubuntu_iso_selected="$1"
regexp -s x "^./([^/])$" "$1"
if [ -n "$x" ]; then
set selected_ubuntu_iso_tag=" (${x})"
fi
fi
export ubuntu_iso_selected
export selected_ubuntu_iso_tag
export ubuntu_iso_dev
configfile "${rescue_cfg}"
}
function is_e2fs {
insmod regexp
insmod functional_test
if regexp "," $1; then
probe -s fs -f $1
if [ "$fs" = "btrfs" ]; then
return 0
elif regexp "^ext" $fs; then
return 0
fi
fi
return 1
}
function cmp_ver {
insmod regexp
regexp -s v1 "([0-9][0-9\.-]+[0-9])" "$1"
regexp -s v2 "([0-9][0-9\.-]+[0-9])" "$2"
if [ -z "$v1" -a -z "$v2" ]; then
set ret=100
export ret
return
elif [ -z "$v1" ]; then
set ret=102
export ret
return
elif [ -z "$v2" ]; then
set ret=101
export ret
return
fi
set s1=$v1
set s2=$v2
set ret=101
while true; do
set v1=
set v2=
regexp -s v1 "([0-9]+)" "$s1"
regexp -s v2 "([0-9]+)" "$s2"
if [ -z "$v1" -a -z "$v2" ]; then
set ret=1
break
elif [ -z "$v1" ]; then
set ret=0
break
elif [ -z "$v2" ]; then
set ret=2
break
elif [ $v1 -eq $v2 ]; then
continue
elif [ $v1 -gt $v2]; then
set ret=2
break
else
set ret=0
break
fi
regexp -s s1 "[0-9]+[^0-9]*([0-9].*)" "$s1"
regexp -s s2 "[0-9]+[^0-9]*([0-9].*)" "$s2"
done
if [ -z "$ret"]; then
set ret=1
fi
export ret
}
function find_proper_file {
set udir="$1"
set pat_prefix="$2"
set pat_suffix="$3"
if [ -z "$udir" ]; then
set udir=${ubuntu_iso_dir}
fi
#set udir=/${udir#/}
set tmp_var=
insmod regexp
insmod functional_test
for f in ${udir}/${pat_prefix}*${pat_suffix}; do
if [ ! -f "$f" ]; then
set ret=
export ret
return
fi
cmp_ver $tmp_var $f
if [ ${ret} -ge 100 ]; then
continue
elif [ ${ret} -lt 1 ]; then
set tmp_var="$f"
continue
fi
done
if [ -z "$tmp_var" ]; then
set tmp_var="$f"
fi
set ret="$tmp_var"
export ret
}
function detect_linux_dev {
set linux_root_dev=
set linux_boot_dev=
set linux_boot_dir=
insmod regexp
insmod functional_test
for d in (*,*); do
if is_e2fs "$d"; then
if [ -z "$linux_root_dev" -a -f "${d}/sbin/init" ]; then
set linux_root_dev="$d"
export linux_root_dev
fi
if [ -z "$linux_boot_dev" ]; then
if [ -f "${d}/grub/grub.cfg" ]; then
set linux_boot_dev="$d"
set linux_boot_dir=
export linux_boot_dev
export linux_boot_dir
elif [ -f "${d}/boot/grub/grub.cfg" ]; then
set linux_boot_dev="$f"
set linux_boot_dir=/boot
export linux_boot_dev
export linux_boot_dir
fi
fi
if [ -n "$linux_boot_dev" -a -n "$linux_root_dev" ]; then
return 0
fi
fi
done
if [ -z "$linux_boot_dev" -a -z "$linux_root_dev" ]; then
return 1
else
return 0
fi
}
function detect_ubuntu_iso {
insmod regexp
set success=0
set ubuntu_loop=
set udir="$1"
if [ -z "$udir" ]; then
set udir=${ubuntu_iso_dir}
fi
#set udir=/${udir#/}
regexp -s dev "^(\([^\)]*\)).*\$" "$udir"
if [ -z "$dev" ]; then
if detect_ubuntu_iso_dev; then
if [ -z "${ubuntu_iso_dev}" ]; then
return 1
else
set udir="${ubuntu_iso_dev}${udir}"
fi
fi
fi
for dist in ubuntu kbuntu lubuntu xubuntu; do
for xarch in ${arch} ${use_amd64} i386; do
for type in desktop server; do
#if searchex -s ubuntu_loop -f "${udir}/${dist}-${ret}-${type}-${arch}.iso"; then
find_proper_file "${udir}" "${dist}-" "-${type}-${xarch}.iso"
if [ -n "$ret" ]; then
#set ubuntu_loop="${udir}/${dist}-${ret}-${type}-${xarch}.iso"
set ubuntu_loop="$ret"
set success=1
break 3
fi
done
done
done
if [ -z "$ubuntu_loop" ]; then
searchex -s ubuntu_loop -f "${udir}/ubuntu.iso"
fi
export ubuntu_loop
}
function search_grub4dos {
searchex -s grub4dos_dev -f ${grub4dos_dir}/grub.exe
export grub4dos_dev
}
function boot_legacy_iso {
set iso_file="$1"
set iso_dir2="$2"
if [ -z "$2" ]; then
set iso_dir2="${iso_dir}"
fi
search_grub4dos
set boot_legacy_cmd="find --set-root ${iso_dir2}/${iso_file}; map ${iso_dir2}/${iso_file} (0xff); map --hook; chainloader (0xff)"
linux16 ($grub4dos_dev)${grub4dos_dir}/grub.exe --config-file=""find --set-root ${iso_dir2}/${iso_file}; map ${iso_dir2}/${iso_file} (0xff); map --hook; chainloader (0xff)""
}
function ubuntu_auto_select {
insmod regexp
if [ -z "${ubuntu_iso_selected}" ]; then
if [ -z "${ubuntu_iso_dev}" ]; then
detect_ubuntu_iso_dev
fi
detect_ubuntu_iso ${ubuntu_iso_dev}${ubuntu_iso_dir}
set ubuntu_iso_selected=${ubuntu_loop}
else
set ubuntu_loop=${ubuntu_iso_selected}
fi
if [ -n "${ubuntu_loop}" ]; then
regexp -s ubuntu_iso "^[^/]*(/.*)\$" ${ubuntu_loop}
regexp -s x "^.*/([^/]*)\$" "${ubuntu_loop}"
if [ -n "$x" ]; then
set selected_ubuntu_iso_tag=" (${x})"
fi
fi
export ubuntu_iso
}
function ubuntu_iso_automount {
ubuntu_auto_select
loopback lo ${ubuntu_loop}
}
set ubuntu_iso_menu="Select Ubuntu ISO"
if [ -z "${ubuntu_iso_selected}" ]; then
ubuntu_auto_select
if [ -z "$ubuntu_iso_dev" ]; then
set ubuntu_iso_menu="----------- No Ubuntu ISO directory found! ----------"
else
set ubuntu_iso_menu="Select Ubuntu ISO"
fi
fi
####################################################################
Boot menu configuration
####################################################################
separator use like this
menuentry " " --source="set ret=;"
#================================================
Ubuntu ISO selection
just select ubuntu iso for booting
#================================================
submenu "${ubuntu_iso_menu}${selected_ubuntu_iso_tag}" {
load_fs_driver
insmod regexp
insmod functional_test
detect_ubuntu_iso_dev
if [ -n "$ubuntu_iso_dev" ]; then
menuentry "Cancel selected" --source="select_ubuntu_iso"
for img in ${ubuntu_iso_dev}${ubuntu_iso_dir}/ubuntu*.iso;
do
regexp -s img_name "^.*/([^/]*)\$" $img
menuentry "$img_name" --source="select_ubuntu_iso $img"
done
fi
}
#================================================
Ubuntu ISO booting
#================================================
set menu_title=‘Ubuntu Live (Auto Detect)’
if [ -z "${ubuntu_iso_dir}" ]; then menu_title=‘’; fi
menuentry "${menu_title}" {
if [ -n "${ubuntu_iso_dir}" ]; then
load_fs_driver
ubuntu_iso_automount
if [ -n "${ubuntu_iso}" ]; then
if [ -f (lo)/casper/vmlinuz.efi ]; then
linux (lo)/casper/vmlinuz.efi persistent iso-scan/filename="${ubuntu_iso}" $bootopts
else
linux (lo)/casper/vmlinuz persistent iso-scan/filename="${ubuntu_iso}" $bootopts
fi
initrd (lo)/casper/initrd.lz
else
echo "Error: file not found ($ubuntu_iso)!"
fi
fi
}
set menu_title=‘Try Ubuntu without Install (RAMDISK/Auto Detect)’
if [ -z "${ubuntu_iso_dir}" ]; then menu_title=‘’; fi
menuentry "${menu_title}" {
if [ -n "${ubuntu_iso_dir}" ]; then
load_fs_driver
ubuntu_iso_automount
if [ -n "${ubuntu_iso}" ]; then
if [ -f (lo)/casper/vmlinuz.efi ]; then
linux (lo)/casper/vmlinuz.efi iso-scan/filename="${ubuntu_iso}" $ramdopts $bootopts
else
linux (lo)/casper/vmlinuz iso-scan/filename="${ubuntu_iso}" $ramdopts $bootopts
fi
initrd (lo)/casper/initrd.lz
else
echo "Error: file not found ($ubuntu_iso)!"
fi
fi
}
set menu_title=‘Try Ubuntu without Install (Auto Detect)’
if [ -z "${ubuntu_iso_dir}" ]; then menu_title=‘’; fi
menuentry "${menu_title}" {
if [ -n "${ubuntu_iso_dir}" ]; then
load_fs_driver
ubuntu_iso_automount
if [ -n "${ubuntu_iso}" ]; then
if [ -f (lo)/casper/vmlinuz.efi ]; then
linux (lo)/casper/vmlinuz.efi iso-scan/filename="${ubuntu_iso}" $bootopts
else
linux (lo)/casper/vmlinuz iso-scan/filename="${ubuntu_iso}" $bootopts
fi
initrd (lo)/casper/initrd.lz
else
echo "Error: file not found ($ubuntu_iso)!"
fi
fi
}
set menu_title=‘Install Ubuntu (RAMDISK/Auto Detect)’
if [ -z "${ubuntu_iso_dir}" ]; then menu_title=‘’; fi
menuentry "${menu_title}" {
if [ -n "${ubuntu_iso_dir}" ]; then
load_fs_driver
ubuntu_iso_automount
if [ -n "${ubuntu_iso}" ]; then
if [ -f (lo)/casper/vmlinuz.efi ]; then
linux (lo)/casper/vmlinuz.efi iso-scan/filename="${ubuntu_iso}" $instopts $ramdopts $bootopts
else
linux (lo)/casper/vmlinuz iso-scan/filename="${ubuntu_iso}" $instopts $ramdopts $bootopts
fi
initrd (lo)/casper/initrd.lz
else
echo "Error: file not found ($ubuntu_iso)!"
fi
fi
}
set menu_title=‘Install Ubuntu (Auto Detect)’
if [ -z "${ubuntu_iso_dir}" ]; then menu_title=‘’; fi
menuentry "${menu_title}" {
if [ -n "${ubuntu_iso_dir}" ]; then
load_fs_driver
ubuntu_iso_automount
if [ -n "${ubuntu_iso}" ]; then
if [ -f (lo)/casper/vmlinuz.efi ]; then
linux (lo)/casper/vmlinuz.efi iso-scan/filename="${ubuntu_iso}" $instopts $bootopts
else
linux (lo)/casper/vmlinuz iso-scan/filename="${ubuntu_iso}" $instopts $bootopts
fi
initrd (lo)/casper/initrd.lz
else
echo "Error: file not found ($ubuntu_iso)!"
fi
fi
}
#================================================
Custom ISO booting
#================================================
#menuentry ‘System rescue CD’ {
load_fs_driver
searchex -s -f /boot-images/SystemRescueCD.iso
loopback lo /boot-images/SystemRescueCD.iso
linux (lo)/isolinux/rescuecd isoloop="/boot-images/SystemRescueCD.iso"
initrd (lo)/isolinux/initram.igz
#}
#menuentry ‘Snoopy Ghost’ {
boot_legacy_iso ‘snoopy.ghost.iso’
#}
#================================================
compose menuentry from list of ISO in $iso_dir
if select then Boot from ISO in $iso_dir
#================================================
set boot_iso_menu="Boot from ISO"
if [ -z "${iso_dir}" -o ! -d "(hd0,1)${iso_dir}" ]; then
set boot_iso_menu="----------- No ISO directory found! ----------"
set iso_dir=
export boot_iso_menu
export iso_dir
fi
submenu "${boot_iso_menu}" {
load_fs_driver
insmod regexp
insmod functional_test
insmod normal
export iso_dir
if [ -n "${iso_dir}" ]; then
if [ -d "(hd0,1)${iso_dir}" ]; then
for img in (hd0,1)${iso_dir}/*.iso;
do
regexp -s img_name "^.*/([^/]*)\$" $img
menuentry "$img_name" --source="boot_legacy_iso $img_name"
done
fi
fi
}
#================================================
Auto-Detecting OS
#================================================
menuentry "Linux (Auto-detect)" {
load_fs_driver
insmod regexp
insmod functional_test
insmod normal
insmod probe
detect_linux_dev
if [ -n "$linux_root_dev" -a -n "$linux_boot_dev" ]; then
#for f in ($grub_bootdev)/vmlinuz* ($grub_bootdev)/boot/vmlinuz*; do set kernel=$f; break; done
#for f in ($grub_bootdev)/initrd* ($grub_bootdev)/boot/initrd*; do set initrd=$f; break; done
#xxxxxxxxxx
find_proper_file ${linux_boot_dev}${linux_boot_dir} System.map-
if [ -n "$ret" ]; then
regexp -s ret ".*/System.map-([^/]+)\$" $ret
fi
set root=${linux_boot_dev}
set kernel=${linux_boot_dev}${linux_boot_dir}/vmlinuz-${ret}
set initrd=${linux_boot_dev}${linux_boot_dir}/initrd.img-${ret}
probe -s rootuuid $linux_root_dev -u
linux $kernel root=UUID=$rootuuid quiet splash
initrd $initrd
else
echo "Error: linux partition is not found!"
fi
}
menuentry "Windows XP/2k NTLDR (Auto-detect)" {
load_fs_driver
insmod ntldr
#search -s grub4dos_dev -f /grub4dos/grub.exe
#linux16 ($grub4dos_dev)/grub4dos/grub.exe --config-file=""map () (hd0)\; map (hd0) ()\; map --hook\; find --ignore-floppies --ignore-cd --set-root /ntldr\; chainloader /ntldr""
if searchex -s -f /ntldr; then
ntldr /ntldr
else
echo "Error: windows NT boot loader not found!"
fi
}
menuentry "Windows 7/8/Vista BootMgr (Auto-detect)" {
load_fs_driver
insmod ntldr
if searchex -s -f /bootmgr; then
ntldr /bootmgr
else
echo "Error: windows Boot manager not found!"
fi
}
menuentry "DOS (Auto-detect)" {
load_fs_driver
#searchex -s grub4dos_dev -f /grub4dos/grub.exe
#linux16 ($grub4dos_dev)/grub4dos/grub.exe --config-file=""map () (hd0)\; map (hd0) ()\; map --hook\; find --ignore-floppies --ignore-cd --set-root /ntldr\; chainloader /ntldr""
set dossys=
if [ search -f /io.sys ]; then
set dossys=/io.sys
elif [ search -f /kernel.sys ]; then
set dossys=/kernel.sys
fi
if [ -n "$dossys" ]; then
linux16 (${grub4dos_dev}${grub4dos_dir})/grub.exe --configfile="find --set-root ${dossys};chainloader ${dossys}"
set root=(${dossys})
chainloader ${dossys}
else
echo "Error: DOS system not found!"
fi
}
#================================================
Change boot loader to Grub4DOS
#================================================
menuentry ‘Chainload GRUB4DOS’ {
load_fs_driver
search_grub4dos
if [ -n "$grub4dos_dev" ]; then
set root=(${grub4dos_dev})
linux16 ${grub4dos_dir}/grub.exe --config-file=""find --set-root /menu.lst --ignore-floppies --ignore-cd\; configfile /menu.lst""
fi
}
[/code:ifjxsdcx]