LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script(s) ate my OS (https://www.linuxquestions.org/questions/linux-newbie-8/script-s-ate-my-os-845402/)

zensunni 11-19-2010 06:34 PM

Script(s) ate my OS
 
So, I can't boot my Ubuntu 10.04 lts after doing something that I'm guessing was very stupid and now my OS just goes to grub rescue cmd line.

I'm hoping that if I say what I did, I can maybe have a shot at recovering my OS.

I created a script in /ect/init.d/ called hourly_reminder.sh, which is thus:

Code:

sleep 40

/bin/su - joe -c "/bin/bash /home/joe/Scripts/hourly_reminder.sh" &
/bin/su - joe -c "/bin/bash /home/joe/Scripts/after_hours_user.sh" &
/bin/bash /home/joe/Scripts/after_hours.sh

Note that the first two files exist:
/home/joe/Scripts/hourly_reminder.sh
/home/joe/Scripts/after_hours_user.sh

Note also that the last one doesn't exist:
/home/joe/Scripts/after_hours.sh

after_hours.sh was a mistake in the script. The real file was:
/home/joe/Scripts/after_hours_root.sh

This wasn't realized until after the OS died.

Also note that I made two hourly_reminder.sh scripts (one in /etc/init.d & one in /home/joe/Scripts).

So, the code for all three child scripts are:

/home/joe/Scripts/hourly_reminder.sh
Code:

#!/bin/bash

export DISPLAY=:0.0;
export  XAUTHORITY=$(ps h $(pidof X) | awk '{print $11}');

for (( ; ; ))
do

  sleep 3600
  #sleep 3
  /usr/bin/xmessage -button ok -center "Hourly reminder to get off the computer"

done

/home/joe/Scripts/after_hours_user.sh
Code:

#!/bin/bash

export DISPLAY=:0.0;
export  XAUTHORITY=$(ps h $(pidof X) | awk '{print $11}');


for (( ; ; ))
do

  z_hr=`date +%H`
  echo $z_hr
  if [ $z_hr > 13 ] || [ $z_hr < 5 ]; then
          /usr/bin/xmessage -button ok -center "Its too late to be on the computer. You have 15 minutes." &
        sleep 900
          /usr/bin/xmessage -button ok -center "1 minute to Shutdown" &
  fi

done

/home/joe/Scripts/after_hours_root.sh
Code:

#!/bin/bash

export DISPLAY=:0.0;
export  XAUTHORITY=$(ps h $(pidof X) | awk '{print $11}');


for (( ; ; ))
do

  z_hr=`date +%H`
  echo $z_hr
  if [ $z_hr > 13 ] || [ $z_hr < 5 ]; then
        sleep 960
          /sbin/shutdown -h now
  fi

done

The first time, I started the computer with these scripts, I waited 15 min, had three xmessages come up, then gnome gtk windows were blank. When I opened windows & destop stuff they wouldn't work (even gedit was blank). I tried restarting and it got to the login screen once, I think. Then it wouldn't get to the login screen and would breakdown halfway in the startup.

Then it would just start at grub rescue terminal.

Right now, I'm on a crunch-bang live CD (which is awesome BTW) and have since taken out all text in the /ect/init.d/hourly_reminder.sh script.

I am now in the process of downloading and burning an ubuntu 10.04 LTS disk.

Any help in this matter would be awesome. I hope I've been descriptive enough.

stress_junkie 11-19-2010 07:57 PM

The only thing that looks suspicious is the export XAUTHORITY. This is what I get when I execute your code on my Gnome Ubuntu working system logged in as a normal user.
Code:

$ echo $(ps h $(pidof X) | awk '{print $11}')
-nolisten

That doesn't look good.

Note that logged on as a normal user my XAUTHORITY looks like this.
Code:

$ echo $XAUTHORITY
/var/run/gdm/auth-for-user1-4HduOT/database

user1 is my user name in this example.

The rest of the scripts seem harmless.

zensunni 11-20-2010 03:37 AM

Well I guess I should start with repairing grub2.

How is this done? I tried to mount my filesystem, but the ubuntu live CD didn't find it.

When I typed:
mount /dev/sda1 /media/sda1

it said I must specify a filetype.

my crunchbang live CD picked it up and mounted it under /media/disk

can I do a grub2 recovery on crunchbang for ubuntu 10.04?

here's my fdisk -l output:
Code:

crunchbang@crunchbang:~$ sudo fdisk -l

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a49cf

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1      13995  112412672  83  Linux
/dev/sda2          13995      14594    4805633    5  Extended
/dev/sda5          13995      14594    4805632  82  Linux swap / Solaris

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x78eb963b

  Device Boot      Start        End      Blocks  Id  System
/dev/sdb1              1      121601  976760001    7  HPFS/NTFS

Disk /dev/sdc: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e9953

  Device Boot      Start        End      Blocks  Id  System
Note: sector size is 4096 (not 512)

Disk /dev/sdd: 15.7 GB, 15744368640 bytes
224 heads, 60 sectors/track, 286 cylinders
Units = cylinders of 13440 * 4096 = 55050240 bytes
Disk identifier: 0x00000000

  Device Boot      Start        End      Blocks  Id  System
/dev/sdd1  *          1        286    15375120    b  W95 FAT32
Partition 1 has different physical/logical beginnings (non-Linux?):
    phys=(0, 0, 60) logical=(0, 1, 1)

What should I do?

stress_junkie 11-20-2010 09:02 AM

I see that your fdisk -l listing shows sda1 is Linux, sda2 is the extended logical partition space, and sda5 is your swap partition.

Quote:

Originally Posted by zensunni (Post 4165139)
Well I guess I should start with repairing grub2.
How is this done? I tried to mount my filesystem, but the ubuntu live CD didn't find it.
When I typed:
mount /dev/sda1 /media/sda1
it said I must specify a filetype.

This error usually means that the operating system didn't recognize the file system type because it doesn't have a driver (module) installed for it. It most often appears when you are trying to mount a Microsoft file system.

Quote:

Originally Posted by zensunni (Post 4165139)
my crunchbang live CD picked it up and mounted it under /media/disk

Speaking from no knowledge of crunchbag I would say that yes you can use crunchbag to fix your installed Ubuntu system.

So now let's get on with fixing GRUB 2. Note that the steps to repair legacy GRUB are the same until we get to the GRUB commands.

Here is the procedure. You MUST be logged in as root in order to perform this procedure.
1- fsck the Ubuntu file system
Note that this by itself could fix your problem Try to boot Ubuntu after this step.
2- mount the Ubuntu system partition
3- mount --bind the /dev and /proc file sytems to the corresponding directories in the mounted Ubuntu file system
4- chroot into the Ubuntu file system
5- remove the offending script from the system startup
6- repair (optional) and install GRUB 2

Here are the details.
1- fsck the Ubuntu file system
Code:

fsck /dev/sda1
This may fix your problem. Try to boot Ubuntu at this point. If it doesn't work then start over using the live CD and go to step 2.

2- mount the Ubuntu system partition (/dev/sda1) to /media/disk. You said that crunchbag does this already so I won't put a mount command in here. I don't want to confuse you with something that you don't need. Just be sure that the partition is mounted read/write.
Code:

touch /media/disk/delete.me
ls -lh /media/disk/delete.me

If you see the "delete.me" file then you are all set. Yes you could simply have used mount | grep media to see if the file system was mounted read/write.

3- mount --bind the two system directories /proc and /dev to the mounted Ubuntu file system.
Code:

mount --bind /proc /media/disk/proc
mount --bind /dev /media/disk/dev

4- chroot into the Ubuntu file system
Code:

chroot /media/disk /bin/sh
From this point on all file paths are relative to the Ubuntu system partition. In other words the Ubuntu system partition is / for this shell ONLY. Any new shell instances will still be using the live CD as their environment.

5- remove the offending script from the system startup. Keep in mind that there are lots of ways to do this. My way preserves the code so that you can continue to experiment.
Code:

cd /etc/init.d
mv hourly_reminder.sh disabled-hourly_reminder.sh

6- now fix GRUB 2. You may only have to run /usr/sbin/grub-install.
Code:

/usr/sbin/grub-install
I don't see any reason that your scripts should have broken GRUB 2 in the first place so let's say something else broke GRUB 2. You may have to repair the configuration. These commands should do it. Notice that I am calling /usr/sbin/grub-install after the two GRUB 2 "repair" utilities.
Code:

/usr/bin/os-prober
/usr/sbin/update-grub
/usr/sbin/grub-install

If these steps don't work then you should think about anything else that you did that could have affected GRUB 2. As I said, your script may have broken X but I don't know why it would have broken GRUB 2.

It is possible that GRUB 2 is not broken but Linux cannot start X. However I would guess that this would lead to Linux loading in terminal mode.

You may have to delete the files /root/.Xauthority and /home/joe/.Xauthority

Anyway, good luck. Keep in touch. Let us know if you fixed the problem and, if you fix it, let us know how you did it.

zensunni 11-24-2010 10:27 AM

Thanks stress_junkie!

Your first step worked. I just ran fsck and it booted right up.

I was kinda disappointed, since I kinda wanted to try reinstalling grub2.

Maybe I should just create another linux instance to just mess with...


All times are GMT -5. The time now is 08:08 AM.