记录Ubuntu有关设置方法

2025-06-23T20:56:00

本文为配置Ubuntu 20.04版本方法,其他版本可能有差异。

配置代理

配置代理而非换源的好处:可以获取到官方服务器最新的版本,镜像服务器可能存在版本更新不及时,证书错误等一系列问题。到时候出问题头都大了。
  • 命令行

编辑文件

sudo nano /etc/profile.d/proxy.sh

写入内容

# set proxy config via profie.d - should apply for all users
export http_proxy="http://127.0.0.1:7890/"
export https_proxy="http://127.0.0.1:7890/"
#export ftp_proxy="http://127.0.0.1:7890/"
export no_proxy="127.0.0.1,localhost"
# For curl
export HTTP_PROXY="http://127.0.0.1:7890/"
export HTTPS_PROXY="http://127.0.0.1:7890/"
#export FTP_PROXY="http://127.0.0.1:7890/"
export NO_PROXY="127.0.0.1,localhost"

设置权限并运行

sudo chmod +x  /etc/profile.d/proxy.sh
source /etc/profile.d/proxy.sh

测试打印

env | grep -i proxy

  • apt包管理器

编辑文件

sudo nano /etc/apt/apt.conf.d/80proxy

写入内容

Acquire::http::proxy "http://127.0.0.1:7890/";
Acquire::https::proxy "http://127.0.0.1:7890/";
#Acquire::ftp::proxy "ftp://127.0.0.1:7890/";

#将127.0.0.1替换为代理服务器的正确IP地址,如果需要身份验证,请设置如下:
#Acquire::http::proxy "http://<username>:<password>@<proxy>:<port>/";
#Acquire::https::proxy "https://<username>:<password>@<proxy>:<port>/";
#Acquire::ftp::proxy "ftp://<username>:<password>@<proxy>:<port>/";
  • conda环境

执行

conda config --set proxy_servers.http http://127.0.0.1:7890
conda config --set proxy_servers.https http://127.0.0.1:7890

使用LVM管理磁盘

优点:可以动态管理磁盘大小,将多块不同硬盘合成为一个连续分区,避免了考虑逻辑卷在硬盘上的位置。
缺点:管理比较麻烦,不能在Windows上访问(包括使用DiskGenius等管理软件)。
  • 调整磁盘大小

使用df -h命令查看信息

可见lvm管理的分区/dev/mapper/ubuntu--vg-ubuntu--lv
使用vgs命令查看信息

root@wyyinspiron:/home/wyy# vgs
    /dev/sdb: open failed: No medium found
    /dev/sdb: open failed: No medium found
    VG        #PV #LV #SN Attr   VSize    VFree 
    ubuntu-vg   1   1   0 wz--n- <109.79g 54.89g

使用vgdisplay命令查看具体信息

root@wyyinspiron:/home/wyy# vgdisplay
    /dev/sdb: open failed: No medium found
    /dev/sdb: open failed: No medium found
    --- Volume group ---
    VG Name               ubuntu-vg
    System ID             
    Format                lvm2
    Metadata Areas        1
    Metadata Sequence No  2
    VG Access             read/write
    VG Status             resizable
    MAX LV                0
    Cur LV                1
    Open LV               1
    Max PV                0
    Cur PV                1
    Act PV                1
    VG Size               <109.79 GiB
    PE Size               4.00 MiB
    Total PE              28105
    Alloc PE / Size       14052 / 54.89 GiB
    Free  PE / Size       14053 / 54.89 GiB
    VG UUID               fhqIse-SP9k-CTgd-oPgw-c1Q5-1JUe-dGp5es

可见当前盘上还有54.89g空间可以分配。
使用lvextend命令对/dev/mapper/ubuntu--vg-ubuntu--lv进行操作,如增加40G。

lvextend -L +40G /dev/mapper/ubuntu--vg-ubuntu--lv

root@wyyinspiron:/home/wyy# lvextend -L +40G /dev/mapper/ubuntu--vg-ubuntu--lv
    /dev/sdb: open failed: No medium found
    /dev/sdb: open failed: No medium found
    Size of logical volume ubuntu-vg/ubuntu-lv changed from 54.89 GiB (14052 extents) to 94.89 GiB (24292 extents).
    Logical volume ubuntu-vg/ubuntu-lv successfully resized.

使用resize2fs命令实行修改

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

root@wyyinspiron:/home/wyy# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
    resize2fs 1.45.5 (07-Jan-2020)
    Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
    old_desc_blocks = 7, new_desc_blocks = 12
    The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 24875008 (4k) blocks long.

再次运行df -h,可见该文件系统容量已扩大。

参考链接:Ubuntu LVM分区扩容:轻松实现磁盘空间扩展,告别空间不足烦恼
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »