Monday 20 August 2012

Start VNC automatically

So a couple of you have been asking about getting VNC to start automatically (me included).  I did a bit of digging and have figured out what to do - it's a few simple steps.  First off though, must say thanks to Penguin Tutor for the actual answer to this issue.


So - I'm assuming that you have VNC up and running, working if you start it manually after each boot.  If not, take a look here.


Create startup file
The first thing you need to do is create the file that will actually start VNC on startup.  I'm doing this via Putty (instructions here), but you can just as easily use Terminal directly from the Pi.

Type the following:
sudo nano /etc/init.d/tightvncserver

NOTE: nano is a lightweight editor - the command above will create a new file called tightvncserver in the /etc/init.d directory and open it for editing, presenting the following screen (note the [ New File ] entry at the bottom, indicating a new file):

Once you have the file open, paste in the following:

# First configure the user you want to run this under - this will generally be pi, unless you've created your own users
export USER='pi'

eval cd ~$USER

# Check the state of the command - this'll either be start or stop 
case "$1" in
  start)
    # if it's start, then start vncserver using the details below
    su $USER -c '/usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565'
    echo "Starting vncserver for $USER "
    ;;
  stop)
    # if it's stop, then just kill the process
    pkill Xtightvnc
    echo "vncserver stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/vncserver {start|stop}"
    exit 1
    ;;
esac
exit 0

# thanks - check out http://myraspberrypiexperience.blogspot.co.uk for more info!


NOTE: In the file I've specified my own resolution with the text -geometry 1280x800 - you can leave this out of you want

This will be what your screen now looks like.

To exit, press Ctrl+X.  You'll be prompted to save - just type Y:

You'll be prompted to confirm the filename - just press Enter:


Set file properties
Once that's done make sure the file has the right propertied by typing the following:
sudo chmod 755 /etc/init.d/tightvncserver

NOTE: Important to do this step every time you modify this file.  I redid these steps to create the tutorial, skipped this step and couldn't VNC in on the reboot!

Add File to startup sequence
And now just add your file to the list of startup actions by typing the following:
sudo update-rc.d tightvncserver defaults

And that should be it!  Just restart, and you should be able to VNC straight in!

