CentOS/Redhat/Fedora 系統命令:

1. 安装软件源

# 导入public key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org#Centos8
yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm#Centos7
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
# 备份当前repo文件
cp  /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.back
# 下载ali cloud centos 源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 安装扩展仓库
wget -O /etc/yum.repos.d/epel-7.repo wget http://mirrors.aliyun.com/repo/epel-7.repo #Centos8
wget http://mirrors.aliyun.com/repo/Centos-8.repo -O /etc/yum.repos.d/Centos-8.repo
# 下载163 centos 源
wget http://mirrors.163.com/repo/Centos-8.repo -O /etc/yum.repos.d/Centos-8.repo# Fedora:
wget http://mirrors.aliyun.com/repo/fedora.repo -O /etc/yum.repos.d/fedora.repo
或者
wget https://mirrors.163.com/.help/fedora-updates-163.repo
wget https://mirrors.163.com/.help/fedora-163.repoyum clean all
yum makecache
yum update#yum源码包
yum install yum-utils -y
# download rpm
yumdownloader --downloadonly --downloaddir=/tmp bison# download source
yumdownloader --source bison# save to xx.tar.gz
rpm2cpio bison-3.7.6-3.fc35.src.rpm| cpio -id#compile
make//查询 rpm packages
dnf -q provides lib{babeltrace,bpf}-devel

1.1 安装常用tools

# 7z
# apt install  -y  p7zip-full#curl
yum  -y install curl#python3
dnf install python3#cmake
yum install cmake#llvm
yum install llvm lld lldb
dnf install clang#wineyum install wine #apci
# yum install acpica-tools
rpm -ivh http://mirrors.163.com/centos/8/BaseOS/x86_64/os/Packages/acpica-tools-20180629-3.el8.x86_64.rpm#busyboxrpm -ivh  http://rpmfind.net/linux/fedora/linux/releases/33/Everything/x86_64/os/Packages/b/busybox-1.32.0-2.fc33.x86_64.rpm#numactlyum install numactl# tuneyum install tune

2. 安裝 Linux kernel 編譯依賴包

yum install -y dosfstools
yum install -y  grub2-efi-x64-modules.noarch
yum install -y  efibootmgr
yum -y  install gcc  gcc-c++
yum install -y ncurses ncurses-devel
yum install -y elfutils-libelf-devel openssl-devel dwarves make flex bison
yum install -y glibc-static
yum -y install gcc gcc-c++ git python3 nasm iasl libuuid-devel qemu
dnf --enablerepo=powertools install dwarves或者
yum install -y gcc gcc-c++ git python3 nasm iasl libuuid-devel dosfstools ncurses ncurses-devel elfutils-libelf-devel openssl-devel dwarves make flex bison glibc-static

3. 安装GUI

yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target4. 編譯Linux kernel
//下载linux-4.18.1.tar.xz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.18.1.tar.gz //解压linux-4.18.1.tar.xz
tar xvf linux-4.18.1.tar.gz -C /usr/src//切换内核解压目录下
cd /usr/src/linux-4.18.1//制作.config
# make mrproper
cp /boot/config-4.6.3-fc32.x86_64 /usr/src/linux-4.18.1/.config
make olddefconfig
或者
make menuconfig//编译kernel
make all//安装模块/内核
make modules_install
make install
reboot

5. 製作busybox命令

