0

I would like to run some simple commands after system loads, but without editing SquashFS of Ubuntu.

Perfect way would be to have ISO written to USB and just add one simple script on this USB, something like RUN_AFTER_START.sh that would be run after the Ubuntu starts.

Is there any way to do it?

  • Why do you not want to edit the SquashFS? What's your reason for using a live CD rather than installing Ubuntu? What's your reason for using a CD rather than a USB media? Is it a usable option for you to use GRUB and modify the GRUB configuration? – kasperd Jan 12 at 16:44
  • Why is this question tagged 16.10? Ubuntu 16.10 has been out of support for more than a year. – kasperd Jan 12 at 16:46
  • I meant 18.10 - fixed. – Mr. P Jan 12 at 16:59
  • @kasperd, I meant LiveUsb - fixed. About why not messing around SquashFS - it is pointless to extract squashfs, change one bit and compress it just to make one simple change. LiveUSB and not installation - i just cannot install ubuntu. I can only use it as LiveUSB. About GRUB - I am not sure if grub will allow me to use Ubuntu apps like apt etc? – Mr. P Jan 12 at 17:07
  • Why can't you install Ubuntu? It is possible to install Ubuntu on a USB media and run it from there. It is even possible to boot the live system from a USB media and then install Ubuntu on the media you just booted from. As far as I recall the live USB medias do use GRUB as the boot loader, so you could edit the GRUB menu to change how it boots. – kasperd Jan 12 at 17:17
1

You can make a persistent live drive. I suggest Ubuntu 18.04.1 LTS, using mkusb

  • If you run standard Ubuntu live, you need an extra instruction to get the repository Universe. (Kubuntu, Lubuntu ... Xubuntu have the repository Universe activated automatically.)

    sudo add-apt-repository universe  # only for standard Ubuntu
    
    sudo add-apt-repository ppa:mkusb/ppa  # and press Enter
    sudo apt-get update
    
    sudo apt-get install mkusb mkusb-nox usb-pack-efi
    
  • Run mkusb-dus in order to create the persistent live drive

     dus ubuntu-18.04.1-desktop-amd64.iso
    

Boot into the persistent live drive

  • Activate the repository 'universe' (good for many application programs, including espeak that I use for a demo example)

    sudo add-apt-repository universe
    sudo apt update
    sudo apt install espeak
    
  • Edit crontab: Select the simple editor nano

    crontab -e
    

    and add the line (you need full path to the command)

    @reboot                 /usr/bin/espeak 'I am ready now'
    

    exit and save.

  • Reboot and you should hear the computer say 'I am ready now' just before you will see the desktop.


If you want to run a desktop application program I suggest that you use autostart, add a desktop file into the directory

/etc/xdg/autostart
  • @reboot runs quite early during boot. Depending on what command you want to run it's quite possible the services it depends on haven't started yet. – kasperd Jan 12 at 20:02
  • @kasperd, you are right. And if that is the case for our OP, we may have to work out more details about autostart (even if it is not a desktop application program, or should I say a program with a graphical user interface). – sudodus Jan 12 at 21:30
  • Thanks guys for help. I have used the easiest (i think :) ) approach - persistence. I got, however, multiple problems with mkusb but it was probably with wrong selection of items (GPT, MSDOS, uefi and so on...). Anyway, in the end I managed to get it working. Currently i have 1 question: With 'persistent' and 'toram' options in grub, is the persistence overlay loaded to RAM as well or only linux image is loaded to ram and the rest is on usb? – Mr. P yesterday
  • When running (and when there is enough RAM), things that are used are in RAM. ToRAM makes the squash file system load into RAM at boot (instead of loading things, when needed). Normally the partition with the image of the iso file, /dev/sdb4, is mounted on /cdrom, but with toram /dev/shm is mounted on /cdrom as you can see with the command df. But the casper-rw partition is still mounted, this is where things are stored (maybe not directly, it is probably buffered in RAM, but you cannot disconnect the persistent live USB drive). – sudodus yesterday
  • On the other hand, in a live-only system (booted without persistence), when you boot with toram, the running system is completely detached from the USB drive, so after unmounting other (non-system) partitions you can unplug it. – sudodus yesterday

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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