Monday, February 25, 2019

Fix GRUB2 Using Ubuntu LiveCD

Here's how:
  1. Boot from the live CD or live USB, in "Try Ubuntu" mode.
  2. Determine the partition number of your main partition. sudo fdisk -lsudo blkid or GParted (which should already be installed, by default, on the live session) can help you here. I'm going to assume in this answer that it's /dev/sda2, but make sure you use the correct partition number for your system!
    If your main partition is in an LVM, the device will instead be located in /dev/mapper/, most likely, /dev/mapper/{volume}--{os}-root where {volume} is the LVM volume name and {os}is the operating system. Execute ls /dev/mapper for the exact name.
  3. Mount your partition:
    sudo mount /dev/sda2 /mnt  #Replace sda2 with the partition from step 2
    
    If you have a separate /boot/var or /usr partitions, repeat steps 2 and 3 to mount these partitions to /mnt/boot/mnt/var and /mnt/usr respectively. For example,
    sudo mount /dev/sdXW /mnt/boot
    sudo mount /dev/sdXY /mnt/var
    sudo mount /dev/sdXZ /mnt/usr
    
    replacing sdXWsdXY, and sdXZ with the respective partition numbers.
  4. Bind mount some other necessary stuff:
    for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    
  5. If Ubuntu is installed in EFI mode (see this answer if you're unsure), use sudo fdisk -l | grep -i efi or GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdXY with the actual partition number for your system:
    sudo mount /dev/sdXY /mnt/boot/efi
    
  6. chroot into your Ubuntu install:
    sudo chroot /mnt
    
  7. At this point, you're in your install, not the live session, and running as root. Update grub:
    update-grub
    
    If you get errors or if going up to step 7 didn't fix your problem, go to step 8. (Otherwise, it is optional.)
  8. Depending on your situation, you might have to reinstall grub:
    grub-install /dev/sda
    update-grub # In order to find and add windows to grub menu.
    
  9. If Ubuntu is installed in EFI mode, and EFI partition UUID has changed, you may need to update it in /etc/fstab. Compare it:
    blkid | grep -i efi
    grep -i efi /etc/fstab
    
    If current EFI partition UUID (from blkid) differs from the one in /etc/fstab, update /etc/fstab with current UUID.
  10. If everything worked without errors, then you're all set:
    exit
    sudo reboot
    
  11. At this point, you should be able to boot normally.
If you cannot boot normally, and didn't do step 8 because there were no error messages, try again with step 8.
  • Sometimes giving GRUB2 the correct configuration for your partitions is not enough, and you must actually install it (or reinstall it) to the Master Boot Record, which step 8 does. Experience helping users in chat has shown that step 8 is sometimes necessary even when no error messages are shown.

Sunday, February 3, 2019

Common administrative commands in Red Hat Enterprise Linux 5, 6, and 7

System basics

TaskRHEL5RHEL6RHEL7
View subscription information/etc/sysconfig/rhn/systemid/etc/sysconfig/rhn/systemid
subscription-manager identity
subscription-manager identity
Configure subscriptionrhn_register
subscription-manager 1
rhn_register
rhnreg_ks
subscription-manager
subscription-manager2
rhn_register 3
View RHEL version information/etc/redhat-release
View system profilesosreport
dmidecode
hwbrowser
sosreport
dmidecode
lstopo
lscpu

Basic configuration

TaskRHEL5RHEL6RHEL7
Graphical configuration toolssystem-config-*gnome-control-center
Text-based configuration toolssystem-config-*-tui
Configure printersystem-config-printer
Configure networksystem-config-networknmcli
nmtui
nm-connection-editor
Configure system languagesystem-config-languagelocalectl
Configure time and datesystem-config-date
date
timedatectl
date
Synchronize time and datentpdate
/etc/ntp.conf
timedatectl
/etc/chrony.conf
ntpdate
Configure keyboardsystem-config-keyboardlocalectl
Configure SSH/etc/ssh/ssh_config
/etc/ssh/sshd_config
~/.ssh/config ssh-keygen

Jobs and services

TaskRHEL5RHEL6RHEL7
List all serviceschkconfig --list
ls /etc/init.d/
systemctl -at service
ls /etc/systemd/system/*.service
ls /usr/lib/systemd/system/*.service
List running servicesservice --status-allsystemctl -t service --state=active
Start/stop serviceservice name start
service name stop
systemctl start name.service
systemctl stop name.service
Enable/disable servicechkconfig name on
chkconfig name off
systemctl enable name.service
systemctl disable name.service
View service statusservice name statussystemctl status name.service
Check if service is enabledchkconfig name --listsystemctl is-enabled name
Create new service file or modify configurationchkconfig --addsystemctl daemon-reload
/etc/systemd/system/*.service
View run level/targetrunlevel
who -r
systemctl get-default
who -r
Change run level/target/etc/inittab
init run_level
systemctl isolate name.target
systemctl set-default
Configure logging/etc/syslog.conf/etc/rsyslog.conf/etc/rsyslog.conf
/etc/rsyslog.d/*.conf
/var/log/journal
systemd-journald.service
View logs/var/log/var/log
journalctl
Configure system auditadd audit=1 to kernel cmdline
auditctl
/etc/audit/auditd.conf
/etc/audit/audit.rules
authconfig
/etc/pam.d/system-auth
pam_tty_audit kernel module
View audit outputaureport /var/log/faillog
Schedule/batch taskscron
at
batch
Find file by namelocate
Find file by characteristicfind
Create archivetar
cpio
zip

Kernel, boot, and hardware

TaskRHEL5RHEL6RHEL7
Single user/rescue modeappend 1 or s or init=/bin/bash to kernel cmdlineappend rd.break or init=/bin/bash to kernel cmdline
Shut down systemshutdown
Power off systempoweroffpoweroff
systemctl poweroff
Halt systemhalthalt
systemctl halt
Reboot systemrebootreboot
systemctl reboot
Configure default run level/target/etc/inittabsystemctl set-default
Configure GRUB bootloader/boot/grub/grub.conf/etc/default/grub
grub2-mkconfig
grub-set-default
Configure kernel modulemodprobe
View hardware configuredhwbrowserlshw (in EPEL)
Configure hardware deviceudev
View kernel parameterssysctl -a
cat /proc/cmdline
Load kernel modulemodprobe
Remove kernel modulemodprobe -r
View kernel versionrpm -q kernel
uname -r

Software management

TaskRHEL5RHEL6RHEL7
Install softwareyum install
yum groupinstall
yum install
yum group install
View software infoyum info
yum groupinfo
yum info
yum group info
Update softwareyum update
Upgrade softwareyum upgrade
Configure software repositorysubscription-manager repos
/etc/yum.repos.d/*.repo
Find package owning filerpm -qf filename
yum provides filename-glob
View software versionrpm -q packagename
View installed softwarerpm -qa
yum list installed

User management

TaskRHEL5RHEL6RHEL7
Graphical user managementsystem-config-users
Create user accountuseradd
Delete user accountuserdel
View/change user account detailsusermod
/etc/passwd
vipw
id
Create user groupgroupadd
Delete user groupgroupdel
Change group detailsgroupmod
/etc/group
Change user passwordpasswd
Change user permissionsusermod
visudo
Change group permissionsgroupmod
visudo
Change password policychage
View user sessionsw

File systems, volumes, and disks

TaskRHEL5RHEL6RHEL7
Default file systemext3ext4xfs
Create/modify disk partitionsfdisk
parted
fdisk
gdisk
parted
ssm create
Format disk partitionmkfs.filesystem_type (ext4, xfs)
mkswap
mkfs.filesystem_type (ext4, xfs)
mkswap
ssm create
Defragment disk spacecopy data to new file system
fsck (look for 'non-contiguous inodes')
copy data to new file system
fsck (look for 'non-contiguous inodes')
xfs_fsr
Mount storagemount
/etc/fstab
mount
/etc/fstab
ssm mount
Mount and activate swap/etc/fstab
swapon -a
Configure static mounts/etc/fstab
View free disk spacedf
View logical volume infolvdisplay
lvs
vgdisplay
vgs
pvdisplay
pvs
Create physical volumepvcreatepvcreate
ssm create (if backend is lvm)
Create volume groupvgcreatevgcreate
ssm create (if backend is lvm)
Create logical volumelvcreatelvcreate
ssm create (if backend is lvm)
Enlarge volumes formatted with default file systemvgextend
lvextend
resize2fs
vgextend
lvextend
xfs_growfs
ssm resize
Shrink volumes formatted with default file systemresize2fs
lvreduce
vgreduce
XFS cannot currently be shrunk; copy desired data to a smaller file system.
Check/repair file systemfsckfsck
ssm check
View NFS shareshowmount -e
mount
Configure NFS share/etc/exports
service nfs reload
/etc/exports
systemctl reload nfs.service
Configure on-demand auto-mounts/etc/auto.master.d/*.autofs
/etc/auto.*
Change file permissionschmod
chown
chgrp
umask (future file creation)
Change file attributeschattr
Change access control listsetfacl

Networking

TaskRHEL5RHEL6RHEL7
Configure name resolution/etc/hosts
/etc/resolv.conf
/etc/hosts
/etc/resolv.conf
nmcli con mod
Configure hostname/etc/sysconfig/networkhostnamectl
/etc/hostname
nmtui
View network interface infoip addr
ifconfig
brctl
ip addr
nmcli dev show
teamdctl
brctl
bridge
Configure network interface/etc/sysconfig/network-scripts/ifcfg-*/etc/sysconfig/network-scripts/ifcfg-*
nmcli con [add|mod|edit]
nmtui
nm-connection-editor
View routesip route
Configure routesip route add
system-config-network
/etc/sysconfig/route-iface
ip route add
nmcli
nmtui
nm-connection-editor
/etc/sysconfig/route-iface
Configure firewalliptables and ip6tables
/etc/sysconfig/ip*tables
iptables and ip6tables
/etc/sysconfig/ip*tables
system-config-firewall
firewall-cmd
firewall-config
View ports/socketsss
lsof
netstat
ss
lsof

Security and identity

TaskRHEL5RHEL6RHEL7
Configure system security/etc/selinux/config
chcon
restorecon
semanage
setsebool
system-config-selinux
Report on system securitysealert
LDAP, SSSD, Kerberosauthconfig
authconfig-tui
authconfig-gtk
Network usersgetent

Resource management

TaskRHEL5RHEL6RHEL7
Trace system callsstrace
Trace library callsltrace
Change process prioritynice
renice
Change process run locationtaskset
Kill a processkill
pkill
killall
View system usagetop
ps
sar
iostat
netstat
vmstat
mpstat
numastat
top
ps
sar
iostat
netstat
ss
vmstat
mpstat
numastat
tuna
top
ps
sar
iostat
ss
vmstat
mpstat
numastat
tuna
View disk usagedfdf
iostat