Merge the OS to use same applications?
No, practically speaking. Having two separate operating systems, of different versions, but then setting up that you can use binaries from another version in a different operating system would 1) in many cases be impossible because of binary incompatibility and/or wrong or unavailable dependencies or 2) be technically very complicated to setup, and then still with significant more risk of unexpected issues.
Yes, in principle, you could mount the system partition of the other operating system, and run some simple binaries directly in the other operating system. The majority of binaries, however, are far more complex, and depend on specify system configurations and dependencies. They will not run when you try to execute them from a different operating system. Someone very proficient in linux still may be able to get some of this to work as a hobby - it is an exercise that would need to be repeated for each and every application individually.
So is there any way to share the applications installed in Kubuntu is also used in Ubuntu without reinstalling the same software in Ubuntu again and so I on't have to switch between OS's.
As you wrote it here, yes.
Maintain a single operating system, and install both Gnome Shell, the shell of standard Ubuntu, and KDE Plasma, the shell of Kubuntu, on it. Any application you install will then be available whichever desktop you are logged in to.
Yes, you can run software from multiple Ubuntu installs at the same time using a chroot. There are a few caveats:
- All programs will run under a single kernel.
- Programs in the chroot won't be available by default to the main OS. You'll need to create wrapper scripts to launch them.
- A bunch of tweaks may need to be made to get things running smoothly. At a minimum, file ownership/users/groups will need to be harmonized. What's shown below works on my system. You will likely need to make additional tweaks that I can't foresee.
To set up a chroot you'll need to do the following:
-
Boot into the Kubuntu install.
-
Install
schroot
:apt-get install schroot
Add the following to
/etc/schroot/schroot.conf
withUSERNAME
changed to your username:[gnome] description=Ubuntu 20.04 directory=/chroot/gnome users=USERNAME groups=root root-groups=USERNAME
-
Add the chroot's root directory to
/etc/fstab
(it's the second line below). Then add bind mounts for system directories and any non-standard mounts that you're using. If you need any special mount options, add them as well. For example:/.media /media none defaults,bind,noauto 0 0 LABEL=gnome /chroot/gnome ext4 defaults,auto,errors=remount-ro 0 0 /proc /chroot/gnome/proc none defaults,rbind,noauto 0 1 /dev /chroot/gnome/dev none defaults,rbind,noauto 0 1 /sys /chroot/gnome/sys none defaults,rbind,noauto 0 1 /var/run/dbus /chroot/gnome/run/dbus none defaults,rbind,noauto 0 1 /var/lock /chroot/gnome/run/lock none defaults,rbind,noauto 0 1 /var/tmp /chroot/gnome/var/tmp none defaults,rbind,noauto 0 1 /tmp /chroot/gnome/tmp none defaults,rbind,noauto 0 1 /home /chroot/gnome/home none defaults,rbind,noauto 0 1 /media /chroot/gnome/media none defaults,rbind,noauto 0 1
-
Create directories:
mkdirhier /.media /chroot/gnome chmod 755 /.media /chroot /chroot/gnome chown root.root /.media /chroot /chroot/gnome
-
Add the following to
/etc/rc.local
:# Make mounts shared mount /.media || true mount /media || true /bin/mount --make-rshared /.media || true # If you have any static mounts under /media, add mount commands for # them here and set them to noauto in /etc/fstab # Mount system directories mount /chroot/gnome/proc || true mount /chroot/gnome/dev || true mount /chroot/gnome/sys || true mount /chroot/gnome/run/dbus || true mount /chroot/gnome/run/lock || true mount /chroot/gnome/var/tmp || true mount /chroot/gnome/tmp || true mount /chroot/gnome/home || true mount /chroot/gnome/media || true # Additional tweaks # (These might not be needed on your system) # Start udevd under gnome # Audio on Chrome won't work without this ( schroot -c gnome -p -u root /etc/init.d/udev start ) || true # Fix pulseaudio killall pulseaudio || true
-
You may need to apply additional tweaks at login time. If needed/appropriate, create the following shell script and set it to run at login, i.e. when the desktop environment (KDE or Gnome) starts:
#!/bin/sh # Fix Pulse Audio while pidof pulseaudio ; do killall pulseaudio sleep 1 done schroot -p -c gnome start-pulseaudio-x11 # Uncomment this if you're running KDE4 in the chroot #schroot -p -c KDE4_chroot kded4 & # (additional tweaks may be needed)
-
Harmonize users and groups between the two installs. You can probably get away with just making sure your user (and its group) have the same UID and GID on the two. You'll need to update the appropriate UIDs and GIDs in the chroot's
/etc/passwd
,/etc/group
and/etc/shadow
(make a note of the old UIDs and GIDs). Once that's done, update the numeric IDs in the chroot filesystem; thefind
command's-exec
option along withchown
andchgrp
can help here. -
If you have a daemon that you want to run in the chroot, create the following init script (
/etc/init.d/DAEMON_NAME
, change DAEMON_NAME as appropriate) and make it executable:#!/bin/sh set -e schroot -p -c gnome -u root /etc/init.d/DAEMON_NAME $@ exit 0
Then add the following to the end of
/etc/rc.local
:/etc/init.d/DAEMON_NAME restart
-
Add shell scripts to start any programs in the chroot that you want to run as a regular user. Don't forget to make them executable. If desired, you can add a desktop icon to launch the wrapper script. For example:
/usr/local/bin/chrome_gnome
:#!/bin/sh mkdir $HOME/.chrome_gnome || true schroot -p -c gnome -- google-chrome --user-data-dir=$HOME/.chrome_gnome "$@"
-
Reboot the system and everything should work. To run a command in the chroot either use the wrapper you set up in the previous step or just manually run the
schroot ...
command from the commandline.
You'll need to adjust all of the above to suit your system. For example, you'll probably want to merge the contents of your two home directories into a single directory mounted in both installs. Do this before making any bind mounts (or rebooting) since existing files under the mount point won't be visible once the bind mount is made (they'll still be there on disk but won't be accessible).
If you need to install or update software in the chroot simply use schroot -p -c gnome -u root
then run apt
, etc. as normal.
Additional parallel Ubuntu installs can be made. Use debootstrap
to do the initial install into a new directory then add it as shown above.
If you want to be able to click on links in a chrooted application and have them open using the base OS's default handler you'll need to make a few more changes. Note that after doing this things won't work correctly if you directly boot the OS that has been chrooted.
-
Create a shell script
/usr/local/bin/xdg-open-relay-receive
and make it executable:#!/bin/sh mkfifo -m 666 /tmp/xdg-open-relay tail -f "/tmp/xdg-open-relay" | while read line do xdg-open "$line" done
You might want to edit the above to tighten up the permissions on
/tmp/xdg-open-relay
. -
Add the following to the end of the script you created to run at login time:
killall xdg-open-relay-receive nohup /usr/local/bin/xdg-open-relay-receive &
-
Replace the chroot's
xdg-open
command with a new shell script:-
mv /chroot/gnome/usr/bin/xdg-open /chroot/gnome/usr/bin/xdg-open.DISABLED
-
Write the following to
/chroot/gnome/usr/bin/xdg-open
and make it executable:#!/bin/sh echo "$@" > /tmp/xdg-open-relay
-