remove requirement to unplug usb after live session

Asked by vidtek99@gmail.com

I have a requirement to shut the machine down and restart after returning to the premises with restricted physical access where I can't get back in until security will allow. Using a customised persistence usb stick.

I would like to edit the grub.cfg file to remove the requirement to press enter after removing media by adding "noprompt" after quiet splash.
This works when manually editing the grub options on boot, but it still requires the stick to be physically removed and re-inserted in order to boot again to the usb stick.

I have scoured the internet for answers and others have asked this question in many forums, but not a single answer. I have read and re-read man pages and how-tos until I have spots before the eyes nobody seems at be able to solve this.

My customised usb is generated with Cubic then burned by MKUSB with persistence options. The base distribution for cubic is neon-user-20211021-0945.iso

The persistence works beautifully and works for my situation. I do not want a complete install on the USB stick, I want to use persistence.

My requirement is very simple. Remove both the prompt and the need to remove the stick to reboot.

Question information

Language:
English Edit question
Status:
Solved
For:
Cubic Edit question
Assignee:
No assignee Edit question
Solved by:
vidtek99@gmail.com
Solved:
Last query:
Last reply:
Revision history for this message
vidtek99@gmail.com (vidtek99) said :
#1

On rebooting the prompt (paraphrasing) to press Enter then remove usb stick can be eliminated by editing the grub.cfg file.

In order to edit the file you will need to use another linux environment and edit the file /boot/grub/grub.cfg

scroll down to the menu entry you want to use (normally the first one) and where it says "quiet splash" put "noprompt"

I normally remove the "quiet" entry as I like to see what happens during boot.

This was suggested by "Sudodus" at the ubuntu forums, many thanks to him.

Revision history for this message
Cubic PPA (cubic-wizard) said :
#2

@vidtek99,

Glad you got it working.

Make sure you mark your question as "Solved," otherwise Launchpad will automatically delete the question if it remains "Open" for too long.

Revision history for this message
vidtek99@gmail.com (vidtek99) said (last edit ):
#3

The main issue is not resolved.

Sudodus solution just removed the prompt, it didn't resolve the main issue of having to physically remove the. usb stick and replug it back in.

Revision history for this message
vidtek99@gmail.com (vidtek99) said :
#4

After more research, this script written by Patrick Cronin from this answer on Stackechange:

https://askubuntu.com/questions/1036341/unplug-and-plug-in-again-a-usb-device-in-the-terminal

seems to do the trick on a working system, but where would it need to be inserted/called from within a cubic environment to activate on shutdown without hanging the machine?

#!/bin/bash

port="usb1" # replace '1' with actual bus number as shown by lsusb -t: {bus}-{port}(.{subport})

bind_usb() {
  echo "$1" >/sys/bus/usb/drivers/usb/bind
}

unbind_usb() {
  echo "$1" >/sys/bus/usb/drivers/usb/unbind
}

unbind_usb "$port"
# sleep 1 # enable delay here
bind_usb "$port"

Revision history for this message
vidtek99@gmail.com (vidtek99) said :
#5

OK
That failed miserably. So I tried another tack.

I have been through my mountain of computer stuff and pulled out an Anker 7port with 3 power only usb3 powered hub. https://uk.anker.com/products/a7515

I tried in my workshop to see if when the power was removed the usb hub was reset as though unplugged from the host computer.

It was, the little blue active light went off, the hub was disconnected and I was able to reboot the computer without physically unplugging the usb stick.

So a work-around, not the most elegant solution, a software approach built-in to the live system would have been far more elegant but this works for my application. I have tested it with a smart plug and even using google assistant voice control I was able to achieve my goal.
The timing is critical, disconnect too early in the reboot process and it will cause the machine to hang (as the usb stick is the current o/s), too late and the bios boot process will already have started.

If anyone can come up with a way to achieve the same result by removing the way a live system insists on a replug that would be far better.

Tony.

Revision history for this message
Cubic PPA (cubic-wizard) said :
#6

Tony,

I didn't get a chance to test the shut-down process while using a Live USB plugged into the system.

However, I was thinking of a possible software solution...

Run a script at shutdown to force unmount the USB. (You may also be able to do a "lazy" unmount using `umount -l`, so the system ~thinks~ the drive is not mounted).
This way, the system may not detect that a USB is present, and thus, should not prompt the user to remove it.

Revision history for this message
vidtek99@gmail.com (vidtek99) said :
#7

@Cubic PPA

Thanks for the suggestion, I tried a couple of shutdown scripts to achieve this, but the problem was they ran on shutdown while the system is still operating from the live system on the usb stick.

It all ends very messy with a completely hung system and pressing the computer power switch off to reset it.

So it's a bit chicken and egg....

That's why using the hardware the poweroff has to be timed critically in the period immediately after the o/s no longer has sway over the system, and re-powered on immediately before the bios is activated.

Not a long time interval, it's about 7 seconds on my machines.

Revision history for this message
Cubic PPA (cubic-wizard) said :
#8

If you are using the `umount` command, try with the `-l` option.

Revision history for this message
vidtek99@gmail.com (vidtek99) said :
#9

@Cubic PPA

Thanks for the suggestion, it isn't unmounting that's the issue, it's completely resetting this particular USB bus.

The hardware work-around I found is working (after a fashion) I just have to be on my toes to judge the timing correctly.

Cheers Tony.