CSDN=/root/csdn
TOP_BUILD=$CSDN/build
mkdidr -p $TOP_BUILD
cd $CSDN#下载解压busybox源码
wget  https://busybox.net/downloads/busybox-1.26.2.tar.bz2  --no-check-certificate
tar xjf busybox-1.26.2.tar.bz2 #生成.config
cd $CSDN/busybox-1.26.2
mkdir -pv $TOP_BUILD/obj/busybox-x86
make O=$TOP_BUILD/obj/busybox-x86 defconfigmake O=$TOP_BUILD/obj/busybox-x86 menuconfig
sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" $TOP_BUILD/obj/busybox-x86/.config
(或者Busybox Settings  ---> Build BusyBox as a static binary (no shared libs).)cd $TOP_BUILD/obj/busybox-x86
make -j2
make installmkdir -pv $TOP_BUILD/initramfs/x86-busybox
cd $TOP_BUILD/initramfs/x86-busybox
mkdir -pv {bin,dev/tty0,sbin,etc,proc,sys/kernel/debug,usr/{bin,sbin},lib,lib64,mnt/root,root}#copy 编译生成的busybox
cp -av $TOP_BUILD/obj/busybox-x86/_install/*  $TOP_BUILD/initramfs/x86-busybox
cp -av /dev/{null,console,tty,sda1} $TOP_BUILD/initramfs/x86-busybox/dev/#创建init文件
cat > $TOP_BUILD/initramfs/x86-busybox/init < EOF
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
#mount -t debugfs none /sys/kernel/debug
mdev -s
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
#exec /bin/sh
exec /sbin/init
EOF
chmod +x $TOP_BUILD/initramfs/x86-busybox/init#创建 ./etc/passwd与 ./etc/group
echo "root::0:0:root:/:/bin/sh" > ./etc/passwd
touch  ./etc/group #创建 ./etc/inittab
cat > ./etc/inittab << EOF
::sysinit:/etc/rc.d/rcS
::respawn:/sbin/getty -n -l /bin/sh ttyS0 115200
::respawn:/bin/cttyhack /bin/sh
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
::restart:/sbin/init
EOF#创建 . ./etc/fstab
cat > ./etc/fstab << EOF
proc     /proc    proc     defaults 0 0
sys      /sys     sysfs    defaults 0 0
none     /dev     devtmpfs defaults 0 0
tmpfs    /dev/shm tmpfs    defaults 0 0
none     /dev/pts devpts   defaults 0 0
EOF#创建 . ./etc/hostname
echo "busybox_csdn" >  ./etc/hostname#创建  ./etc/rc.d/rcS
mkdir -p ./etc/rc.d/ && touch ./etc/rc.d/rcSecho '#!/bin/sh
/bin/hostname -F /etc/hostname
/bin/mount /proc               # We need to do this before remounting root
/bin/mount /sys
/bin/mount -o remount,rw /     # Remount read-write
/bin/mount /dev
/bin/mkdir /dev/shm
/bin/mkdir /dev/pts
/bin/mount -a                  # Mount all filesystems in fstab, except those marked with 'noauto'
/sbin/ifconfig lo 127.0.0.1    # Setup loopback interface for network (if you have networking in your kernel)
#/sbin/inetd                    # If you want inetd to run
#/sbin/telnetd                  # If you want standalone telnetd to run -- incompatible with inetd it seems
' > ./etc/rc.d/rcS
chmod +x ./etc/rc.d/rcS#创建 tty设备文件
mknod ./dev/tty1 c 4 1
mknod ./dev/tty2 c 4 2
mknod ./dev/tty3 c 4 3
mknod ./dev/tty4 c 4 4
ls -l ./dev/tty[0-9]#打包initramfs
cd $TOP_BUILD/initramfs/x86-busybox
find . -print0 | cpio --null -ov --format=newc     | gzip -9 > $TOP_BUILD/obj/initramfs-busybox-x86.cpio.gz#对U盘前500MB清零dd if=/dev/zero of=/dev/sdb  bs=1M count=512;    #对U盘(/dev/sdb)进行分区
gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 60062433 sectors (28.6 GiB)Number  Start (sector)    End (sector)  Size       Code  NameCommand (? for help): n
Partition number (1-128, default 1):
First sector (34-60062466, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-60062466, default = 60062466) or {+-}size{KMGTP}: 110MiB
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to 'EFI System'Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 59839200 sectors (28.5 GiB)Number  Start (sector)    End (sector)  Size       Code  Name1            2048          225280   109.0 MiB   EF00  EFI SystemCommand (? for help): n
Partition number (2-128, default 2):
First sector (34-60062466, default = 227328) or {+-}size{KMGTP}:
Last sector (227328-60062466, default = 60062466) or {+-}size{KMGTP}: 400MiB
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 59247327 sectors (28.3 GiB)Number  Start (sector)    End (sector)  Size       Code  Name1            2048          225280   109.0 MiB   EF00  EFI System2          227328          819200   289.0 MiB   8300  Linux filesystemCommand (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@localhost ~]##对U盘(/dev/sdb)进行格式化
fdisk -l  /dev/sdb
mkfs.vfat  -F 32 -s 2 /dev/sdb1
mkfs.ext3 /dev/sdb2#对U盘安装bootloader这里用grub tool,也可以使用LILO
mkdir -p /mnt/boot/efi && mkdir -p /mnt/boot/grub
mount /dev/sdb2 /mnt/  && mount /dev/sdb1  /mnt/boot/efi
grub2-install --root-directory=/mnt/   --target=x86_64-efi   /dev/sdb#创建EFI/BOOT/bootx64.efi,确保UEFI可以boot
mkdir -p  /mnt/boot/efi/EFI/BOOT
cp  /mnt/boot/efi/EFI/centos/grubx64.efi  /mnt/boot/efi/EFI/BOOT/bootx64.efi# copy 本机的kernel 镜像(也可以自己编译)
cp  /boot/vmlinuz-3.10.0-514.el7.x86_64  /mnt/#copy上面编译的busybox initramfs
cp   /root/csdn/build/obj/initramfs-busybox-x86.cpio.gz  /mnt/# 获取主分区的UUID用来填充grub.cfg
lsblk -f# Get UUID
# In Grub UI,ls -l 8006ca13-d59a-4a28-8b02-e8c8eed498b4mount /dev/sdb2 /mnt/
mount /dev/sdb1 /mnt/boot/eficp  /boot/vmlinuz-3.10.0-514.el7.x86_64  /mnt/
cp   /root/csdn/build/obj/initramfs-busybox-x86.cpio.gz  /mnt/echo 'menuentry 'csdn-kernel-3.10.0-514.el7.x86_64' --class gnu-linux --class gnu --class os {insmod gzioinsmod part_gptsearch --no-floppy --fs-uuid --set  8006ca13-d59a-4a28-8b02-e8c8eed498b4echo 'Loading csdn kernel 3.10.0 ...'linux  /vmlinuz-3.10.0-514.el7.x86_64  rw init=/bin/sh console=ttyS0,9600n8 console=tty0 consoleblank=0 earlyprintk=ttyS0,9600 kgdboc=kbd,ttyS0 loglevel=7echo   'Loading initial ramdisk busybox  ...'initrd /initramfs-busybox-x86.cpio.gz
}'  > /mnt/boot/efi/EFI/centos/grub.cfgecho 'menuentry 'csdn-kernel-3.10.0-514.el7.x86_64' --class gnu-linux --class gnu --class os {insmod gzioinsmod part_gptsearch --no-floppy --fs-uuid --set  8006ca13-d59a-4a28-8b02-e8c8eed498b4echo 'Loading csdn kernel 3.10.0 ...'linux  /vmlinuz-3.10.0-514.el7.x86_64  rw init=/bin/sh console=ttyS0,9600n8 console=tty0 consoleblank=0 earlyprintk=ttyS0,9600 kgdboc=kbd,ttyS0 loglevel=7echo   'Loading initial ramdisk busybox  ...'initrd /initramfs-busybox-x86.cpio.gz
}'  > /mnt/boot/grub2/grub.cfgcat /mnt/boot/efi/EFI/centos/grub.cfgumount /dev/sdb1
umount /dev/sdb2dd if=/dev/sdb bs=512 count=819201 of=./csdn_busybox2.img
7za a csdn_busybox2.7z csdn_busybox2.img
scp root@192.168.1.18:/root/csdn_busybox2.7z .# QEMU 启动busybox
chcp 65001 && "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 256 -cpu "qemu64" -boot order=dc -serial stdio -hda csdn_busybox2.img
chcp 65001 && "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 256 -cpu "qemu64" -boot order=dc -serial stdio -hda D:\share\centos7.img
chcp 65001 && "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 256 -cpu "qemu64" -boot order=dc -serial stdio  -usbdevice disk:HDD_BOOT.img

5. 编译并运行Ovmf開源固件命令

make -C /root/edk2/BaseTools/Source/C
./OvmfPkg/build.sh -D DEBUG_ON_SERIAL_PORT# 在Centos下制作虚拟盘
# 新建HDD_BOOT.img的空文件
qemu-img create -f raw HDD_BOOT.img 64M
# 格式化img文件
mkfs.vfat HDD_BOOT.img
# 将文件加载到设备文件
losetup  /dev/loop8 HDD_BOOT.img
#新建挂载目录
mkdir -p /mnt/hello
#将设备挂载到目录
mount /dev/loop8 /mnt/hellocp ./Build/OvmfX64/DEBUG_GCC48/X64/HelloWorldPci.efi  /mnt/hello
cp ./Build/OvmfX64/DEBUG_GCC48/X64/DumpHobs.efi /mnt/hello
# 将efi文件回写到 HDD_BOOT.img
umount /dev/loop8
losetup -d /dev/loop8qemu-system-x86_64 -bios ./Build/OvmfX64/DEBUG_GCC48/FV/OVMF.fd  \
-serial stdio -usb -drive if=none,format=raw,id=disk1,file=HDD_BOOT.img \
-device usb-storage,drive=disk1

6. 设置虚拟串口

sed 's/quiet/console=ttyS1,9600 loglevel=8/' -i /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg reboot

7.對硬盤鏡像制作centos grub2

gdisk ./centos7.img
>t
losetup --offset 1MiB --sizelimit 1024MiB /dev/loop7 ./centos7.img
losetup --offset 1024MiB  /dev/loop8 ./centos7.img
mount /dev/loop8 /mnt2
mount /dev/loop7 /mnt2/boot/efi
grub2-install --efi-directory=/mnt2/   --target=x86_64-efi  ./centos7.img

8. 使能 SSH 遠程登陸

echo 'PasswordAuthentication yes
PermitRootLogin yes
AllowUsers root' >> /etc/ssh/sshd_config
service sshd restart

9. 修改語言

sed '/LANG=/cLANG="en_US.UTF-8"' -i /etc/locale.conf

10. 设置代理

export proxy="http://xxx.com:123(实际定义Port)"
export http_proxy=$proxy
export https_proxy=$proxy
echo 'sslverify=0' >> /etc/dnf/dnf.confecho '
export HTTP_PROXY="http://xxx.com:123(实际定义Port)/"
export HTTPS_PROXY="https://xxx.com:912/"
export http_proxy="http://xxx.com:123(实际定义Port)/"
export https_proxy="https://xxx.com:912/"
export FTP_PROXY="http://xxx.com:21/"
use_proxy=on
' >> /etc/profile.d/proxy.sh
chmod +x /etc/profile.d/proxy.shecho '
proxy="http://xxx.com:123(实际定义Port)/"
' >> /etc/dnf/dnf.confecho '
proxy="http://xxx.com:123(实际定义Port)/"
' >> /etc/yum.conf//fix ssl errors
echo '
proxy=http://proxy-xxxx.com:xxx/
' >> .curlrc

10. 各種鏡像文件轉換

#轉換 vmdk为 img 文件
"C:\Program Files\qemu\qemu-img.exe"  convert Fedora-single.vmdk Fedora-single.img#轉換 img為vmdk文件
"C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe"  -r ".\Fedora 64 位.vmdk" -t 0 ".\Fedora-single.vmdk"# 轉換img為vdi
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" convertfromraw -format VDI Fedora-single.img Fedora-single.vdi
"C:\Program Files\qemu\qemu-img.exe" convert -f raw -O vdi fwts-live-22.03.00-x86_64.img fwts-live-22.03.00-x86_64.vdi# 轉換vdi為img
"C:\Program Files\qemu\qemu-img.exe" convert -f vdi Fedora-single.vdi  Fedora-single2.img
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  clonehd Fedora-single.vdi Fedora-single.raw   --format RAW# 轉換vmdk為vdi
"C:\Program Files\qemu\qemu-img.exe" convert -f vmdk -O vdi Fedora-single.vmdk Fedora-single.vmdk.vdi
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  clonehd Fedora-single.vmdk Fedora-single.vdi --format VDI #轉換 vdi為 qcow2
"C:\Program Files\qemu\qemu-img.exe" convert -f vdi Fedora-single.vdi  -O qcow2 Fedora-single2.qcow2  #轉換 vdi為 vmdk
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  clonehd Fedora-single.vdi Fedora-single.vmdk --format VMDK #轉換 vdi為 VHD
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  clonehd Fedora-single.vdi Fedora-single.vhd --format VHD # 設置鏡像文件UUID
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  showmediuminfo  Fedora-single.vdi
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  internalcommands sethduuid Fedora-single.vdi d8f845dc-1362-433a-8d56-0ee196fa4f6d# VDI 文件扩容
1) "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd  Fedora-single.vdi --resize 119202) "C:\Program Files\qemu\qemu-img.exe" resize Fedora-single.img +10G
"C:\Program Files\qemu\qemu-img.exe" convert -f raw -O vdi Fedora-single.img Fedora-single.vdi

11. 设置串口免密码

cp /lib/systemd/system/serial-getty@.service /lib/systemd/system/serial-getty@.service.bak sed '/ExecStart=-/cExecStart=-/sbin/agetty -a root -8 -L %I 9600 $TERM' -i /lib/systemd/system/serial-getty@.service

12. 添加开机自启动程序

//编辑开机自启动脚本
vim /etc/rc.local//设置开机自启动权限
chmod +x /etc/rc.d/rc.local

13. 忘记密码,重置root用户

# 方法一:
在 linux16 参数这行的最后面追加“rd.break
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit reboot# 方法二:
//按e 进入编辑界面如下把ro改为?“rw init=/sysroot/bin/sh”. 然后 “Ctrl+x”启动
//依次输入以下命令进行root密码修改,修改完成之后退出 强制重启即可。
chroot /sysroot/passwd
passwd
touch /.autorelabel
exit
reboot

14. 编译grub:

wget https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz
tar xvf grub-2.04.tar.xz
# ./configure && make && make install

15. 擴展主分區

fdisk -u /dev/sdb
Command (m for help): p
Command (m for help): d
Selected partition 2
Command (m for help): n
Partition number (1-4): 2
First sector (195313-25165823, default 195313): 195313 # must align as original
Command (m for help): w
e2fsck -f /dev/sdb2
resize2fs /dev/sdb2

16. 安裝多個系統到單一DISK

# sdb3-> 主os的第三塊分區, sdc 為guest os
dd if=/dev/sdc of=/dev/sdb3 status=progress bs=10M conv=noerror

17. 更改GCC 版本

wget https://ftp.gnu.org/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz
或者
wget https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.xz
tar xf gcc-7.5.0.tar.xz
cd gcc-7.5.0
./contrib/download_prerequisites
sed 's/ftp:\/https:\//' ./contrib/download_prerequisites
cd ..
mkdir gcc-7.5.0-build
cd gcc-7.5.0-build
../gcc-7.5.0/configure --enable-languages=c,c++ --disable-multilib
make
sudo make installexport PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

18 Install VNC server

# yum -y install tigervnc-server
# vncserver //设置密码
# vncpasswd //设置密码
# echo "gnome-session &" >> /root/.vnc/xstartup#yum install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
//fix the terminal could not open
# echo '
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &
gnome-session &' >> /root/.vnc/xstartup# echo '
#!/bin/bash
/sbin/iptables -I INPUT 1 -p TCP --dport 5901:5910 -j ACCEPT
vncserver -geometry 1920x1080' >> vnc.sh# echo -e 'VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768"' >> /etc/sysconfig/vncservers

19. 配置LVM

# lvs // 查看VG
# lvcreate  -L 30.00g -n lvubutnu fedora_intel-obmc
# mkfs.ext4 /dev/fedora_intel-obmc/lvubutnu
# mount /dev/fedora_intel-obmc/lvubutnu /mnt# lvcreate  -L 30.00g -n lvkernel fedora
# mkfs.ext4 /dev/fedora/lvkernel
# mount /dev/fedora/lvkernel /mnt

20. 运行QEMU 虚拟机

# qemu-img create -f qcow Ubuntu20.img 20G
# qemu-kvm  -enable-kvm  -boot d -cdrom ubuntu-20.04-desktop-amd64.iso -hda Ubuntu20.img -m 8192
# qemu-kvm -m 8192 -enable-kvm Ubuntu20.imgecho 'qemu-kvm  -enable-kvm  -boot d -cdrom ubuntu-20.04-desktop-amd64.iso -hda Ubuntu20.img -m 8192' >> insatll_ubuntu.sh
chmod +x  insatll_ubuntu.shecho '
#!/bin/bash
qemu-kvm -L /mnt/img -m 8192 -hda /mnt/img/Ubuntu20.img -enable-kvm' > /mnt/img/setupvm.sh
chmod +x /mnt/img/setupvm.shecho '
#!/bin/bash
mount /dev/fedora_intel-obmc/lvubutnu /mnt
/mnt/img/setupvm.sh > /dev/null 2>&1 &' >> startvm.sh
chmod +x startvm.sh# lsusb --> Bus 001 Device 006: ID 0951:16a2 Kingston Technology DTR30G2
# qemu-kvm -m 8192 -enable-kvm Ubuntu20.img -usbdevice host:xxx:xxx

21. qemu + gdb debug kernel

#CGDB安装
[root@localhost ~]# wget https://github.com/cgdb/cgdb/archive/v0.7.0.tar.gz
[root@localhost ~]# tar xf v0.7.0.tar.gz
[root@localhost ~]# cd cgdb-0.7.0/
[root@localhost cgdb-0.7.0]# ./autogen.sh
[root@localhost cgdb-0.7.0]# ./configure --prefix=${HOME}/cgdb
[root@localhost cgdb-0.7.0]# make && make install
或者
#yum install cgdb -y# Install qemu
yum install qemu-kvm qemu-img -y
ctrl-alt-f      toggle full screen
ctrl-alt-n      switch to virtual console 'n'
ctrl-alt        toggle mouse and keyboard grab#GDB debug kernel
cd /root/linux-4.9.153
# cgdb vmlinux(gdb) target remote :1234
Remote debugging using :1234
native_safe_halt () at ./arch/x86/include/asm/irqflags.h:57
(gdb) b register_filesystem
Breakpoint 1 at 0xffffffff81257dd0: file fs/filesystems.c, line 70.
(gdb) c
Continuing.Breakpoint 1, register_filesystem (fs=0xffffffffa00a0ac0) at fs/filesystems.c:70
(gdb) p fs->name
$1 = 0xffffffffa0095cc0 "ext3"

22 . 开机设置网卡和打开kernel message

#grubby --update-kernel=ALL --args="console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 loglevel=9 "
#sed '/ONBOOT=/cONBOOT=yes' -i  /etc/sysconfig/network-scripts/ifcfg-ens3#设置默认启动kernel
grubby --set-default /boot/vmlinuz-3.10.0-229.4.2.el7.x86_64
grubby --set-default-index=0(以实际序列为准)

23 . Linux inject Ras errors

# Refer the below guide
https://uefi.org/specs/ACPI/6.4/18_ACPI_Platform_Error_Interfaces/error-injection.html# Inejct CE errors
dmesg -C
modprobe einj
cd /sys/kernel/debug/apei/einj
echo 0x8 > error_type  # memory CE
echo 0x12345677 > param1 #any system address
echo 0xfffffffffffff000 > param2 #13->f,3->0
echo 1 > error_inject# Inejct UCE errors
dmesg -C
modprobe einj
cd /sys/kernel/debug/apei/einj
echo 0x10 > error_type      #memory non-fatal
echo 0x23457890 > param1   #anoterh addr to test non-fatal
echo 1 > error_inject
dmesg# Inejct UCE fatal  errors
dmesg --clear # clear serial log
modprobe einj
cd /sys/kernel/debug/apei/einj
echo 0x20 > error_type      #(memory fatal)
echo 0x23452222 > param1  #(another addr to test fatal)
echo 1 > error_inject

24 . Linux grub設置關閉VGA vedio / 網卡

grubby  --update-kernel /boot/vmlinuz-$(uname -r) --args="modprobe.blacklist=ast,igc video=offb:off console=ttyS0,115200"

25. 生成git 秘钥

ssh-keygen -t rsa

26. U盤Linux 安裝失敗

  # dracut_initqueue[599]: Warning: Could not boot# -> grub 界面 quiet后输入1(单用户模式)->  ls /dev/sdxx (找到U盤對應的設備)-> reboot-> 修改 vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS -> vmlinuz initrd=initrd.img inst.stage2=hd:/dev/sdbx(U 盤設備)

27. Linux crash dump

# 設置crashkernel 參數到grub
grubby --update-kernel=ALL --args="console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 loglevel=9 crashkernel=512M  "# Enable kdump 服務
systemctl enable kdump.service
systemctl start kdump.service
systemctl status kdump
systemctl is-active kdump# Enable CentOS-Stream-Debuginfo.repo
sed  's/enabled=0/enabled=1/' -i /etc/yum.repos.d/CentOS-Stream-Debuginfo.repo# 安裝 debug kernel
yum install kernel-debuginfo
debuginfo-install kernel# 安裝Crash tool
yum install kexec-tools
yum install kernel-debug
yum install crash# 使用crash 分析vmlinux
crash /var/crash/xxx/vmcore /usr/lib/debug/lib/modules/4.18.0-147.5.1.el8_1.x86_64/vmlinux

Ubuntu/Demian 系統命令

1. Ubuntu设置为命令行(no-gui)登录

sed '/GRUB_CMDLINE_LINUX_DEFAULT=/cGRUB_CMDLINE_LINUX_DEFAULT="splash text"'  -i /etc/default/grub
update-grub

2. 安装软件源:

cp /etc/apt/sources.list /etc/apt/   sources.list.bak
echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
' > /etc/apt/sources.list
apt update

虚拟机设置(VBOX, VMware)

1. 设置共享文件夹

# Vmware
#kernel headers
yum install kernel-devel
vmhgfs-fuse /mnt/hgfs
# Vbox
yum -y install kernel-headers kernel-devel
yum groupinstall "Development tools"   #安装gcc
init 6
mount /dev/cdrom /media
#mount /dev/dvd /media
cd /media
bash ./VBoxLinuxAdditions.run
init 6
modprobe vboxsf
/etc/init.d/vboxdrv setup
mount -t vboxsf vmshare /media

2. 设置虛擬串口

# Vmware
\\.\pipe\com_1 -> /dev/ttyS1
# VBOX
\\.\pipe\com_1 -> /dev/ttyS0

15. 设置UEFI啓動

# Vmware UEFI 啓動
VMware设置->选项->高级中,选择UEFI
(#Fix 固件类型无法选择UEFI“常规”,版本选择“Ubuntu64位”,工作目录选择一个别的路径)
# VBOX UEFI 啓動
設置->系統->啓用EFI

16 Linux Kernel cmd

#makefile 传递宏给module
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) EXTRA_CFLAGS="-DBUILD_NUMBER=$(BUILD_NUMBER)" modules

常用的下载网址

1. 下載fwt-live測試鏡像
https://fwts.ubuntu.com/fwts-live/
https://github.com/xypron/fwts
2. 下載vbox路径
http://download.virtualbox.org/virtualbox/6.0.0

Linux debug 常用命令相关推荐

  1. Linux GDB常用命令一栏

    Linux GDB 常用命令如下: 1.启动和退出gdb (1)启动:gdb ***:显示一段版权说明: (*** 表示可执行程序名) (2)退出:quit.有的时候输入quit后会出现相关提示:类似 ...

  2. Linux GCC 常用命令

    Linux GCC 常用命令与汇编 文章目录 Linux GCC 常用命令与汇编 1 .简介 2 .简单编译 2.1 预处理 2.2 编译为汇编代码 2.3 汇编(Assembly) 2.4 连接(L ...

  3. Linux GCC常用命令和ELF文件格式

    Linux GCC常用命令和ELF文件格式 一.各种工具 (一)GCC编译工具 (二)Binutils (三)C 运行库 一. C 语言程序 Hello.c示例 (一)准备工作 (二)编译过程 1.预 ...

  4. linux下常用命令wget进行整站下载

    一.Linux下的wget Linux系统中的wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持H ...

  5. linux下常用命令

    目  录 引言    1 一.安装和登录    2 (一)    login    2 (二)    shutdown    2 (三)    halt    3 (四)    reboot    3 ...

  6. linux系统 常用命令

    linux系统 常用命令 ps –ef|grep java 查看进程 netstat –an|grep 52818查看端口是否开启 tail –f log.log 查看日志 echo hello &g ...

  7. linux的编程命令,linux编程常用命令

    学习linux编程最基本的就是要掌握常用的编程命令,下面由学习啦小编为大家整理了linux编程常用命令相关知识,希望大家喜欢! linux编程常用命令1.编译应用程序 make -f makefile ...

  8. linux指令笔试,Linux笔试常用命令

    Linux笔试常用命令 时间:2019-01-01 [www.unjs.com - 资料大全] 文件操作命令 ls 作用:列目录,Linux笔试常用命令>(https://www.unjs.co ...

  9. linux find -size参数,Linux find 常用命令

    Linux find 常用命令 (2012-10-24 11:32:52) 标签: linux shell 说明: 以下内容,若标注在 [ ] 中括号内的均可省略,除非做特别说明. 但严格来说,若缺少 ...

最新文章

  1. Nginx源码分析:启动流程
  2. python中dpi_python matplotlib 绘图 和 dpi对应关系详解
  3. Ubuntu14.04安装QQ2013
  4. 安卓手机反应越来越慢怎么办_安卓手机运行慢怎么办 只需几步轻松提升安卓手机速度...
  5. java 2d划线 刷子_月光软件站 - 编程文档 - Java - Java图形设计中,利用Bresenham算法实现直线线型,线宽的控制(NO 2D GRAPHICS)...
  6. 白帽子讲web安全笔记
  7. 第二次作业,问卷星的使用
  8. matlab gz,MATLAB之single函数
  9. 关于严蔚敏老师《数据结构(C语言版)》书中代码的误解
  10. solr和elasticsearch
  11. php+mysql(5.1)+apache+centos 编译安装
  12. python如何安装spyder?
  13. python 生成16位integer
  14. 配置rtools 4.0 https://cran.r-project.org/bin/windows/Rtools/
  15. 计算机桌面垃圾筒怎么恢复出来,桌面垃圾桶被误删了,怎么恢复
  16. android textview 楷体,Android自定义控件之自定义Text,画出米字格-FenGKun
  17. Unity之tvOS平台注意事项
  18. c++心形编码_使用C++描绘心形
  19. 数字化转型大背景下,企业的核心竞争力在哪里?
  20. 怎么样把中文版的Windows7改成英文版的Windows7

热门文章

  1. 履带式机械臂小车的制作分享
  2. maven 跳过单元测试打包
  3. 极光im java_java手写一个迷你版的Tomcat代码分享
  4. Xilinx ISE系列教程(8):读取FPGA芯片唯一ID号
  5. Python turtle画图库画姓名实例(Python入门)
  6. java第一周_从计算机基础到流程控制语句(if_else)
  7. Vulnhub_gigachad_vh
  8. 人工智能安全政策与标准
  9. 理清「万维网」和「互联网」的概念和区别
  10. 基于ASP的反垃圾邮件管理系统的设计与实现