79 comments:

  1. I need help. My server did not start after a reboot, no matter what script i use. I´m using Raspbian “wheezy” from 2012-08-16. I did all the steps described above. I am wondering about your note to the chmod, but i did it. Can you help me?

    ReplyDelete
    Replies
    1. Hi Bernhard - I'm not too sure I'm afraid. The first time I tried, it also didn't work, but after I ran the chmod step it worked. I deleted the file, re-traced my steps a 2nd time and it worked that time too.

      Best advice? Scrap everything and try it again from scratch, re-run through the steps & instructions :) So often I kick myself when it works the 2nd time.

      Something else I tried when troubleshooting my initial issue was to connect via Putty and run the file you created manually - that'll identify if it's an issue with the file or configuring it in the start-up process.

      Hope this helps!

      Delete
  2. In the tightvncserver file you use different names when starting and killing the process, why is that?

    ReplyDelete
  3. If I understand it correctly, Xtightvnc in the pkill command is the name or the process that is actually running, whereas the application itself is called vncserver. I haven't confirmed this yet, but if you get vnc up and running and then look at your processes you should see one running called Xtightvnc.

    ReplyDelete
  4. My own fault totally but any way you can *prevent* vnc from loading after doing this?

    I'm pretty new with Linux and currently cant figure out how to get onto my desktop now!!

    Probably something really obvious but Id appreciate a pointer.

    ReplyDelete
    Replies
    1. I haven't tried to use this myself, but after a quick google it looks like you'll just need to do the following:
      1) Delete the script file you created
      2) Remove the script from the startup process

      As mentioned, I haven't tested this myself, but I think the commands would be as follows:
      1) sudo delete /etc/init.d/tightvncserver
      2) sudo update-rc.d tightvncserver remove

      I hope it works!

      Delete
    2. hi tass,

      i think you made a small mistake in the commands, delete should be rm (stands for remove), no shame on you becous i had to look it up ;) just letting every1 know.

      Harrie

      Delete
    3. Thanks for the head-up Harrie!

      Delete
  5. Good day to all
    I follow with interest and passion raspberry on the blog, I tried to start the tightvncserver to boot, that does not work, the error 'this (update-rc.d: using dependency based boot sequencing
    insserv: warning: script 'tightvncserver' missing LSB tags and overrides
    ).
    There will be 'a solution to the problem?
    thanks
    Stefano

    ReplyDelete
    Replies
    1. Hi Stefano. I haven't actually hit that problem on my Pi, although I've tried to replicate this same process on my Ubuntu machine and got pretty much the same issue. Not too sure where it comes from. I see someone has posted an alternative below that might help. What he's done there is to put the actual command line straight into the rc file, rather than using the method above which places a shortcut of sorts into the rc file. This direct approach might get better results?

      Delete
  6. You can actually have this start at a boot-up by editing your /etc/rc.local file and inserting the following before the exit 0 line.

    su -c "tightvncserver :1 -geometry 1280x1024 -depth 24" user

    Geometry you can change to your screen resolution and user would your username that you use to login. I have seen vncserver be used instead of tightvncserver but couldn't get that to work on my system.

    ReplyDelete
    Replies
    1. Thanks for the suggestion - hope this more direct approach helps Stefano out!

      Delete
  7. I was also getting "Missing LSB tags and overrides."

    Adding the following to the start of the file seemed to take care of it:
    ### BEGIN INIT INFO
    # Provides: vncserver
    # Required-Start: networking
    # Required-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Starts VNC
    # Description:
    ### END INIT INFO

    No warnings, and I was able to VNC in without a problem.

    ReplyDelete
  8. Hi,

    It seems that tightvnc server stops responding after a day or so. I have it running on my pi which is always on. Any ideas why this happens and what a possible resolution is?

    Thanks

    ReplyDelete
    Replies
    1. Sorry samad64, I haven't had this problem as I don't tend to leave my Pi on long enough, and if I do it's to use Raspbmc. I'll try get one of my other boards up and running soon to see if I experience the same issue. What distro and you running?

      Delete
  9. im using raspbian wheezey from 10/28/12

    thanks for looking into it

    ReplyDelete
    Replies
    1. Right - I've re-imaged, am up and running - let's see how it goes. I've got a few more questions:
      - how are you starting VNC - automatically or manually?
      - if manually, what command are you using?
      - if automatically are you using the initial command I posted, or have you tried the 'Unknown' comment above?

      Delete
    2. I'm using your automatic method. Have not tried unknown's comment above.

      I've got a workaround for now, a cron job set to execute every 24 hours to kill the server and restart it... but its not very ideal

      When I am unable to connect, it simply says the password is incorrect - though a restart of vnc will let me in with the same password

      Delete
    3. OK, thanks. Odd that it's giving you a password error. I've started with the other approach first (su -c "tightvncserver :1 -geometry 1280x1024 -depth 24" user). The poster suggested tighvncserver rather than vncserver as he had issues with vncserver - might be related. I'll keep it running over the next few days and keep connecting in and let you know how it goes.

      Delete
    4. Hi samad64. So I've run this for the past few days, intermittently connecting, without any issue. There are a couple of things different that I can think of - it might be worth trying them one by one:
      - I'm using the latest Wheezy release (2012-12-16). You might not have to create a new blank image - simply running sudo apt-get update
      - I've running tightvncserver now rather than vncserver like my post outlines.

      I don't think it's hardware related due to the 'password' error, so I would hope of those 2 sort it out. Let us know how it goes.

      Delete
  10. Adding:

    su -c "tightvncserver :1 -geometry 1280x1024 -depth 24" user


    to the /etc/rc.local file, did solve the missing LSB tags and overrides error.

    Thanks for the excellent guide!

    ReplyDelete
  11. You can actually have this start at a boot-up by editing your /etc/rc.local file and inserting the following before the exit 0 line.
    su -c "tightvncserver :1 -geometry 1280x1024 -depth 24" user
    Regard's,
    Ben Linus,
    Go here for more info

    ReplyDelete
  12. Unfortunately my pi didn't start the vnc server after the reboot. What is the problem. This is a virgin pi, I have been using it since 2 hours. :)

    ReplyDelete
  13. hello all,
    If you have problems with starting vnc on boot you can have a look on this website:

    http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/running-vncserver-at-startup

    For me it worked out this way :D
    Good luck!

    ReplyDelete
    Replies
    1. first i want to say that i am glad to help you with my google skills :P

      This method is also more useful in another way, becous it will only start the vnc server when startx (desktop) get launched so it will not try to start it up on boot and fail (if you are not starting startx automatically) and then you still need to start it manually..

      gr. Harrie

      Delete
  14. hi ,
    i have a problem when running vnc server, like this :

    Couldn't start Xtightvnc; trying default font path.
    Please set correct fontPath in the vncserver script.
    Couldn't start Xtightvnc process.

    help me please

    ReplyDelete
  15. Every tutorial I have used to get tightvncserver to start at boot renders my pi useless. After doing this one I am stuck in a login boot - A box asking me for my username pi, and my password raspberry with a choice of default login. Password works but then just comes back up again.

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Raspberry Pi... Teach your kids about computing! I was a unix admin long ago (now a windows admin). Linux has had 20+ years to evolve and we're still dealing with this obtuse command-line crap. What a joke!

    ReplyDelete
  18. Great post!
    I also have a Pi blog: http://raspberrynewbie.wordpress.com/

    ReplyDelete
  19. Now that you have the ability to VNC into your Pi, you will likely never want to hook it up to a monitor, mouse and keyboard again.

    ReplyDelete
  20. woww artikel yg sangat sangat bagus sekali..

    Agen Bola Terpercaya

    ReplyDelete
  21. Hi, I've been looking through the web to find a solution to my vnc or x problem. I can successfully connect to my pi via vnc however all I get is grey desktop and x mouse pointer. Any ideas why? Cheers, George

    ReplyDelete
  22. i was using headless setup using ethernet, but suddenly it has stopped working due to ethernet port, . is there any way to setup headless via VNC directly without display ?

    ReplyDelete
  23. i was using headless setup using ethernet, but suddenly it has stopped working due to ethernet port, . is there any way to setup headless via VNC directly without display ?

    ReplyDelete
  24. If you are looking for space in East Delhi , just logon www.think4buysale.in and make it perfect deal for yourself as www.think4buysale.in is the best destination to find property deals in patparganj industrial area with real pics of premises and will complete solution to your requirements.Just logon to think4buysale.in or call on +919958023001 and let the experts do the best for you.

    Office space for rent in patparganj Industrial area

    Office space for rent in karkardooma

    Commercial Office space for rent in laxmi nagar

    Office space for rent in Preet vihar


    Bridal Mehndi Artist in Delhi

    ReplyDelete
  25. https://www.completegate.com/2016080659/blog/raspberry-pi-the-ultimate-convenience Do read and share your views ....

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. This is really an informative blog for an ECE student like me this blog is worth to read and know many things about Raspberry pie.
    coworking space in Hyderabad
    Office Space in HyderabadOffice space for rent in Bangalore
    Coworking space in Bangalore

    ReplyDelete
  29. Thanks for sharing .If you're planning to start a business in Chennai and looking for professional Business Center In Chennai can help you find a strategic business office address. They offers a wide range of serviced offices, office suites and tailormade office packages including business set-up services.
    Fully Furnished Office Space For Rent In Chennai
    Co-Working Space In Chennai
    Best Co-Working Space In Chennai
    Private Office Space In Chennai
    Office Space In Chennai
    Shared Office Space For Rent In Chennai
    Business Center In Chennai

    ReplyDelete
  30. Halo,I'm Helena Julio from Ecuador,I want to talk good about Le_Meridian Funding Investors on this topic.Le_Meridian Funding Investors gives me financial support when all bank in my city turned down my request to grant me a loan of 500,000.00 USD, I tried all i could to get a loan from my banks here in Ecuador but they all turned me down because my credit was low but with god grace I came to know about Le_Meridian so I decided to give a try to apply for the loan. with God willing they grant me loan of 500,000.00 USD the loan request that my banks here in Ecuador has turned me down for, it was really awesome doing business with them and my business is going well now. Here is Le_Meridian Funding Investment Email/WhatsApp Contact if you wish to apply loan from them.Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.com WhatsApp Contact:+1-989-394-3740.

    ReplyDelete
  31. Coworking is an American business model where individuals/organizations work independently under one roof yet share many office facilities and value-added services amongst each other. iSprout is now a leading coworking space in Hyderabad. We have a similar set-up in Vijayawada and Chennai with the vision to become a Pan-India brand. The concept of coworking spaces that started in the USA in 2005 is now a global phenomenon.

    ReplyDelete
  32. Next from Kia is the KIA SONET, comes with wild design, fantastic build quality, thundering speed & what not! Kia sonet features are truly incredible. Know Kia Sonet on road Price in Hyderabad CarKia 36 @ Jubliee Hills.

    ReplyDelete
  33. Thanks for sharing good information about Start VNC automatically. It was extremely helpful. Coworking Office Space in Noida

    ReplyDelete
  34. Thanks for sharing good information about Start VNC automatically. It is extremely helpful. Coworking Office in Noida

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Thank you for sharing. I am so very inspired by your story. I have a mountain of student loans and other consumer debt that is screaming at me and that I need to pay off. After making a mess of my finances, I woke up and wanted to be home with my children. I’ve been home for 4 years, but have to get from under this mountain. Your post was filled with great information. It’s a lot to digest, but will definitely save this to reference over and over as I move forward.


    Harold Burton

    ReplyDelete
  37. "I needed to take a minute to thank you. Your guide convinced me to go ahead and finally start my own blog. I wanted it to look professional from day 1 and I must say that it has been a great hit ever since I launched. Your guide has helped me incredibly much, and I am so grateful you put it together for people like me. Keep up the awesome work. Thanks again and greetings from Germany.Joseph Donahue

    ReplyDelete
  38. Very useful & enlightening post! Thank you very much for sharing. You can check-Spiritual Maturity: 7 Steps to Be More Spiritually Mature

    ReplyDelete
  39. Great Share!

    First off, congratulations on this post. If You are searching for latest government jobs in India. Other department for state and central government job. This bucket list for you to know the right jobs detail.

    This is really awesome but that's what you always crank out my friend. Reading your story got my face leaking and my heart singing. Find qualification based government job and vacancies with employment news at: vacancysquare.com

    All the best, I’m excited to watch your journey! Keep it works and share your amazing thoughts.

    Great share and thanks again for the mention here,

    Thanks and Regards!
    Vacancysquare

    ReplyDelete
  40. Thats a very long and informative post. You where on point from the onslaught, choosing domain names, niche etc to readership and improving your blog. useful content from any upcoming blogger.
    Kelly Hubbard

    ReplyDelete
  41. Having a office can boost your productivity because it gives you the positive environment to work and of course when you sit on a chair with a proper working mindset then it feels even more product and excellent to work, well for all those who are looking for the Our Office you can visit here to check out the best available options for you.

    ReplyDelete
  42. Very Nice and Knowledgeable content. Will create a lot among the people. In case you are looking for Best Co Working Space in Noida sector 63 with all basic amenities, visit us.

    ReplyDelete
  43. Experience the perfect blend of work and community in Bangalore's top Coworking Spaces. Discover flexible membership options and a range of amenities tailored to your needs.

    ReplyDelete
  44. Discover the ideal fusion of community and work in top office space in Gurgaon. Find membership packages that are flexible and a variety of perks that are suited to your needs.

    ReplyDelete
  45. I found this tutorial incredibly helpful for setting up VNC to start automatically on my Raspberry Pi. The step-by-step instructions made the process easy to follow, and I appreciate the detailed explanations. Kudos to Penguin Tutor for providing the solution!

    If you're looking for more Raspberry Pi tips and tricks, make sure to check out noshtek.com as well. They have a wealth of valuable information for Raspberry Pi enthusiasts. Thanks again for sharing this useful guide!

    ReplyDelete