Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Friday, March 16, 2012

How to restart from windows to linux / linux to windows on dual boot PCs


If you have a dual boot installation of Ubuntu and Windows 7 on the same PC like me, you need to switch windows for gaming or business purposes occasionally. Menu selection screen only shows few seconds and if you miss, you have to restart the PC again. I need a shortcut on both linux and windows desktop to switch OS after restart. 

You may want to use permanently default OS on grub and search "one time boot" options. Here I will explain a method for changing default OS by a small script on both windows and linux sides.

Please note that I'm using EXT2 file system on linux for this method to work. Last version 0.51 of ext2fsd software claims that they support writing to ext3/4 volumes too. However I didn't try it yet. If someone try this method with ext3 or 4 please notify me... 



On Windows side:




This software mounts ext2 partitions and maps to windows. 


  • Copy and edit the grub.cfg script that set the default OS as linux. 0 is Ubuntu, 5 is Windows on my PC's grub configuration. So I change the value to 0 to open the pc in linux OS. 

#

# DO NOT EDIT THIS FILE

#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

  • Create a batch script to copy and overwrite the grub.cfg file to linux partititon and restart windows.

batch script "restart to linux" is:


start /d "C:\Program Files\Ext2Fsd" Ext2Mgr.exe
timeout /t 10
copy d:\grub.cfg I:\boot\grub
shutdown /r /t 0


Meaning:

start /d "C:\Program Files\Ext2Fsd" Ext2Mgr.exe 

Here letter "I" is my drive that has grub config file "/boot/grub/grub.cfg".




timeout /t 10 


wait for 10 seconds to start the ext2fsd program and mount the drivers



 copy d:\grub.cfg I:\boot\grub

Copy the grub.cfg file which has default OS as linux



shutdown /r /t 0 


Reboot windows immediately.




On Linux side:


  • We need to use sudo without password in the script file.  Run visudo and add your username to its config file.

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

#includedir /etc/sudoers.d
username  ALL=(ALL) NOPASSWD:ALL


  • Copy and modify grub.cfg file that has default OS as windows. Here "5" is windows OS on my PC.

grub.cfg file must be like:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="5"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi


  • create a file on linux desktop, name it as "reboot_to_windows", give execute grants



# chomod 777 reboot_to_windows


  • Add these lines to copy the modified grub.cfg file to /boot/grub directory and reboot linux
sudo cp -f /home/oturan/Desktop/grub.cfg /boot/grub
sudo reboot





Thats all! It worked for me, hope it works on your PC too. Bye.

Tuesday, November 1, 2011

Ubuntu Unity 11.04 & 11.10 Teamviewer startup problem for 2 eth card pc's

If you have a pc with 2 ethernet ports like me, you may have a problem with teamviewer autostart.
Since teamviewer starts before ethernet card is activated, it is trying to activate but it fails. 
Here is a workaround for this problem:

  •  Install teamviewer from official site. 
Although it was freezing sometimes on Ubuntu 10.04, it is working flawless on Ubuntu 11.10



  • Create a shell script to start teamviewer with 50 seconds delay. 
Delay is needed to wait the ethernet card to activate


$ vi /home/user/teamviewer_start.sh

sleep 50
teamviewer6 &
  • Click start menu and launch startup applicatons



  • Click add button, name it Teamview or something you choose.



  • Click Browse button for command and choose the sciript.



Now teamviewer succesfully opens and availiable at ubuntu startup.

Ubuntu Unity 11.04 & 11.10 VNC server with X11vnc


  • Uninstall default VNC server:

sudo apt-get remove vino


  • Install x11vnc
sudo apt-get install x11vnc


  • Create /etc/init/x11vnc.conf for lightdm


sudo vi /etc/init/x11vnc.conf

start on login-session-start
script
x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -forever -bg -o /var/log/x11vnc.log -rfbauth /etc/x11vnc.pass -rfbport 5900

end script

  • Create a password with storepasswd option
x11vnc -storepasswd "password_enter_here" /etc/x11vnc.pass