Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3736  / 2 Years ago, sat, december 4, 2021, 2:42:25

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 '$ adeb 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.


More From » grub2

 Answers
6

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

[#40266] Sunday, December 5, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rvousnove

Total Points: 456
Total Questions: 130
Total Answers: 98

Location: El Salvador
Member since Sun, Sep 12, 2021
3 Years ago
;