"According to Appendix L of the Racing Rules of Sailing, if Flag D is displayed ashore but not all boats go afloat, how long must Flag D remain displayed before the warning signal can be made, and does this duration depend on what is specified in the Sailing Instructions?"
Flag D with one sound means ‘Boats [are requested not to][shall not] leave the [harbour][shore] until this signal is made. The warning signal will not be made before the scheduled time or less than <number> minutes after flag D is displayed.’
That SI does not state for how long flag D must remain displayed.
Seemingly the race committee may display Flag D with one sound signal then immediately removed the flag.
Alternatively, a protest committee considering redress for a boat that may have unavoidably been unable to hear the sound signal might conclude that the race committee was required to keep the flag displayed for a reasonable time.
Another good reason to use flag G to positively remain ashore while it is displayed.
I have used both Flag "D" and Flag "G" on many, many events.
Which I use depends on the legal responsibilities in the country I am running racing and the port/shore authority rules in the place where the racing is.
In many countries I have no legal responsibility for the safety of the sailors when they are not racing (and in some, even when they are racing!). In these countries I usually use Flag "G", removing it a good time before racing will start. I use it also when I am required to have boats inspected before launching to ensure they have the right kit aboard. I always get a PC member or Jury to follow the last boat out that launches within a reasonable time of the G flag being removed. Once that judge tells me they are on the race course I can go into sequence (as long as in accordance with the not before time in the SIs)
Where I am legally responsible for boats when they are not racing, I use Flag "D" when the support boats are in place and again I use a judge to make sure that all boats that launch within a reasonable time of the D flag being displayed have reached the starting area before I go into sequence. I remove the D Flag once there is no support boat lying off the launching area to ensure the safety of any boat that launches. The Beachmaster can raise it again if they think it is safe for a boat to launch. Often this boat will have a dedicated coach boat, Sometimes my safety officer vill have to send a boat to escort them out. It is then removed again.
The things we now have to do to guard ourselves against claims of negligence!
PS: or as an appendix "Appx ?: Auxiliary Race Signals"
"The following Race Signals are referenced in the Appendices and are only enforce when stated so in a race document governing the event" .. or something.