1

I'm working on making an ISO image I can burn to a USB device as a live system. In order to install to the internal drive of the system that booted the live USB, I have an icon on the desktop to launch the installer.

After installation, I want to remove the icon. In order to do this, I was going to make a script that detected whether the system was running as a live USB or was actually installed. Is there a way to detect this from BASH?

Thanks!

  • Basically, no guarantees 'cause no actual difference. But can be detected by detect the property of the device your root filesystem reside on, like a overlayfs with the lower fs on a loop device which is on a USB device. udevadm might help. – 炸鱼薯条德里克 Sep 25 '18 at 23:39
3

You can examine the entry for the root file system in /proc/mounts. If you boot from CD, you likely use iso9660 as a file system and have a device like /dev/sr0.

Of course, you can just create a file somewhere as part of the installation and use the presence of this file as an indicator.

  • that /dev/sr0 helped me get to me what I figured out I could do. So thanks! – Batcastle Sep 26 '18 at 13:02
0

I found that you can do lsblk | grep 'sr0' and if it finds that sr0 then more than likely it is running as a live usb. Even if it is actually installed with a live usb plugged in that sr0 only shows up if the live usb is actually booted.

  • The sr0 is a CD, not USB storage. Instead of grep, you could use lsblk /dev/sr0. I get a line for sr0 just for having a CD drive, without even a CD being present in the drive. – RalfFriedl Sep 27 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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