#!/bin/sh [ -d /dev ] || mkdir -m 0755 /dev [ -d /root ] || mkdir -m 0700 /root [ -d /sys ] || mkdir /sys [ -d /proc ] || mkdir /proc [ -d /tmp ] || mkdir /tmp mkdir -p /var/lock mount -t sysfs -o nodev,noexec,nosuid none /sys mount -t proc -o nodev,noexec,nosuid none /proc tmpfs_size="10M" if [ -e /etc/udev/udev.conf ]; then . /etc/udev/udev.conf fi if ! mount -t devtmpfs -o mode=0755 none /dev; then echo "W: devtmpfs not available, falling back to tmpfs for /dev" mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1 [ -e /dev/null ] || mknod /dev/null c 1 3 fi mkdir /dev/pts mount -t devpts -o noexec,nosuid,gid=5,mode=0620 none /dev/pts || true > /dev/.initramfs-tools mkdir /dev/.initramfs export DPKG_ARCH= . /conf/arch.conf export MODPROBE_OPTIONS="-qb" export ROOTDELAY= export init=/sbin/init export panic= . /conf/initramfs.conf for conf in conf/conf.d/*; do [ -f ${conf} ] && . ${conf} done . /scripts/functions run_scripts /scripts/init-top load_modules run_scripts /scripts/init-premount [ -d /mnt ] || mkdir -m 0755 /mnt rdecho () { printf "\033[7;31m$*\n\033[0m" } grecho () { printf "\033[7;32m$*\n\033[0m" } lines=$(dialog --stdout --print-maxsize|tr -d " "|sed -e "s/.*://"|cut -d\, -f1) columns=$(dialog --stdout --print-maxsize|tr -d " "|sed -e "s/.*://"|cut -d\, -f2) scrolllines=$lines shell1 () { PS1='(kiyoChelp) ' /bin/sh -i /dev/console 2>&1 } checkelf () { if [ "a$(file $1|grep -i ELF)" = "a" ];then elfarg="" else elfarg=" --args-linux " fi } scroll () { count=0 while [ $count -ne $1 ]; do count=$(expr $count + 1) echo done } settingchange () { kernel=$(echo $1|sed -e "s/(hd[0-9]*,[0-9]*)//") initrd=$(echo $2|sed -e "s/(hd[0-9]*,[0-9]*)//") kernelopts=$3 while [ a = a ];do scroll $scrolllines dialog --begin 0 0 --no-shadow --msgbox "$mes Check the above and push ENTER key." $lines $columns ll=$(expr 2 + $(echo "$mes"|wc -l)) scrolllines=$(if [ $ll -gt $lines ];then echo $lines;else echo $ll;fi) mes5="kernel is: $kernel $(if [ -z "$(echo $initrd|tr -d " ")" ];then echo "initrd line is not set.";else echo "initrd is: $initrd";fi) kernel option is: $kernelopts You can check $5/$4 by pressing SHIFT+PageUp and come back here by SHIFT+PageDown Do you want to boot with the above settings?" scroll $scrolllines q=$(dialog --begin 0 0 --no-shadow --stdout --menu "$mes5" $lines $columns 3 y yes c "edit settings" q "quit selecting this menuentry") scrolllines=$(expr 6 + $(echo "$mes5"|wc -l)) if [ "$q" = "y" ];then checkelf /mnt/$kernel if [ "a$initrd" = "a" ];then kexec -l /mnt${kernel} $elfarg --append="$3" 2>/tmp/kexeclog if [ $? -eq 1 ];then rdecho "kexec failed!" cat /tmp/kexeclog; echo; sleep 5; continue fi else kexec -l /mnt${kernel} $elfarg --initrd=/mnt${initrd} --append="${kernelopts}" 2>/tmp/kexeclog if [ $? -eq 1 ];then rdecho "kexec failed!" cat /tmp/kexeclog; echo; sleep 5; continue fi fi umount /boot /mnt /mnt2 /mntroot kexec -e rdecho "Boot failed!" sleep 10 break elif [ "$q" = "c" ];then scroll $scrolllines q=$(dialog --begin 0 0 --no-shadow --stdout --nook --nocancel --inputbox "${mes5} Type the kernel file in full path (nothing:unchanged)" $lines $columns "$kernel") scrolllines=$(expr 6 + $(echo "$mes5"|wc -l)) if [ "a$q" != "a" ]; then kernel=$q;fi scroll $scrolllines q=$(dialog --begin 0 0 --no-shadow --stdout --nook --nocancel --inputbox "${mes5} Type the initrd file in full path (nothing:unchanged. Type \"d\" to delete)" $lines $columns "$initrd") scrolllines=$(expr 7 + $(echo "$mes5"|wc -l)) if [ "a$q" = "ad" ];then initrd="" elif [ "a$q" != "a" ];then initrd=$q fi scroll $scrolllines q=$(dialog --begin 0 0 --no-shadow --stdout --nook --nocancel --inputbox "${mes5} Type the kernel option (nothing:unchanged)" $lines $columns "${kernelopts}") scrolllines=$(expr 6 + $(echo "$mes5"|wc -l)) if [ "a$q" != "a" ];then kernelopts=$q;fi elif [ "$q" = "q" ];then break fi done } grubloop () { while [ a = a ];do scroll $scrolllines a=$(dialog --begin 0 0 --no-shadow --stdout --menu "$1 settings file $5/$2 is found. What do you want to do?" 11 80 3 1 "select title" 2 "show $5/$2" 3 "end this function") scrolllines=7 if [ "$a" = 2 ];then scroll $scrolllines dialog --begin 0 0 --no-shadow --textbox /mnt$5/$2 $lines $columns scrolllines=$lines elif [ "$a" = 1 ];then selectmes="" grep $3 /mnt$5/$2 | sed -e "s/^[^a-zA-Z0-9#]*$3 *//" > /tmp/menuentries i=0 num=$(wc -l /tmp/menuentries|tr -s " "|sed -e "s/^ *//"|cut -d" " -f1) while [ $i -lt $num ];do i=$(expr $i + 1) selectmes=$(echo "$selectmes $(expr $i - 1) $(sed -n -e "${i}p" /tmp/menuentries|sed -e "s/\"//g"|tr " " _)") done scroll $scrolllines a=$(dialog --begin 0 0 --no-shadow --stdout --menu "Please select the menu you want to look inside" $(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) $columns $(echo "$selectmes"|wc -l) $selectmes) num=$(grep -A15 -e "$(sed -n -e $(expr $a + 1)p /tmp/menuentries)$" /mnt$5/$2|grep -n ^[^a-zA-Z0-9#]*$3|sed -n -e 2p|cut -d: -f1) scrolllines=$(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) if [ -n "$num" ];then num=$(expr $num - 2) else num=15 fi grep -A $num -e "^[^a-zA-Z0-9#]*$3 *$(sed -n -e $(expr $a + 1)p /tmp/menuentries)$" /mnt$5/$2 > /tmp/grubcfg1 mes="The contents is: $(cat /tmp/grubcfg1) " kernelline=$(grep ^[^a-zA-Z0-9#]*$4 /tmp/grubcfg1|sed -n -e 1p) initrdline=$(grep ^[^a-zA-Z0-9#]*initrd /tmp/grubcfg1|sed -n -e 1p) kernel=$(echo $kernelline|sed -e "s/^[^a-zA-Z0-9#]*$4 *//"|cut -f1 -d" ") kernelopts=$(echo $kernelline|sed -e "s/^[^a-zA-Z0-9#]*$4 *//"|sed -e "s/$(echo $kernel|sed -e 's/\//\\\//g')//"|tr -s " ") initrd=$(echo $initrdline|sed -e "s/^[^a-zA-Z0-9#]*initrd *//"|cut -f1 -d" ") if [ $2 = "grub.cfg" -a -n "$(grep -e '[^#]*loopback' /tmp/grubcfg1)" ];then loopdisk=$(grep -v insmod /tmp/grubcfg1|grep -e '[^#]*loopback'|sed -n -e 1p|sed -e "s/.*loopback//"|tr -s " "|cut -d " " -f3|sed -e "s/.*)//") if [ -f /mnt$loopdisk ];then mkdir /mntroot mount -o move /mnt /mntroot mount -o loop,ro /mntroot$loopdisk /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" if [ -n "$(file /mntroot/$loopdisk|grep -i ext)" ];then mount -t ext4 -o loop,ro,noload /mntroot/$loopdisk /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" mount --move /mntroot /mnt;sleep 5 break fi elif [ -n "$(file /mntroot/$loopdisk|grep -i ISO|grep -i 9660)" ];then mount -t iso9660 -o loop /mntroot/$loopdisk /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" mount --move /mntroot /mnt;sleep 5 break fi fi fi looppoint=$(grep -v insmod /tmp/grubcfg1|grep -e '[^#]*loopback'|sed -n -e 1p|sed -e "s|.*loopback||"|tr -s " "|cut -d " " -f2) kernel=$(echo $kernel|sed -e "s/(${looppoint})//g") initrd=$(echo $initrd|sed -e "s/(${looppoint})//g") else rdecho "There is not a file $loopdisk in $(mount|grep 'on /mnt '|cut -d" " -f1)" mount --move /mntroot /mnt;sleep 5 break fi fi settingchange "$kernel" "$initrd" "$kernelopts" "$2" "$5" break elif [ "$a" = 3 ];then break fi done } addsyslinuxconf () { aaa=$(grep -i -e "include" $1|sed -e "s/include//") if [ -z "$aaa" ];then return;fi for bb in $aaa;do if [ -n "$(file /mnt$2/$bb|grep -i text)" ];then syslinuxfiles="$syslinuxfiles /mnt$2/$bb" addsyslinuxconf "/mnt$2/$bb" "$2" fi done } while [ a = a ];do grecho "========================== Type s and push ENTER key to use shell or wait until all the device you want to boot is recognized and then push ENTER key. ==========================" read -s a lvm vgchange -aly if [ "$a" = "s" ];then shell1 continue fi deviceslist=$(blkid|cut -d: -f1) okdeviceslist="" for a in $deviceslist;do umount -l /mnt 2>/dev/null mount -t $(blkid $a|sed -e "s/.*TYPE=\"//"|sed -e "s/\".*//") $a /mnt -o ro 2>/dev/null || continue okdeviceslist="${okdeviceslist} $a" umount -l /mnt 2>/dev/null done i=0 echo deviceslist="" for a in ${okdeviceslist};do deviceslist=$(echo "$deviceslist $i $(blkid|grep "${a}:"|sed -e "s/\"//g"|tr " " _)") i=$(expr $i + 1) done scroll $scrolllines a=$(dialog --begin 0 0 --no-shadow --stdout --menu "Please select the root partition of Linux you want to boot." $(if [ $lines -gt $(expr $(echo "$deviceslist"|wc -l) + 6 + 2) ];then expr $(echo "$deviceslist"|wc -l) + 6 + 2;else echo $lines;fi) $columns $(echo "$deviceslist"|wc -l) $deviceslist) ll=$(expr $(echo "$deviceslist"|wc -l) + 6 + 2) scrolllines=$(if [ $lines -gt $ll ];then echo $ll;else echo $lines;fi) device=$(echo ${okdeviceslist}|cut -d" " -f $(expr $a + 1)) grecho "You selected $a:$device" mount -t $(blkid $device|sed -e "s/.*TYPE=\"//"|sed -e "s/\".*//") $device /mnt -o ro aa="l" while [ $aa = "l" ];do scroll $scrolllines aa=$(dialog --begin 0 0 --no-shadow --stdout --title "What do you want to do?" --menu "" 10 80 4 y "Search Grub, Sys(iso,ext)linux, Lilo, Wubi or kernel automatically" m "Select manually config/kernel/initramfs files" l "Select file to loop mount" zzz "Use shell (busybox)") scrolllines=8 if [ $aa = "l" ];then scroll $scrolllines scrolllines=$lines tomount=$(dialog --keep-window --begin 0 0 --no-shadow --colors --stdout --title "Select \Z5file to loop mount\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/ $(expr $lines - 10) $columns) if [ $? = 1 ];then rdecho "You canceled!";sleep 5;continue;fi [ -d /mntroot ] || mkdir /mntroot mount --move /mnt /mntroot tomount=$(echo $tomount|sed -e "s@^/mnt@/mntroot@") mount $(if [ -n "$(file $tomount|grep -i ISO|grep 9660)" ];then echo "-t iso9660";fi) -o loop,ro $tomount /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" if [ -n "$(file $tomount|grep -i ext)" ];then mount -t ext4 -o loop,ro,noload $tomount /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" mount --move /mntroot /mnt;sleep 5 fi else mount --move /mntroot /mnt;sleep 5 fi fi fi done if [ -n "$(echo $aa|grep y)" ];then if [ -e /mnt/boot/grub/grub.cfg -o -e /mnt/grub/grub.cfg ];then [ -e /mnt/boot/grub/grub.cfg ]&& cc="/boot/grub"||cc="/grub" grubloop "GRUB2" "grub.cfg" "menuentry[^_]" "linux" "$cc" fi if [ -e /mnt/boot/grub/menu.lst -o -e /mnt/grub/menu.lst ];then [ -e /mnt/boot/grub/menu.lst ]&& cc="/boot/grub"||cc="/grub" grubloop "GRUB_legacy" "menu.lst" "title" "kernel" "$cc" fi if [ -e /mnt/menu.lst ];then grubloop "GRUB_legacy" "menu.lst" "title" "kernel" "" fi if [ -e /mnt/boot/syslinux/syslinux.cfg -o -e /mnt/syslinux/syslinux.cfg -o -e /mnt/syslinux.cfg -o -e /mnt/boot/extlinux.conf -o -e /mnt/extlinux.conf -o -e /mnt/boot/isolinux/isolinux.cfg -o -e /mnt/isolinux/isolinux.cfg ];then [ -e /mnt/boot/syslinux/syslinux.cfg ]&& c="/boot/syslinux" && cc="syslinux.cfg" [ -e /mnt/syslinux/syslinux.cfg ]&& c="/syslinux" && cc="syslinux.cfg" [ -e /mnt/syslinux.cfg ]&& c="" && cc="syslinux.cfg" [ -e /mnt/boot/extlinux.conf ]&& c="/boot" && cc="extlinux.conf" [ -e /mnt/extlinux.conf ]&& c="" && cc="extlinux.conf" [ -e /mnt/boot/isolinux/isolinux.cfg ]&& c="/boot/isolinux" && cc="isolinux.cfg" [ -e /mnt/isolinux/isolinux.cfg ]&& c="/isolinux" && cc="isolinux.cfg" syslinuxfiles="/mnt$c/$cc" addsyslinuxconf "/mnt$c/$cc" "$c" while [ a = a ];do a=$(dialog --begin 0 0 --no-shadow --stdout --menu "$(echo $cc|sed -e "s/\..*//") settings file $c/$cc is found. $syslinuxfiles is/are found as configuration file(s)." 12 80 3 1 "select menuentry" 2 "show configuration file(s)" 3 "end this function") if [ "$a" = 2 ];then for a in $syslinuxfiles;do scroll $scrolllines dialog --begin 0 0 --no-shadow --title "$a" --textbox $a $lines $columns scrolllines=$lines done elif [ "$a" = 1 ];then selectmes="" grep -H -i ^[^a-zA-Z0-9#]*label\ * $syslinuxfiles > /tmp/menuentries i=0 num=$(wc -l /tmp/menuentries|tr -s " "|sed -e "s/^ *//"|cut -d" " -f1) while [ $i -lt $num ];do i=$(expr $i + 1) selectmes=$(echo "$selectmes $(expr $i - 1) $(sed -n -e "${i}p" /tmp/menuentries|sed -e "s/\"//g"|tr " " _)") done scroll $scrolllines a=$(dialog --begin 0 0 --no-shadow --stdout --menu "Please select the menu you want to look inside" $(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) $columns $(echo "$selectmes"|wc -l) $selectmes) num=$(grep -A15 -e "$(sed -n -e $(expr $a + 1)p /tmp/menuentries|cut -d: -f2)$" "$(sed -n -e $(expr $a + 1)p /tmp/menuentries|cut -d: -f1)"|grep -i -n ^[^a-zA-Z0-9#]*label\ *|sed -n -e 2p|cut -d: -f1) scrolllines=$(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) if [ -n "$num" ];then num=$(expr $num - 2) else num=15 fi grep -i -A $num -e "^[^a-zA-Z0-9#]*$(sed -n -e $(expr $a + 1)p /tmp/menuentries|cut -d: -f2)$" "$(sed -n -e $(expr $a + 1)p /tmp/menuentries|cut -d: -f1)" > /tmp/grubcfg1 # the above line has problem when label line contains ":" or file name contains ":". mes="The contents is: $(cat /tmp/grubcfg1) " kernelline=$(grep -i -e "^[^a-zA-Z0-9#]*\(kernel\|linux\)" /tmp/grubcfg1|sed -n -e 1p) initrdline=$(grep -i ^[^a-zA-Z0-9#]*initrd /tmp/grubcfg1|sed -n -e 1p) kernelopts=$(grep -i ^[^a-zA-Z0-9#]*append /tmp/grubcfg1|sed -e "s/^[^a-zA-Z0-9#]*\(append\|APPEND\) *//"|tr -s " ") if [ "a$(echo $kernelopts|grep -i initrd=)" = "a" ];then initrd=$(echo $initrdline|sed -e "s/^[^a-zA-Z0-9#]*\(initrd\|INITRD\) *//"|cut -f1 -d" ") else initrd=$(echo $kernelopts|sed -e "s/.*initrd=//"|cut -d" " -f1) fi settingchange "$(echo $kernelline|sed -e "s/^[^a-zA-Z0-9#]*\(kernel\|KERNEL\|linux\|LINUX\) *//"|cut -f1 -d" ")" "$initrd" "$kernelopts" "$cc" "$c" break elif [ "$a" = 3 ];then break fi done fi if [ -f /mnt/etc/lilo.conf ];then while [ a = a ];do scroll $scrolllines a=$(dialog --begin 0 0 --no-shadow --stdout --menu "/etc/lilo.conf (LILO settings file)is found." 10 50 3 1 "select menuentry" 2 "show /etc/lilo.conf" 3 "end this function") scrolllines=7 if [ "$a" = 2 ];then scroll $scrolllines dialog --begin 0 0 --no-shadow --title "/etc/lilo.conf" --textbox /mnt/etc/lilo.conf $lines $columns scrolllines=$lines elif [ "$a" = 1 ];then grep label= /mnt/etc/lilo.conf | sed -e "s/^[^a-zA-Z0-9#]*label=//" > /tmp/menuentries selectmes="" i=0 num=$(wc -l /tmp/menuentries|tr -s " "|sed -e "s/ *//"|cut -d" " -f1) numnum=$(wc -l /mnt/etc/lilo.conf|tr -s " "|sed -e "s/ *//"|cut -d" " -f1) while [ $i -lt $num ];do i=$(expr $i + 1) selectmes="$selectmes $(expr $i - 1) $(sed -n -e "${i}p" /tmp/menuentries|tr " " _)" done scroll $scrolllines scrolllines=$(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) a=$(dialog --begin 0 0 --no-shadow --stdout --menu "Please type the number of the menu you want to look inside" $scrolllines $columns $(echo "$selectmes"|wc -l) $selectmes) num1=$(sed -e $(grep -n -e "label=$(sed -n -e $(expr $a + 1)p /tmp/menuentries)$" /mnt/etc/lilo.conf|cut -d: -f1)q /mnt/etc/lilo.conf|grep -n image=|cut -d: -f1|sort -n -r|sed -n -e 1p) num2=$(sed -n -e $num1,${numnum}p /mnt/etc/lilo.conf|grep -n image=|cut -d: -f1|sed -n -e 2p) num3=$(sed -n -e $num1,${numnum}p /mnt/etc/lilo.conf|grep -n other=|cut -d: -f1|sed -n -e 1p) if [ a$num2 = a ];then if [ a$num3 = a ];then num2=$numnum else num2=$num3 fi elif [ a$num3 = a ];then : elif [ $num2 -gt $num3 ];then num2=$num3 fi sed -n -e "${num1},$(expr $num1 + $num2 - 2)p" /mnt/etc/lilo.conf > /tmp/grubcfg1 mes="The contents is: $(cat /tmp/grubcfg1)" initrdline=$(grep initrd= /tmp/grubcfg1|sed -n -e 1p) initrd=$(echo $initrdline|sed -e "s/^[^a-zA-Z0-9#]*initrd= *//"|cut -f1 -d" ") kernelline=$(grep image= /tmp/grubcfg1|sed -n -e 1p) kernel=$(echo $kernelline|sed -e "s/^[^a-zA-Z0-9#]*image=//"|cut -f1 -d" ") kernelopts="$(grep append= /tmp/grubcfg1|sed -e "s/^[^a-zA-Z0-9#]*append=//"|sed -e "s/\"//g") $(if [ "$(grep read-write /tmp/grubcfg1)" ];then echo "rw";fi) $(if [ "$(grep read-only /tmp/grubcfg1)" ];then echo "ro";fi) $(grep ramdisk= /tmp/grubcfg1) $(grep literal= /tmp/grubcfg1|sed -e "s/^[^a-zA-Z0-9#]*literal=//"|sed -e "s/\"//g")" if [ -n "$(grep root=current /tmp/grubcfg1)" ];then kernelopts="$(grep root= /mnt/etc/lilo.conf|sed -n -e 1p) $kernelopts" else kernelopts="$(grep root= /tmp/grubcfg1) $kernelopts" fi settingchange "$kernel" "$initrd" "$kernelopts" "lilo.conf" "/etc" break elif [ "$a" = 3 ];then break fi done fi if [ -f /mnt/ubuntu/disks/root.disk ];then grecho "/ubuntu/disks/root.disk is found. Maybe this is WUBI file." device=$(grep " /mnt " /proc/mounts|cut -d" " -f1) mkdir /mntroot mount --move /mnt /mntroot mount -o loop,ro /mntroot/ubuntu/disks/root.disk /mnt if [ -n "$(mount|grep ' /mnt ')" ];then mkdir /boot mount --bind /mnt/boot /boot settingchange "/vmlinuz" "/initrd.img" "root=UUID=$(blkid $device|sed -e 's/^.*UUID=\"//'|sed -e 's/\".*//') loop=/ubuntu/disks/root.disk ro" "root.disk" "/ubuntu/disks" elif [ -n "$(file /mntroot/ubuntu/disks/root.disk|grep -i ext)" ];then mount -t ext4 -o loop,ro,noload /mntroot/ubuntu/disks/root.disk /mnt 2>/tmp/errormes if [ -z "$(mount|grep ' /mnt ')" ];then rdecho "$(cat /tmp/errormes)" mount --move /mntroot /mnt;sleep 5 else mkdir /boot mount --bind /mnt/boot /boot settingchange "/vmlinuz" "/initrd.img" "root=UUID=$(blkid $device|sed -e 's/^.*UUID=\"//'|sed -e 's/\".*//') loop=/ubuntu/disks/root.disk ro" "root.disk" "/ubuntu/disks" fi fi fi kernels=$(ls /mnt/boot/ -1|grep vmlinuz) selectmes="" i=0 for a in $kernels;do i=$(expr $i + 1) bb="$(ls -1 /mnt/boot/initrd*$(echo $a|cut -c9-)*|sed -n "1p")" selectmes="$selectmes $i ${a}_with_$bb" done scroll $scrolllines scrolllines=$(if [ $lines -gt $(expr $(echo "$selectmes"|wc -l) + 6 + 2) ];then expr $(echo "$selectmes"|wc -l) + 6 + 2;else echo $lines;fi) a=$(dialog --begin 0 0 --no-shadow --stdout --menu "The following kernels seems to be available." $scrolllines $columns $(echo "$selectmes"|wc -l) $selectmes) if [ $? = 0 ];then kernelopts="root=UUID=$(blkid|grep "$device:"|sed -e "s/^.*UUID=\"//"|sed -e "s/\".*//") ro" kernel="/boot/$(echo ${kernels}|cut -d" " -f $a)" settingchange "$kernel" "$(ls -1 /mnt/boot/initrd*$(echo $kernel|cut -c15-)*|sed -n "1p"|sed -e "s@^/mnt@@")" "$kernelopts" "$kernel" "" fi fi if [ "$aa" = "m" ];then while [ a = a ];do con=0 scroll $scrolllines scrolllines=$lines configfile=$(dialog --keep-window --begin 0 0 --no-shadow --colors --stdout --title "Select \Z5file to read\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/ $(expr $lines - 10) $columns) if [ $? = 1 ];then rdecho "You canceled selecting config file";con=1;sleep 5;break;fi if [ -n "$(file $configfile|cut -d: -f2|grep -i text)" ];then break;else rdecho "$configfile is not a text file!";sleep 5;fi done if [ $con -eq 0 ];then nkf -w -Lu $configfile > /tmp/configfile cc=$(echo $configfile|sed -e "s@^/mnt/@/@" -e "s@/[^/]*\$@@") mes2=$(echo $configfile|sed -e "s@^.*/@@") configfile=/tmp/configfile fi while [ a = a ];do scroll $scrolllines if [ $con -eq 0 ];then kernel=$(dialog --keep-window --begin 0 0 --no-shadow --colors --title "$cc/$mes2: Move by arrow keys to find \Z5kernel (vmlinuz... etc)\Zn" --textbox $configfile $(expr $lines - 11) $columns --and-widget --keep-window --begin $(expr $lines - 14) 0 --no-shadow --colors --stdout --title "Select \Z5kernel\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/$kernel 5 $columns) else kernel=$(dialog --keep-window --begin 0 0 --no-shadow --colors --stdout --title "Select \Z5kernel\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/$kernel $(expr $lines - 10) $columns) fi if [ $? = 1 ];then rdecho "You canceled selecting kernel file";kernel=nothing;sleep 5;break;fi if [ -n "$(file $kernel|cut -d: -f2|grep -i Linux|grep -i kernel)" ];then kernel=$(echo $kernel|sed -e "s@^/mnt/@/@") break else rdecho "$kernel is not a kernel!" sleep 5 fi done if [ "$kernel" = "nothing" ];then continue;fi while [ a = a ];do scroll $scrolllines if [ $con -eq 0 ];then initrd=$(dialog --keep-window --begin 0 0 --no-shadow --colors --title "$cc/$mes2: Move by arrow keys to find \Z5initramfs (initrd... etc)\Zn" --textbox $configfile $(expr $lines - 11) $columns --and-widget --keep-window --begin $(expr $lines - 14) 0 --no-shadow --colors --stdout --title "Select \Z5initramfs\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/$initrd 5 $columns) else initrd=$(dialog --keep-window --begin 0 0 --no-shadow --colors --stdout --title "Select \Z5initramfs\Zn. \Z1ENTER\Zn to finish. \Z1Space\Zn to select. \Z1/\Zn to enter in Dir. /mnt is root Dir." --fselect /mnt/$initrd $(expr $lines - 10) $columns) fi if [ $? = 1 ];then grecho "You skipped initramfs.";sleep 5;initrd="";break elif [ -n "$(file $initrd|cut -d: -f2|grep -i compressed|grep -i data)" ];then initrd=$(echo $initrd|sed -e "s@^/mnt/@/@") break else rdecho "$initrd does not seem to be a valid initramfs!" sleep 5 fi done scroll $scrolllines if [ $con -eq 0 ];then kernelopts=$(dialog --keep-window --begin 0 0 --no-shadow --colors --title "$cc/$mes2 : Move by arrow keys to find \Z5kernel options\Zn" --textbox $configfile $(expr $lines - 4) $columns --and-widget --keep-window --begin $(expr $lines - 7) 0 --no-shadow --colors --stdout --title "Input \Z1kernel options\Zn." --inputbox "" 7 $columns $kernelopts) else kernelopts=$(dialog --keep-window --begin 0 0 --no-shadow --colors --stdout --title "Input \Z1kernel options\Zn." --inputbox "" 7 $columns $kernelopts) scrolllines=7 fi settingchange "$kernel" "$initrd" "$kernelopts" "$mes2" "$cc" fi if [ "$aa" = "zzz" ];then shell1 fi done