Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want kubuntu to ask me at start up - which of the profile I want to use. There should be a default answer which should run automatically in 3 seconds. Much as if were Grub asking You which operational system You would like to start.

The rational to have several start-up options: normally I have a lot of things starting by default: krusader, firefox, konsole, emacs... So the full loading takes about 1 minute. But sometimes - I'm on the run, and need just to do some single thing - so I'll need only, say krusader. I'd've made several start-up scripts... So I'm wondering - is it possible to choose between them at start up?

Perhaps that could be done with Grub...

Edit:

Grub didn't asked me about the start up profile at all - that is not even "Normal mode" or "Recovery mode". I made him do it with Grub Editor (the package is called kcm-grub2):

sudo sed -i '$ a\deb http://download.opensuse.org/repositories/home:ksmanis/xUbuntu_11.10/ /' /etc/apt/sources.list
wget -q http://download.opensuse.org/repositories/home:ksmanis/xUbuntu_11.10/Release.key -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install kcm-grub2

After the installation and restart, in System settings -> Startup and Shutdown new item has appeared: Grub2 Bootloader. In there - I checked "Automatically choose the default boot entry in 3 seconds".

After that, following the lumbric solution I've copied the gnu-linux menuentry record to the end of the /etc/grub.d/40_custom, and add a "productivity-profile" there. Here's the text of the modified 40_custom:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Full' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        set gfxpayload=$linux_gfx_mode
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set=root 392f79ba-0f1f-422f-ac76-11860e0f4869
        linux   /boot/vmlinuz-3.0.0-16-generic root=UUID=392f79ba-0f1f-422f-ac76-11860e0f4869 ro   quiet splash vt.handoff=7 productivity-profile=1
        initrd  /boot/initrd.img-3.0.0-16-generic
}
menuentry 'Public' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        set gfxpayload=$linux_gfx_mode
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set=root 392f79ba-0f1f-422f-ac76-11860e0f4869
        linux   /boot/vmlinuz-3.0.0-16-generic root=UUID=392f79ba-0f1f-422f-ac76-11860e0f4869 ro   quiet splash vt.handoff=7 productivity-profile=2
        initrd  /boot/initrd.img-3.0.0-16-generic
}
menuentry 'Fastest' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        set gfxpayload=$linux_gfx_mode
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set=root 392f79ba-0f1f-422f-ac76-11860e0f4869
        linux   /boot/vmlinuz-3.0.0-16-generic root=UUID=392f79ba-0f1f-422f-ac76-11860e0f4869 ro   quiet splash vt.handoff=7 productivity-profile=3
        initrd  /boot/initrd.img-3.0.0-16-generic
}

productivity-profile is picked up by the Start-up bash script.

That's it. Now I have 5 start-up profiles: Clean, Recovery, Full, Public, Fastest.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

With the help of @Lekensteyn, I made a version where you can select the profile in GRUB. The creation of the custom menu can be still improved probably.

Step 1: create custom GRUB menu

You need to create GRUB menu entries with an additional parameter. You can follow this instructions. So copy your default entry from /boot/grub/grub.cfg (the lines with menuentry ... { ... }) to /etc/grub.d/40_custom.

Then edit (the copied entry in /etc/grub.d/40_custom) the line where it says linux /boot... and add at the and of a line seperated with a space:

productivity-profile=1

You can also edit the name of the menu entry, so change the part menuentry 'Ubuntu, with... to something like menuentry 'Ubuntu (Profile 1), with....

Add such a menu entry for each of your profiles (with a unique number each).

You can remove the execute permissions from the other files in /etc/grub.d/ in order to remove these menu entries. Don't forget to run sudo update-grub afterwards.

Note that after a kernel update, you'd have to change your grub menu manually if you follow this instructions! (You can improve this answer and describe how to edit the scripts in /etc/grub.d/ accordingly.´)

Step 2: check if Step 1 was successful

Reboot and select one of the profiles. Then run in a terminal:

cat /proc/cmdline 

You should get something like:

BOOT_IMAGE=/boot/vmlinuz-2.6.... root=...  productivity-profile=2

...where the number at the end of the line has to be the chosen profile.

Step 3: Adopt script to your needs and run it on start up

Then use this script to run your start up scripts:

#!/bin/bash    

profile=$(cat /proc/cmdline |sed 's/.*productivity-profile=\([0-9]\).*/\1/g')

echo Running profile $profile ...

case $profile in
   1)
      # Run script for profile 1
      ./script-profile1.sh
      ;;
   2)
      # Run script for profile 1
      ./script-profile2.sh
      ;;
   3)
      # Run script for profile 1
      ./script-profile3.sh
      ;;
   *)
      echo Error
      ;;
esac
share|improve this answer
2  
Suggestions: use grep -Po 'productivity-profile=\K[0-9]' /proc/cmdline (I learned this at unix.se). To avoid having manually to enter the kernel version, see this answer to add extra boot entries for switching nvidia drivers –  Lekensteyn Feb 20 '12 at 22:37
    
Wow, great! I was searching often how to do this with grep, thanks! –  lumbric Feb 21 '12 at 9:34
add comment

You can run the following script on start up:

#!/bin/bash

echo 'Press a key...'
echo '[1] Full profile (default)'
echo '[2] whatever 2'
echo '[3] another one'

read -t 3 -n 1 -p "Choose profile: " profile

echo

case $profile in
   1)
      # Run script for profile 1
      ./script-profile1.sh
      ;;
   2)
      # Run script for profile 1
      ./script-profile2.sh
      ;;
   3)
      # Run script for profile 1
      ./script-profile3.sh
      ;;
   *)
      echo Invalid choice
      ;;
esac

If you want, you can include a loop, so that it asks you again in case of an invalid choice or you can program it entirely in your favourite programming language.

But I agree, it would be more nice to choose the profile in the beginning of the boot process. You could power on the computer, choose the profile and then return when everything is started. But I don't know how to use parameters from GRUB.

share|improve this answer
2  
/proc/cmdline contains the boot options. –  Lekensteyn Feb 20 '12 at 15:42
    
That is very nice. I'm gining it a try! –  Adobe Feb 20 '12 at 16:04
    
Nope - it doesn't work: it doesn't ask me. It just do the default thing. I tried to konsole -e "theScript.bash" - then I can choose the option - but after loading - everything closing again. I tried to append ampersand - no help. –  Adobe Feb 20 '12 at 17:22
    
I also tried to do in with kdialog - but it doesn't have a "use the default after 3 seconds" options. –  Adobe Feb 20 '12 at 17:25
    
@Lekensteyn ah great! Do think it matters if one adds custom (meaningless) parameters in Grub? One could easily use the grub menu for choosing such profile options. –  lumbric Feb 20 '12 at 18:16
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.