Unknown's avatar

About Arturo Gutierrez Loza

Computer Systems & Software Engineer, Systems Administrator providing IT Services to Healthcare Industry Guadalajara, México

Linux: How to verify unexpected system restarts

In Linux, you can verify system restarts and view reboot history using various commands and log files. Here are some methods to check and verify system restarts:

  1. Using the last Command:The last command displays a list of system login entries and system shutdown/reboot times. To view reboot history, run:
    • last reboot The output will show a list of system reboot times, who initiated the reboot, and from which terminal or IP address it occurred.
  2. Checking System Logs:System logs contain information about system events, including reboots. The /var/log/messages or /var/log/syslog file typically contains reboot information. You can use grep to filter the relevant entries:
    • grep 'reboot' /var/log/messages orbashCopy codegrep 'reboot' /var/log/syslog This will display lines indicating system reboots along with timestamps.
  3. Using the uptime Command:The uptime command provides information about system uptime, including the current time, how long the system has been up, and the number of logged-in users. The load average values can also give you an idea if the system recently restarted:
    • uptime If the system uptime is low, it suggests a recent restart.
  4. Checking the /var/log/wtmp File:The /var/log/wtmp file contains a record of all logins and logouts, including system reboots. You can use the last command with the -f option to view this file:
    • last -f /var/log/wtmp This will display a more detailed history of logins, logouts, and reboots.
  5. Using Audit Logs (if configured):If you have the auditd service configured and running, it may log system events, including reboots, in /var/log/audit/audit.log. You can use the ausearch and aureport commands to search for and report on reboot events in the audit log.

These methods should help you verify system restarts and identify when and why they occurred. The choice of method may depend on your specific needs and the availability of logs on your system.

UNIX-Linux: How to identify what type of Unix or Linux System we are using

To identify the type of Unix or Linux system we are using run:

$ uname -a

Linux Example:

[root@redhat9-01 ~]# uname -a
Linux redhat9-01 5.14.0-284.30.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 25 09:13:12 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@redhat9-01 ~]#

AIX Example:

# uname -a

AIX crnimx01 1 7 000482ADD600

#

Linux: Verify file system utilization

To verify file system utilization on Linux, you can use several commands and tools that provide information about disk space usage, including the df and du commands. Here’s how to use each of these commands:

  1. df – Disk Free Space:The df command is a simple and commonly used tool to display information about file system disk space utilization. By default, it shows information about mounted file systems.To display file system utilization information for all mounted partitions, run:
    • df -h The -h option makes the output more human-readable, showing sizes in megabytes (MB) or gigabytes (GB) instead of blocks.
  2. du – Disk Usage:The du command is used to estimate file and directory space usage. It’s helpful for drilling down into specific directories to see which files or directories are consuming the most space.To check the disk usage of a specific directory, navigate to that directory and run:bashCopy codedu -h The -h option, as before, makes the output human-readable.If you want to see the disk usage of the current directory and its subdirectories in a summarized form, you can use the following command:bash
    • du -sh * This will display the sizes of the subdirectories and files in the current directory.

These commands will help you verify file system utilization on your Linux system and identify which directories or file systems are consuming the most disk space. Depending on your needs, you can choose the most suitable command for your analysis.

Linux: To create an ext4 file system on Linux using LVM (Logical Volume Manager), follow these steps:

To create an ext4 file system on Linux using LVM (Logical Volume Manager), follow these steps:

  1. Install LVM Tools (if not already installed): Ensure that the LVM tools are installed on your system. You can install them using your package manager. On Debian/Ubuntu, you can use apt, and on Red Hat/CentOS, you can use yum:
    • For Debian/Ubuntu
      • sudo apt-get install lvm2
    • For Red Hat/CentOS
      • sudo yum install lvm2
  2. Create Physical Volumes (PVs): Start by creating one or more physical volumes on your available storage devices, such as hard drives or partitions. Replace /dev/sdX with the appropriate device names:bash
    • sudo pvcreate /dev/sdX
  3. Create a Volume Group (VG): After creating one or more physical volumes, you can create a volume group that combines these physical volumes into a single pool of storage. Replace myvg with your desired volume group name:bash
    • sudo vgcreate myvg /dev/sdX1 /dev/sdX2 # Use the appropriate device names
  4. Create Logical Volumes (LVs): Now, create one or more logical volumes within the volume group. Specify the size and name for each logical volume. Replace /dev/myvg/mylv with your desired logical volume name and size:bash
    • sudo lvcreate -n mylv -L 10G myvg # Replace 10G with your desired size
  5. Create the ext4 File System: You can create the ext4 file system on the logical volume you just created using the mkfs.ext4 command:bash
    • sudo mkfs.ext4 /dev/myvg/mylv
  6. Mount the ext4 File System: Create a mount point where you want to access the ext4 file system and then mount it:bash
    • sudo mkdir /mnt/myext4 sudo mount /dev/myvg/mylv /mnt/myext4
  7. Add Entry to /etc/fstab (Optional): To make the mount persistent across reboots, add an entry to the /etc/fstab file:bash
    • echo "/dev/myvg/mylv /mnt/myext4 ext4 defaults 0 2" | sudo tee -a /etc/fstab Replace /dev/myvg/mylv and /mnt/myext4 with your logical volume and mount point.
  8. Verify and Use: You can now verify that the ext4 file system is mounted correctly and start using it:bash
    • df -h This command will show you the available disk space on the mounted ext4 file system.

That’s it! You’ve created an ext4 file system on a logical volume managed by LVM. You can adjust the sizes and names to fit your specific requirements.

Linux boot troubleshooting

Troubleshooting a Linux system that does not boot can be a complex process, and the steps you take will depend on the specific symptoms and hardware involved. Here’s a general guide to help you diagnose and potentially fix the issue:

  1. Check Hardware Connections:
    • Ensure that all cables and hardware components (such as RAM, hard drive, power cables) are properly connected.
  2. Check BIOS/UEFI Settings:
    • Access your system’s BIOS/UEFI settings and make sure the boot order is configured correctly, with the system drive as the first boot option.
  3. Boot into Recovery Mode or GRUB:
    • If your system uses GRUB (the boot loader for Linux), try to access the GRUB menu during boot by pressing the appropriate key (usually Esc, Shift, or F2) and boot into recovery mode if available.
  4. Check for Error Messages:
    • Pay attention to any error messages or warnings that appear on the screen during boot. These messages can provide valuable clues about the issue.
  5. Run Hardware Diagnostics:
    • If you suspect a hardware problem, run hardware diagnostics tools if available. Most manufacturers provide these tools, and they can help identify faulty components.
  6. Check for Disk Errors:
    • Use a live Linux distribution (on a USB or CD/DVD) to boot into a live environment. Then, check your system’s hard drive for errors and repair any filesystem issues. You can use commands like fsck or GUI-based tools.
  7. Inspect Grub Configuration:
    • If the issue seems related to GRUB, check its configuration files (usually in /etc/default/grub and /etc/grub.d/) for errors or misconfigurations. You might need to regenerate the GRUB configuration using update-grub.
  8. Examine Kernel Parameters:
    • In GRUB, you can edit kernel parameters to disable graphical boot and enable verbose output. This can help you see where the boot process is failing. Look for kernel panic messages.
  9. Check for Disk Space Issues:
    • Insufficient disk space can sometimes prevent a system from booting. Use a live environment to check the available disk space on your system’s partitions.
  10. Repair Bootloader:
    • If the bootloader is corrupted, you might need to repair it. The method for repairing GRUB or other bootloaders may vary depending on your Linux distribution. Use the appropriate commands or tools to reinstall or repair the bootloader.
  11. Check for Kernel Issues:
    • If the boot process is failing at the kernel stage, you may need to boot into a previous kernel version (if available) or reinstall/update the kernel.
  12. Backup and Restore:
    • If all else fails, consider backing up your important data using a live environment and then reinstalling the Linux distribution.
  13. Logs:
    • Check system logs, such as /var/log/syslog or /var/log/boot.log, for any clues about what’s causing the boot failure.
  14. Seek Help Online:
    • If you’re still unable to resolve the issue, consider seeking help on Linux forums or communities. Provide as much detail as possible about the problem and the error messages you’ve encountered.

Remember that diagnosing and troubleshooting boot issues can be complex, and it’s important to be cautious when making changes to your system. Be sure to back up your data before attempting any major fixes, and if you’re unsure about a particular step, seek assistance from experienced users or professionals.