Saturday, September 26, 2009

Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

If you run a dual-boot system with Linux and Windows, this has happened to you. You had to do your monthly reinstall of Windows, and now you don’t see the linux bootloader anymore, so you can’t boot into Ubuntu or whatever flavor of linux you prefer.

Here’s the quick and easy way to re-enable Grub.

1) Boot off the LiveCD

2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub “prompt”, and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.

sudo grub

> root (hd0,0)

> setup (hd0)

> exit


Reboot (removing the livecd), and your boot menu should be back.



Only read below if Windows is now missing from the boot menu

If you installed Ubuntu before you installed Windows, then Ubuntu will not have anything in the grub configuration for Windows. This is where you’ll have to do a bit of manual editing to the grub boot menu file.

If you open the file /boot/grub/menu.lst with the following command:

sudo gedit /boot/grub/menu.lst


You’ll see a sample section for Windows, which you’ll want to uncomment and add to the boot menu list in whatever position you want it in. (uncomment by removing the #’s)

# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1


Note that you should also verify that hd0,0 is the correct location for Windows. If you had installed Windows on the 4th partition on the drive, then you should change it to (hd0,3)


source Click here

Thursday, September 24, 2009

Mark Shuttleworth Announces via video Ubuntu 10.04: Lucid Lynx

Mark Shuttleworth spoke via video to UbuCon at the Atlanta Linux Fest 2009 and announced the name of the next Ubuntu release. Ubuntu 10.04 will be code named “Lucid Lynx” and will be an LTS release with support for the desktop for 3 years and for the server for 5 years.




Tuesday, September 8, 2009

How to let normal users shut down the computer in Linux

This may seem like a stupid issue - why SHOULDN'T the average user be able to turn off his/her own machine?

The answer is that Linux is inherently designed as a multiuser system. It would generally be a bad thing if any one user would be allowed to spontaneously turn off the computer while other users are working. Just imagine what hell would ensue if your webserver were taken down by some insignificant user halfway across the world.

Of course, it does seem a little overprotective if the user is physically sitting at the machine, since he/she could just reach over and hit the power button (don't do that!!!).

There are several schools of thought concerning how to allow a user to shut down a machine properly. The first method seems somewhat useless to me, but I put it here for completeness.

shutdown.allow
There is a file in /etc called shutdown.allow (and if there isn't, root can add it). This file contains a list of users (1 per line) who are allowed to shutdown the computer.

This doesn't mean that these users can invoke the shutdown (or reboot or halt) command(s). Instead, it means that an authorized user can shut down the computer by pressing ctrl+alt+del.

In order for this to occur, the ctrl+alt+del key sequence must be trapped in the /etc/inittab file. The necessary line in inittab is

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

When ctrl+alt+del is pressed, init checks if there is an authorized user (listed in /etc/shutdown.allow) logged into any virtual console, and proceeds to shutdown if this is true.

Of course, if I'm running X windows, then generally the window manager will trap ctrl+alt+del for itself, so this won't work anymore.

sudo
The program sudo allows normal users to execute certain root-only commands. Which users are authorized to run which commands is specified in the /etc/sudoers file. This should only be edited with the command visudo.

For example, suppose I wanted to add a group of users who are allowed to shut down the machine. So I first want to add a group called "shutdown" (run these commands while root)

groupadd shutdown

Then I need to edit the /etc/group file to add users to the "shutdown" group. I just tack the usernames at the end of the shutdown line, separated by commas, e.g.

shutdown:x:407:user1,user2,...

Whatever users I put there will be able to shut down the computer (so choose wisely). Now I need to configure sudo to allow members of the "shutdown" group to actually invoke the assorted shutdown commands provided in linux. Run visudo and add the following lines

%shutdown ALL=(root) NOPASSWD: /sbin/reboot
%shutdown ALL=(root) NOPASSWD: /sbin/halt
%shutdown ALL=(root) NOPASSWD: /sbin/shutdown

This allows the "shutdown" group to run /sbin/reboot, /sbin/halt, and /sbin/shutdown AS IF THEY WERE ROOT. The only caveat is that the users must run the commands with the command sudo in front, e.g.

sudo /sbin/halt

This is always a bit of a pain (and users never remember), so I can create the following script called "/usr/bin/reboot" (and similar scripts for halt and shutdown)

#! /bin/sh
sudo /sbin/reboot $*

Remember to make these scripts executable! To make this slightly more secure, I might want to change the ownership of these scripts to the "shutdown" group

chgrp shutdown /usr/bin/reboot /usr/bin/halt /usr/bin/shutdown

and then make them executable only for the group "shutdown"

chmod g+x /usr/bin/reboot /usr/bin/halt /usr/bin/shutdown

KDE shutdown
If you are running kdm (the kde display manager - e.g. graphical login) then the shutdown behavior can be modified in "Control Panel" (in "Administrator Mode" of course). If you are starting KDE manually (using startx or startkde) then you will have to resort to the previous "sudo" solution (and probably add a shortcut on the desktop to one of those scripts).

XFCE4 shutdown
If you are using xfce4 then you will need to configure a few items in order to use the built-in "Reboot computer"/"Turn off computer" options available when you are logging out.

CHANGE - SEE BELOW FOR XFCE 4.2

XFCE 4.0
First, all users who are allowed to shut down the machine from xfce4 must be listed in the /etc/xfce4/shutdown.allow file (syntax is just like in the /etc/shutdown.allow file - see above). Second, the file permissions on the xfce4-shutdown program must be modified. This file is usually in /usr/sbin/xfce4-shutdown, so I would type

chmod u+s /usr/sbin/xfce4-shutdown

the "u+s" argument means that the command xfce4-shutdown will run as though the owner (probably root) initiated it, regardless of which user actually called the program.

This should be enough to shut down the computer from xfce4.

Instructions for XFCE 4.2 The game has changed for xfce 4.2. Now you must instead allow sudo access to a program called /usr/sbin/xfsm-shutdown-helper (note: this may also be located in /usr/local/libexec/ - just use the "locate" command to find xfsm-shutdown-helper).

Using the same kind of ideas presented above in the sudo method of shutdown, I add the following line to /etc/sudoers file (using visudo)

%shutdown ALL=(root) NOPASSWD: /usr/sbin/xfsm-shutdown-helper

This allows the "shutdown" group to shutdown the machine.

This page has been visited 20,481 (19 today) times since January 13, 2005


Source http://www.spencerstirling.com

Monday, September 7, 2009

Instant LAN File Sharing With Python

The other day I was chatting with a co-worker and he pointed out a very simple command that could be used to quickly and easily share files with people within your LAN. This could also be used to share with people on the internets, but you’d have to configure NAT from your router. That much of the configuration is up to you, but I’ll share with you the quick ‘n easy webshare command.

The only requirement, as far as I can tell, is python. I’ve run it on my Linux machine as well as my OS X machine and it worked just fine with no other configuration or packages installed. It should likely work on anything else that has python installed as well.

To share the contents of any folder on your machine simply run:

python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"


You can run that one-liner anywhere on your file system and then access the files via your browser. Simply point your browser to your LAN IP port 8000 and you should see an index listing of the files.

To make this a little simpler I made it an alias in my .bashrc file. Just add this line somewhere in your .bashrc or .bash_aliases:

alias webshare='python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"'


At this point you can simply run the command webshare anywhere on your file system and share those files. This makes for a really simple tool for sharing files quickly and un-sharing them as soon as you’re done. Just hit ctrl-c to cancel and close the process.

source ubuntu-tutorials.com