LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2010, 05:34 PM   #1
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Rep: Reputation: 0
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.

Last edited by zensunni; 11-19-2010 at 05:53 PM.
 
Old 11-19-2010, 06:57 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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.

Last edited by stress_junkie; 11-19-2010 at 07:01 PM.
 
Old 11-20-2010, 02:37 AM   #3
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
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?
 
Old 11-20-2010, 08:02 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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 View Post
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 View Post
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.

Last edited by stress_junkie; 11-20-2010 at 08:45 AM.
 
1 members found this post helpful.
Old 11-24-2010, 09:27 AM   #5
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
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...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The Puppy ate my Fedora! DavidMcCann Puppy 6 03-07-2010 10:55 AM
Iptables ate start-up martincho Linux - Networking 1 09-28-2005 02:14 PM
Vista ate my GRUB! springsteenfan Linux - Software 2 09-19-2005 05:16 PM
help windows ate my MBR AhYup Slackware 1 10-07-2004 04:24 PM
Windows ate my bootloader MediGuy Linux - Newbie 4 10-10-2003 06:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration