This topic was published by DevynCJohnson and viewed 1896 times since "". The last page revision was "".
- Topics - 444
The command-line in GRUB2 (a popular bootloader) offers admins a great tool for managing and fixing GRUB as well as other parts of the computer system. The command-line in GRUB is often referred to as "CLI Mode". To access CLI mode, press "C" when GRUB's menu appears. The command-line is a lot like the Bourne-Again Shell (BASH). However, CLI mode does not have all of the features and commands that BASH offers.
CLI mode supports various shortcuts and features. The TAB button is auto-completion for both commands and file/device paths. Pressing Ctrl+Alt+Del will reboot the system without confirmation. Esc takes the user back to the main menu. The arrow keys are self-explanatory. The "print screen" button makes the BIOS speaker beep (not the speakers used in music/videos).
GRUB supports "if" and "while" constructs in the shell. Also, booleans ("true" and "false") are also supported.
The "acpi" command is used to define a different Advanced Configuration and Power Interface (ACPI) Table than what the operating system intends to use.
GRUB contains a very useful and powerful command called "badram". This command notes bad spots on the RAM and the system will refrain from using those regions.
QUICK FACT: To make a rescue disk, run this command in the terminal of a fully booted system as Root -
To know the blocks that a particular file resides within, use the "blocklist" command. To specify a file, reference the partition GRUB's standard style and type the file's path. Example - "blocklist (hd0,3)/PATH/TO/FILE "
NOTE: When specifying files or directories, type the absolute pathname, device, and partition in the form "(hd1,3)/boot/grub/grub.cfg" (for the second hard-drive and 3rd partition).
The "boot" command will boot the loaded OS/chainloader.
The "cat" command will allow a user to view the contents of a specified text file.
"chainloader" allows a user to load a file as the chainloader. To use this command, type "chainloader /PATH/TO/FILE". If the user wishes to load a chainloader that is on the first sector of the current partition, then type "+1" instead of a file path.
"cmp" is used to compare two files. The syntax for this command is "cmp FILE1 FILE2". If the files differ in size or byte arrangement (contents), then the output will specify whether the sizes differ ("Differ in size") or the contents are different ("Differ at the offset").
"configfile" loads the specified configuration file - "configfile /PATH/TO/FILE".
On x86 systems using GRUB, the "cpuid" command returns true if the CPU supports long mode (64-bit). Otherwise, it returns false.
"crc" returns the CRC32 checksum of the specified file.
"date" displays the date and time.
"drivemap" maps the first specified drive to the second specified drive. This is used for some operating systems that are not installed on the first drive, but expect to be on the first drive. The "-s" argument swaps the mappings, "-r" resets all mappings, and "-l" lists the mappings.
The "echo" used by GRUB is the same echo used in BASH.
"export" makes the specified variable a global variable.
"gettext" uses the files in /boot/grub/locale to translate the specified string - "gettext STRING".
"gptsync" syncs GPT's legacy Master Boot Record (MBR) partition table with entries found on the GUID Partition Table (GPT). Some BIOS chips are not compatible with GPT, so GPT uses a legacy MBR table for backwards compatibility. Up to three entries may reside on the legacy MBR. The accepted command syntax is "gptsync DRIVE PARTITION(+/-[TYPE])". The "PARTITION(+/-[TYPE])" may be repeated for each partition. "DRIVE" specifies the device/drive, "PARTITION" indicates the partition, and "TYPE" specifies the MBR partition type code in hexadecimal (starting with "0x"). The "+" and "-" indicate whether the partition is active or inactive, respectively. Only one partition may be active.
"halt" is used to shutdown the system.
"help" is used to print various information about the commands.
"initrd" is used to load an initial ramdisk for Linux after the "linux" command has executed.
"initrd16" is the same as "initrd", but this is for 16-bit mode. This command can only be run after the "linux16" command.
"insmod" is used to load/insert the specified GRUB module. The modules are typically in a directory under /boot/grub/ and the files end in "*.mod".
"keystatus" is used for scripting. "keystatus --shift" returns "true" if the shift-key is pressed. "keystatus --ctrl" returns "true" if the ctrl-key is pressed. "keystatus --alt" returns "true" if the alt-key is pressed. If no parameters are used, then "true" will be returned if any of the keys are pressed (if the hardware supports checking the key modifier status).
"linux" loads the specified kernel image. Any parameters after the filename are passed to the Linux kernel.
"linux16" is used to boot 16-bit Linux kernels using the 16-bit boot protocol. This command is only available on x86 systems.
"list_env" lists all variables that are in the environment block file.
Variables can be loaded from the environment block file by using the "load_env" command.
"loopback" is used to create a loopback device that is used to access a filesystem that is within a file (such as an *.img file). The accepted syntax is "loopback loop0 /FILE/PATH". "loopback -d" will delete the previously created loopback device.
"ls" lists the files and folders of the current-working directory or all of the devices that GRUB recognizes on the current system.
"normal" loads GRUB's normal-mode which includes loading filesystem modules, cryptography modules, and other features.
"normal_exit" takes GRUB out of normal-mode.
"parttool" is used to make various modifications to the entries on the specified partition on an MBR table. The accepted syntax is "parttool PARTITION COMMANDS"."+" is used as the boolean "true" and "-" is "false". The command "boot BOOLEAN" is used to make a partition bootable or non-bootable. "hidden BOOLEAN" can make a partition hidden or not hidden. "type 0xHEX" is used to set the partition type.
"password" is used to create a user and password (or change the password) - password USER PASSWD.
"password_pbkdf2" is like the "password" command, but this command uses a hashed password instead of a normal password.
"play" is used to play sound. The parameter may be a file path. However, the alternative parameter specifies a tempo (specified using an integer) followed by one or more pitches (in Hertz).
"pxe_unload" unloads the PXE environment on PC systems.
"read" accepts an input from the user. If a variable name (whether already existing or not) is listed after the "read" command, then the user's typed input will become the value of the named variable.
"reboot" is used to restart the system.
"save_env" saves the listed variables to the environment block file.
"search" is used to find a device by file (-f, --file), filesystem label (-l, --label), or filesystem UUID (-u, --fs-uuid). Searching the floppy devices may be slow, so to save time, users can use the "--no-floppy" parameter to skip the floppy devices.
"sendkey" allows a maximum of 16 keystrokes to be stored and sent/submitted to the bootloader as if the user typed those keys. The below listed parameters can be used with this command to simulate certain keys. The "'on'" or "'off'" arguments must be after each parameter. For instance, to simulate turning caps-lock on, the command would be "sendkey --caps 'on'". To prevent the keyboard's LEDs from changing according to the simulated key-presses, append the "--no-led" flag.
When "set" is used without parameters, the environment variables are listed. When "set" is used in a form like "set VAR=VALUE", the variable is set to the defined value.
"unset" deletes/removes a variable.
"uppermem" is a command that is being developed. Therefore, it cannot be used, yet.
- Linux Bootloaders - http://dcjtech.info/topic/linux-bootloaders/
- GRUB and a Little Dash of BURG - http://dcjtech.info/topic/grub-and-a-little-dash-of-burg/
- Grub Modules - http://dcjtech.info/topic/grub-modules/
- Grub Manual - https://www.gnu.org/software/grub/manual/html_node/index.html