Ubuntu 20.04.2 LTS 修改开机信息

发布时间 2023-09-10 00:24:25作者: “!”

   修改Ubuntu开机信息,当前使用版本为最新版本22.04,相同的方法在20.04中也可使用(亲测可用)

  1. 使用管理员账号登录

    sudo su roo
  2. 在以下的路径中查找rc.local.service文件,如果没有则新建文件



    文件中添加如下代码

    [Unit]
    Description=/etc/rc.local Compatibility
    ConditionFileIsExecutable=/etc/rc.local
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    RemainAfterExit=yes
    GuessMainPID=no
    
    [Install]
    WantedBy=multi-user.target
    Alias=rc-local.service
    

     查看内容,确保无误



    赋予当前文件读写权限

    sudo chmod +x /etc/systemd/system/rc-local.service
    

     

  3. 在/etc路径之下新建文件rc.local,如果存在,则修改中内容如下:
    打开文件
    vim /etc/rc.local
    

    具体内容:

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    bash /root/hello.sh
    exit 0
    

     查看修改结果:

     修改当前文件权限

    chmod +x /etc/rc.local
    
  4. 新建具体的欢迎文本内容文件,我的文件是建在的root路径下:
    vim /root/hello.sh
    

    具体文件内容如下,可根据个人兴趣添加信息:

    #********************下方是开机信息********************#
    #!/bin/sh -e
    echo "" > /etc/issue
    ip=`ip addr | grep "scope global" | grep "eth0"  | awk '{print $2}' |awk -F/ '{print $1}'`
    #ip=`ip addr | grep inet | grep eth0 | awk '{print($2)}'`
    #这一段用于获取IP地址。
    
    echo "*************************欢迎你************************************************************************ ">> /etc/issue
    

     修改当前文件权限

    sudo chmod +x /root/hello.sh
    
  5. 重启电脑,欢迎信息添加成功,我的开机界面如下图:
    电脑重启命令
    reboot

     同时向大家推荐一个生成上面这种空芯字体的网站,挺好用的
    http://jiqie.zhenbi.com/5/m1.htm?ivk_sa=1024320u

  6. 至此所有信息修改及添加全部完成,下一篇将介绍登录后的欢迎信息