• Linux 装机必备


    CentOS/Redhat/Fedora 系統命令:

    1. 安装软件源

    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 
    
    # Fedora:
    wget http://mirrors.aliyun.com/repo/fedora.repo -O /etc/yum.repos.d/fedora.repo
    
    yum clean all 
    yum makecache 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    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
    
    或者
    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 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    3. 安装GUI

    yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
    ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
    
    4. 編譯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  				   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    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 defconfig
    
    make O=$TOP_BUILD/obj/busybox-x86 menuconfig
    sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" .config
    (或者Busybox Settings  ---> Build BusyBox as a static binary (no shared libs).)
    
    cd $TOP_BUILD/obj/busybox-x86
    make -j2
    make install
    
    mkdir -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/rcS
    
    echo '#!/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.10
    
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: present
    
    Found 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  Name
    
    Command (? 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  Name
       1            2048          225280   109.0 MiB   EF00  EFI System
    
    Command (? 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  Name
       1            2048          225280   109.0 MiB   EF00  EFI System
       2          227328          819200   289.0 MiB   8300  Linux filesystem
    
    Command (? for help): w
    
    Final 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-e8c8eed498b4
     
    mount /dev/sdb2 /mnt/
    mount /dev/sdb1 /mnt/boot/efi
     
    cp  /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 gzio
    		insmod part_gpt
    		search --no-floppy --fs-uuid --set  8006ca13-d59a-4a28-8b02-e8c8eed498b4
    		echo '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=7
    		echo   'Loading initial ramdisk busybox  ...'
    		initrd /initramfs-busybox-x86.cpio.gz
    }'  > /mnt/boot/efi/EFI/centos/grub.cfg
    
     echo 'menuentry 'csdn-kernel-3.10.0-514.el7.x86_64' --class gnu-linux --class gnu --class os {
    		insmod gzio
    		insmod part_gpt
    		search --no-floppy --fs-uuid --set  8006ca13-d59a-4a28-8b02-e8c8eed498b4
    		echo '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=7
    		echo   'Loading initial ramdisk busybox  ...'
    		initrd /initramfs-busybox-x86.cpio.gz
    }'  > /mnt/boot/grub2/grub.cfg
    
    cat /mnt/boot/efi/EFI/centos/grub.cfg
    
    umount /dev/sdb1
    umount /dev/sdb2
    
    dd 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 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244

    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/hello
    
    cp ./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/loop8
    
    qemu-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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    8. 使能 SSH 遠程登陸

    echo 'PasswordAuthentication yes
    PermitRootLogin yes
    AllowUsers root' >> /etc/ssh/sshd_config
    service sshd restart
    
    • 1
    • 2
    • 3
    • 4

    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.conf
    
    echo '
    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.sh
    
    echo '
    proxy="http://xxx.com:123(实际定义Port)/"
    ' >> /etc/dnf/dnf.conf
    
    echo '
    proxy="http://xxx.com:123(实际定义Port)/"
    ' >> /etc/yum.conf
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    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.vdi  fwts-live-22.03.00-x86_64.img 
    
    # 轉換vdi為img
    "C:\Program Files\qemu\qemu-img.exe" convert -f vdi Fedora-single.vdi  Fedora-single2.img
    
    # 轉換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 文件扩容
    "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd  Fedora-single.vdi --resize 11920
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    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
    
    • 1
    • 2
    • 3

    15 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    16. 配置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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    17. 运行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.img
    
    echo '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.sh
    
    echo '
    #!/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.sh
    
    echo '
    #!/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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    18. qemu + gdb debug kernel

    19 . 开机设置网卡和打开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
    
    • 1
    • 2

    Ubuntu/Demian 系統命令

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

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

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    虚拟机设置(VBOX, VMware)

    1. 设置共享文件夹

    # Vmware
    #kernel headers
    yum install kernel-devel
    vmhgfs-fuse /mnt/hgfs
    
    • 1
    • 2
    • 3
    • 4
    # Vbox
    mkdir shared_linux
    sudo mount -t vboxsf -o "uid=csdn,gid=csdn,dmode=0755,fmode=0755" shared_win ~/shared_linux
    
    • 1
    • 2
    • 3

    2. 设置虛擬串口

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

    15. 设置UEFI啓動

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

    16 Linux Kernel cmd

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

    常用的下载网址

    1. 下載fwt-live測試鏡像
    https://fwts.ubuntu.com/fwts-live/
    https://github.com/xypron/fwts
    
    • 1
    • 2
    • 3
    2. 下載vbox路径
    http://download.virtualbox.org/virtualbox/6.0.0
    
    • 1
    • 2
  • 相关阅读:
    java---哈希表插入和查询---数组模拟(每日一道算法2022.8.18)
    mysql高级语句
    【web前端期末大作业】HTML+CSS宠物狗静态网页设计
    MacOS M1芯片CentOS8部署搭建k8s集群
    如何自动识别爬虫网页的编码
    412-C++中map自定义key和value排序
    FPGA 学习笔记:Vivado 配置IO引脚约束
    Java中Timer和TimerTask的使用
    Frida 脚本抓取 HttpURLConnection 请求和响应
    经典算法——直接选择排序
  • 原文地址:https://blog.csdn.net/xiaopangzi313/article/details/124880992