修复ubuntu22.4无法上网

如图,正常的 VMware 里 Ubuntu22.4, 在用桥接网络/NAT 时是这样的。有一个网络标志。

如果没有,则按照如下操作修复:

  1. 终端中,输入命令,如下
1
ip addr

输出如下图:

图中,ens33,没有出现 ip,则网络配置有问题

  1. 修改 01-network-manager-all.yaml 文件
    sudo gedit /etc/netplan/01-network-manager-all.yaml
    打开后,如果只有前面 4 行,则补充

    1
    2
    network:
    version: 2

Let NetworkManager manage all devices on this system

1
2
3
4
5
6
7
8
network:
version: 2
renderer: NetworkManager
ethernets:
ens33: #根据自己配置的网卡名称改,使用 ip addr 查看得到
dhcp4: true #dhcp4 开启
addresses: [] #设置本机 IP 及掩码,空
optional: true
  1. 修改 NetworkManager.conf 文件
    sudo gedit /etc/NetworkManager/NetworkManager.conf
1
maneged=false改为true
  1. 重启网络
1
2
3
4
sudo service network-manager stop
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start

  1. 经过上述步骤还是不能上网,则检查网卡是否开启

    没有开启,则输入如下:
1
2
3
sudo ip link set ens33 up
sudo dhclient ens33

  1. 重启电脑
    reboot

ubuntu升级第三方库

问题:
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20’ not found (required by layout)

解决方式:
测试依赖:
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

升级方法:

1
2
3
4
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

ppa 速度慢解决
将/etc/apt/sources.list 中
http://ppa.launchpad.net替换为https://launchpad.proxy.ustclug.org

ubuntu增加交换区

Process to Increase Size of Swap Partition and use it for Hibernation
Creating the swap partition
Activating the swap partition
Making the new swap partition work for hibernate (optional)
Creating the swap partition
Boot to Ubuntu install CD and choose the option to run Ubuntu now
Go to system -> GParted Partition Editor

Delete the swap partition and, if there is nothing else in it, the extended partition that holds it. (If by some miracle you’re able to resize your swap partition from here, I imagine your life will be a lot easier than mine.)
Decrease the size of your primary partition by the amount you want your new swap to be (I made mine 2x RAM + 500MB just to be safe). The easiest way to do this is to fill in the amount of space you want swap to be in the “free space following” field
In the free space that has now been created, choose new, type linux-swap and you can name the partition “swap” if you like
Hit the Apply button (should be a check mark) to write the changes to disk
When done, reboot back into Ubuntu
Activating the swap partition
(If your swap is on your primary hard drive, you don’t need to do anything here.) Now you need to find what partition your swap is on and what its UUID is. UUID?! you say? Well that’s the Universally Unique IDentifier for the partition so you can reference it even if it’s on a different mount point from boot-to-boot due to adding disks, etc.

Pull up a terminal and run gksu gparted & and enter your root password. The & lets this process run while still giving you access to the command line.

Right-click on your swap partition and choose Information. You should see the Path and UUID listed there. Keep this open for further reference.
Run gksu gedit /etc/fstab & and look for the line that has swap in it. It should be the third column, separated by spaces or tabs. You can either use the path or the UUID to tell Linux where to find your swap partition. I recommend UUID because it’ll stay constant even if you move the partition around or the disk somehow becomes sdb instead of sda or something like that. Make the appropriate edits and save the file. Your line should look something like this if you used UUID (with your UUID instead, of course):

UUID=41e86209-3802-424b-9a9d-d7683142dab7 none swap sw 0 0

or this if you used path: /dev/sda2 none swap sw 0 0

Save the file.
Enable the new swap partition with this command.

sudo swapon –all
OR

$ sudo swapon –all –verbose
swapon on /dev/sda2
swapon: /dev/sda2: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/sda2: pagesize=4096, swapsize=2147483648, devsize=2147483648
Confirm that the swap partition exists.

$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda2 partition 2097148 0 -1
Reboot to make sure the new swap gets activated properly at startup

ubuntu中java虚拟机内存分配不足

问题:

ubuntu 虚拟机中,编译 android10,出现如下错误:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000769400000, 295698432, 0) failed; error=’Not enough space’ (errno=12)

解决方式:

方法一

最后来根据 (errno=12)这个搜索到一篇文章,说道:
    后来看了美军一个文章(http://www.enchantedage.com/node/235),加一个配置即可:echo 1000000 > /proc/sys/vm/max_map_count

我看了自己虚拟机 ubuntu 里面,/proc/sys/vm/max_map_count 的初始值很小,只有 65530,果断使用这个重设了一下。
  啊,终于好了,太艰难了。

后来又请装双系统的同事看下他们系统里的这个值,也是 65530,但是他们的却不报错,真是醉醉的。看来造成“无法分配内存”的原因,并不是这里,但是可以通过修改这个来解决。

猜测这个原因:1、双系统和虚拟机不同 2、安装 jdk 方式的不同(之前的我,和现在的同事们,都是先下载好 jdk 再安装的;可是现在虚拟机我却使用命令安装,这样不需要配置环境变量)

只是猜测,暂时就不去验证它了,如果再有遇到的同学,解决不了的话,可以朝这个方向尝试下。

方法二:

https://www.cnblogs.com/schips/p/solve_a_problem_of_Not-enough-space_when_building_android.html

ubuntu安装python3.8-ssl

  1. 下载 openssl
    https://www.openssl.org/source/old/1.1.1/openssl-1.1.1d.tar.gz
    注意:python3.8 最好下载高版本 openssl
  2. 编译 openssl
1
2
3
4
5
6
tar zxvf openssl-1.1.1d.tar.gz openssl-1.1.1d
cd openssl-1.1.1d
sudo ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
sudo make
sudo make test
sudo make install
  1. 将编译后 openssl 动态库,加入搜索路径
1
2
3
4
5
6
7
sudo mkdir lib64
sudo ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
sudo ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
sudo su
echo "/usr/lib64" >> /etc/ld.so.conf.d/lib64.conf
// 查看是否成功
ldconfig -v
  1. 下载 python3.8.5
    https://www.python.org/downloads/source/
  2. 解压 python
1
2
3
tar zxvf python3.8.5.tar.gz python3.8.5
cd python3.8.5
sudo apt-get install libffi-dev
  1. 修改配置
    vi modules/Setup
    放开如下注释:
1
2
3
4
SSL=/usr/local/openssl
\_ssl \_ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
  1. 编译 python
1
2
3
4
sudo ./configure --prefix=/usr/local/python
sudo make
sudo make install

  1. 加入动态管理 python
1
2
sudo update-alternatives --install /usr/bin/python python /usr/local/python/python3.8.5/bin/python3.8 3
sudo update-alternatives --config python