Skip to content

Commit f226660

Browse files
Merge pull request #9919 from msaenzbosupport/patch-40
AB#7934: Refactor GRUB configuration documentation formatting
2 parents 88a6067 + 44c3177 commit f226660

3 files changed

Lines changed: 70 additions & 157 deletions

File tree

62.5 KB
Loading
13.4 KB
Loading

support/azure/virtual-machines/linux/serial-console-grub-proactive-configuration.md

Lines changed: 70 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Other extensions such as Custom Script are available however these options requi
6262

6363
Ensuring you have access to the Azure Serial Console and GRUB means that a password change or an incorrect configuration can be rectified in a matter of minutes instead of hours. You could even force the VM to boot from an alternative kernel should you have multiple kernels on disk in the scenario where your primary kernel becomes corrupt.
6464

65-
:::image type="content" source="media/serial-console-grub-proactive-configuration/more-kernel.png" alt-text="Screenshot of the boot selected OS screen in GRUB, which shows multiple kernels can be chosen.":::
65+
:::image type="content" source="media/serial-console-grub-proactive-configuration/more-kernel-updated.png" alt-text="Screenshot of the boot selected OS screen in GRUB, which shows multiple kernels can be chosen.":::
6666

6767
## Suggested order of recovery methods
6868

@@ -96,19 +96,25 @@ To configure the VM to accept a reboot via SysRq commands on the Azure portal, y
9696

9797
For this configuration to persist a reboot, add an entry to the file **sysctl.conf**
9898

99-
`echo kernel.sysrq = 1 >> /etc/sysctl.conf`
99+
```bash
100+
sudo echo kernel.sysrq = 1 >> /etc/sysctl.conf
101+
```
100102

101103
To configure the kernel parameter dynamically
102104

103-
`sysctl -w kernel.sysrq=1`
105+
```bash
106+
sudo sysctl -w kernel.sysrq=1
107+
```
104108

105109
If you don't have **root** access or sudo is broken, it will not be possible configure sysrq from a shell prompt.
106110

107111
You can enable sysrq in this scenario using the Azure portal. This method can be beneficial if the **sudoers.d/waagent** file has become broken or has been deleted.
108112

109113
Using the Azure portal Operations -> Run Command -> RunShellScript feature, requires the waagent process be healthy you can then inject this command to enable sysrq
110114

111-
`sysctl -w kernel.sysrq=1 ; echo kernel.sysrq = 1 >> /etc/sysctl.conf`
115+
```bash
116+
sudo sysctl -w kernel.sysrq=1 ; sudo echo kernel.sysrq = 1 >> /etc/sysctl.conf
117+
```
112118

113119
As shown here:
114120

@@ -124,7 +130,7 @@ Select **Reboot** and **Send SysRq** Command
124130

125131
The system should log a reset message such as this
126132

127-
:::image type="content" source="media/serial-console-grub-proactive-configuration/retting-log.png" alt-text="Screenshot of the reset message log in the command-line interface.":::
133+
:::image type="content" source="media/serial-console-grub-proactive-configuration/reset.png" alt-text="Screenshot of the reset message log in the command-line interface.":::
128134

129135
## Ubuntu GRUB configuration
130136

@@ -135,7 +141,7 @@ By default you should be able to access GRUB by holding down **Esc** key during
135141
Update the file /etc/default/grub.d/50-cloudimg-settings.cfg to keep the GRUB menu on screen for the specified TIMEOUT.
136142
You aren't required to hit **Esc** as GRUB will be displayed immediately.
137143

138-
```console
144+
```output
139145
GRUB_TIMEOUT=5
140146
GRUB_TIMEOUT_STYLE=menu
141147
```
@@ -147,45 +153,23 @@ Similar behavior can be experienced by making changes to the file
147153

148154
Comment out these two lines:
149155

150-
```console
156+
```output
151157
#GRUB_HIDDEN_TIMEOUT=0
152158
#GRUB_HIDDEN_TIMEOUT_QUIET=true
153159
```
154160

155161
and add this line:
156162

157-
```console
163+
```output
158164
GRUB_TIMEOUT_STYLE=countdown
159165
```
160166

161-
## Ubuntu 12\.04
162-
163-
Ubuntu 12.04 will allow access to serial console but doesn't offer the ability to interact.
164-
A **login:** prompt isn't seen
165-
166-
For 12.04 to obtain a **login:** prompt:
167-
168-
1. Create a file called /etc/init/ttyS0.conf containing the following text:
169-
170-
```console
171-
# ttyS0 - getty
172-
#
173-
# This service maintains a getty on ttyS0 from the point the system is
174-
# started until it is shut down again.
175-
start on stopped rc RUNLEVEL=[12345]
176-
stop on runlevel [!12345]
177-
178-
respawn
179-
exec /sbin/getty -L 115200 ttyS0 vt102
180-
```
181-
182-
2. Ask upstart to start the getty
183-
184-
```console
185-
sudo start ttyS0
186-
```
167+
Make sure the [email protected] is enabled so that systemd provides a login prompt on that console:
187168

188-
The settings required to configure serial console for Ubuntu versions can be found [here](https://help.ubuntu.com/community/SerialConsoleHowto)
169+
```
170+
sudo systemctl enable [email protected]
171+
sudo systemctl start [email protected]
172+
```
189173

190174
## Ubuntu Recovery Mode
191175

@@ -205,7 +189,7 @@ Select the line displaying *(recovery mode)* don't press enter but press "e"
205189

206190
Locate the line that will load the kernel and substitute the last parameter **nomodeset** with destination as **console=ttyS0**
207191

208-
```console
192+
```output
209193
linux /boot/vmlinuz-4.15.0-1023-azure root=UUID=21b294f1-25bd-4265-9c4e-d6e4aeb57e97 ro recovery nomodeset
210194
211195
change to
@@ -222,164 +206,89 @@ If all goes well you will see these additional Options, which can help perform o
222206

223207
## Red Hat GRUB configuration
224208

225-
## Red Hat 7\.4\+ GRUB configuration
209+
## Red Hat 8\.6\+ GRUB configuration
226210

227-
The default /etc/default/grub configuration on these versions is adequately configured
211+
The default /etc/default/grub configuration on these versions is adequately configured.
228212

229-
```console
230-
GRUB_TIMEOUT=5
231-
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
232-
GRUB_DEFAULT=saved
233-
GRUB_DISABLE_SUBMENU=true
234-
GRUB_TERMINAL="serial console"
235-
GRUB_SERIAL_COMMAND="serial"
236-
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0"
237-
GRUB_DISABLE_RECOVERY="true"
238-
```
239-
240-
Enable the SysRq key
241-
242-
```console
243-
sysctl -w kernel.sysrq=1;echo kernel.sysrq = 1 >> /etc/sysctl.conf;sysctl -a | grep -i sysrq
244-
```
245-
246-
## Red Hat 7\.2 and 7\.3 GRUB configuration
247-
248-
The file to modify is /etc/default/grub – a default config looks like this example:
249-
250-
```console
251-
GRUB_TIMEOUT=1
213+
```output
214+
GRUB_TIMEOUT=10
252215
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
253216
GRUB_DEFAULT=saved
254217
GRUB_DISABLE_SUBMENU=true
255218
GRUB_TERMINAL_OUTPUT="console"
256-
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0"
219+
GRUB_CMDLINE_LINUX="crashkernel=auto console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300"
257220
GRUB_DISABLE_RECOVERY="true"
258-
```
259-
260-
Change the following lines in /etc/default/grub
261-
262-
```console
263-
GRUB_TIMEOUT=1
264-
265-
to
266-
267-
GRUB_TIMEOUT=5
268-
```
269-
270-
```console
271-
GRUB_TERMINAL_OUTPUT="console"
272-
273-
to
221+
GRUB_ENABLE_BLSCFG=true
274222
223+
GRUB_TIMEOUT_STYLE=countdown
275224
GRUB_TERMINAL="serial console"
225+
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
276226
```
277227

278-
Also add this line:
228+
Make sure the [email protected] is enabled so that systemd provides a login prompt on that console:
279229

280-
```console
281-
GRUB_SERIAL_COMMAND="serial –speed=115200 –unit=0 –word=8 –parity=no –stop=1"
282230
```
283-
284-
/etc/default/grub should now look similar to this example:
285-
286-
```console
287-
GRUB_TIMEOUT=5
288-
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
289-
GRUB_DEFAULT=saved
290-
GRUB_DISABLE_SUBMENU=true
291-
GRUB_TERMINAL="serial console"
292-
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0"
293-
GRUB_DISABLE_RECOVERY="true"
231+
sudo systemctl enable [email protected]
232+
sudo systemctl start [email protected]
294233
```
295234

296-
Complete and update grub configuration using
297-
298-
`grub2-mkconfig -o /boot/grub2/grub.cfg`
299-
300-
Set the SysRq kernel parameter:
301-
302-
`sysctl -w kernel.sysrq = 1;echo kernel.sysrq = 1 >> /etc/sysctl.conf;sysctl -a | grep -i sysrq`
235+
## SuSE
303236

304-
You can alternatively configure GRUB and SysRq using a single line either in the shell or via the Run Command.
305-
Backup your files before running this command:
237+
## SLES 15 sp5
306238

307-
`cp /etc/default/grub /etc/default/grub.bak; sed -i 's/GRUB_TIMEOUT=1/GRUB_TIMEOUT=5/g' /etc/default/grub; sed -i 's/GRUB_TERMINAL_OUTPUT="console"/GRUB_TERMINAL="serial console"/g' /etc/default/grub; echo "GRUB_SERIAL_COMMAND=\"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\"" >> /etc/default/grub;grub2-mkconfig -o /boot/grub2/grub.cfg;sysctl -w kernel.sysrq=1;echo kernel.sysrq = 1 /etc/sysctl.conf;sysctl -a | grep -i sysrq`
239+
The default /etc/default/grub configuration on these versions is adequately configured.
308240

309-
## Red Hat 6\.x GRUB configuration
241+
```output
242+
GRUB_DEFAULT=0
243+
GRUB_HIDDEN_TIMEOUT=0
244+
GRUB_HIDDEN_TIMEOUT_QUIET=true
245+
GRUB_TIMEOUT=1
246+
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 net.ifnames=0 dis_ucode_ldr earlyprintk=ttyS0 multipath=off nvme_core.io_timeout=240 rootdelay=300 scsi_mod.use_blk_mq=1 USE_BY_UUID_DEVICE_NAMES=1 systemd.unified_cgroup_hierarchy=1"
247+
GRUB_CMDLINE_LINUX=""
310248
311-
The file to modify is /boot/grub/grub.conf. The `timeout` value will determine how long GRUB is shown for.
312249
313-
```console
314-
#boot=/dev/vda
315-
default=0
316-
timeout=15
317-
splashimage=(hd0,0)/grub/splash.xpm.gz
318-
#hiddenmenu
319-
serial --unit=0 --speed=9600
320-
terminal serial
321-
terminal --timeout=5 serial console
250+
GRUB_DISTRIBUTOR="SLES15-SP5"
251+
GRUB_GFXMODE=auto
252+
GRUB_TERMINAL_INPUT="serial"
253+
GRUB_TERMINAL_OUTPUT="serial"
254+
GRUB_TIMEOUT_STYLE=countdow
322255
```
323256

324-
The last line *terminal –-timeout=5 serial console* will further increase **GRUB** timeout by adding a prompt of 5 seconds displaying **Press any key to continue.**
325-
326-
:::image type="content" source="media/serial-console-grub-proactive-configuration/press-any-key-to-continue.png" alt-text="Screenshot shows a console with output.":::
327-
328-
GRUB menu should appear on-screen for the configured timeout=15 without the need to press Esc. Make sure to click in the Console in the Browser to make active the menu and select the required kernel.
329-
330-
:::image type="content" source="media/serial-console-grub-proactive-configuration/select-kernel.png" alt-text="Screenshot shows a console with two Linux options.":::
257+
Make sure the [email protected] is enabled so that systemd provides a login prompt on that console:
331258

332-
## SuSE
259+
```
260+
sudo systemctl enable [email protected]
261+
sudo systemctl start [email protected]
262+
```
333263

334264
## SLES 12 sp1
335265

336266
Either use YaST bootloader as per the official [docs](./serial-console-grub-single-user-mode.md#grub-access-in-suse-sles)
337267

338268
Or add/change to /etc/default/grub the following parameters:
339269

340-
```console
341-
GRUB_TERMINAL=serial
342-
GRUB_TIMEOUT=5
343-
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=9600 --parity=no"
344-
345-
```console
346-
Verify that ttys0 is used in the GRUB_CMDLINE_LINUX or GRUB_CMDLINE_LINUX_DEFAULT
347-
348-
```console
349-
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,9600n"
270+
```output
271+
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 net.ifnames=0 dis_ucode_ldr earlyprintk=ttyS0 multipath=off nvme_core.io_timeout=240 rootdelay=300 scsi_mod.use_blk_mq=1 USE_BY_UUID_DEVICE_NAMES=1 systemd.unified_cgroup_hierarchy=1"
272+
GRUB_TERMINAL_INPUT="serial"
273+
GRUB_TERMINAL_OUTPUT="serial"
274+
GRUB_TIMEOUT=10
275+
GRUB_TIMEOUT_STYLE=countdown
350276
```
351277

352278
Recreate the grub.cfg
353279

354-
`grub2-mkconfig -o /boot/grub2/grub.cfg`
355-
356-
## SLES 11 SP4
357-
358-
The Serial Console appears and displays boot messages but doesn't display a **login:** prompt
359-
360-
Open an ssh session into the VM and update the file **/etc/inittab** by un-commenting this line:
361-
362-
```console
363-
#S0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt102
280+
```bash
281+
grub2-mkconfig -o /boot/grub2/grub.cfg
364282
```
365283

366-
Next run the command
367-
368-
`telinit q`
369-
370-
To enable GRUB, the following changes should be made to /boot/grub/menu.lst
284+
Make sure the [email protected] is enabled so that systemd provides a login prompt on that console:
371285

372-
```console
373-
timeout 5
374-
serial --unit=0 --speed=9600 --parity=no
375-
terminal --timeout=5 serial console
376-
377-
root (hd0,0)
378-
kernel /boot/vmlinuz-3.0.101-108.74-default root=/dev/disk/by-uuid/ab6b62bb--
379-
1a8c-45eb-96b1-1fbc535b9265 disk=/dev/sda USE_BY_UUID_DEVICE_NAMES=1 earlyprinttk=ttyS0 console=ttyS0 showopts vga=0x314
286+
```
287+
sudo systemctl enable [email protected]
288+
sudo systemctl start [email protected]
380289
```
381290

382-
This configuration will enable the message **Press any key to continue** to appear on the console for 5 seconds
291+
This configuration will enable the message **Press any key to continue** to appear on the console for 5 seconds
383292

384293
It will then display the GRUB menu for an additional 5 seconds - by pressing the down arrow you will interrupt the counter and select a kernel you want to boot either append the keyword **single** for single user mode that requires root password to be set.
385294

@@ -396,7 +305,9 @@ If you don't have root password and single user requires you to have a root pass
396305

397306
Remount your / (root) file system RW using the command
398307

399-
`mount -o remount,rw /`
308+
```bash
309+
mount -o remount,rw /
310+
```
400311

401312
:::image type="content" source="media/serial-console-grub-proactive-configuration/bash-remount.png" alt-text="Screenshot shows a console with a re-mount action.":::
402313

@@ -406,7 +317,9 @@ Now you can perform root password change or many other Linux configuration chang
406317

407318
Restart the VM with
408319

409-
`/sbin/reboot -f`
320+
```bash
321+
/sbin/reboot -f
322+
```
410323

411324
## Single User mode
412325

0 commit comments

Comments
 (0)