Misc Notes

ubuntu相关笔记

挂载硬盘

1
2
3
$ sudo mkfs.ext4  /dev/sdb
$ sudo blkid
$ sudo vi /etc/fstab

修改文件内容:

1
UUID=a450131d-8c83-4092-a028-887b7f6495b5 /mnt/xxx ext4 defaults 0 1
1
2
$ sudo mount -a
$ sudo chown -R xxx:xxx /mnt/xxx

18.04配置网络

不再使用 /etc/network/interfaces

修改 /etc/netplan/xxxxx.yaml

1
2
3
4
5
6
7
8
9
network:
ethernets:
ens33:
dhcp4: no
addresses: [192.168.1.30/24]
gateway4: 192.168.1.1
nameservers:
addresses: [114.114.114.114,8.8.8.8]
version: 2

改完后 sudo netplay apply

禁用 USB-Storage

  1. 修改下列文件:
    sudo vi /etc/modprobe.d/blacklist.conf
    在文件头部添加以下内容
    1
    2
    blacklist uas
    blacklist usb-storage
  2. 修改下列文件:
    sudo vi /etc/rc.local
    exit 0 上方添加
    1
    2
    modprobe -r uas
    modprobe -r usb-storage
  3. 重启
    sudo reboot

安装签名

1. 安装用到的软件包

1
sudo apt install debsigs

2. 生成GPG密钥

在GUI的终端窗口里输入以下命令

1
gpg --gen-key

三个选择都按默认,最后一个选y

1
2
3
4
Real name: AIOYTJ
Email address: manage@aioytj.com
Comment: AIO
Change (N)ame, (C)omment, (E)mail or (O)key/(Q)uit? O

Passphrase 输入密码,共两次,后面对安装名签名时会使用到,此时会出现

1
Not enough random bytes available.

这时候需要随便做一些操作,比如打开文件夹,打开某个程序输入点东西再关掉,时不时地切回终端窗口看一下,直到出现

1
2
3
4
5
6
7
8
9
10
gpg: key D189DD93 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 2048R/D189DD93 2021-06-10
Key fingerprint = E3BD 6698 7C40 E362 741C E398 96F4 3D0F D189 DD93
uid AIOYTJ (AIO) <manage@aioytj.com>
sub 2048R/C1F4D81B 2021-06-10

这个时候运行

1
gpg --list-secret-keys

可以看到已经生成的gpg key

1
gpg --list-key --keyid-format LONG

输出如下

1
2
3
4
5
/home/yangxc/.gnupg/pubring.gpg
-------------------------------
pub 2048R/96F43D0FD189DD93 2021-06-10
uid AIOYTJ (AIO) <manage@aioytj.com>
sub 2048R/9B4B8F01C1F4D81B 2021-06-10

以上输出内容中,第一行pub后面的 96F43D0FD189DD93 即为该密钥的指纹,第二行uid后面的是 USER ID,下面导入密钥环中会用到。

3. 把密钥导入密钥环

1
2
3
4
gpg --armor --output public-key.txt --export "AIOYTJ (AIO) <manage@aioytj.com>"
sudo mkdir /usr/share/debsig/keyrings/96F43D0FD189DD93
sudo touch /usr/share/debsig/keyrings/96F43D0FD189DD93/pubring.gpg
sudo gpg --no-default-keyring --keyring /usr/share/debsig/keyrings/96F43D0FD189DD93/pubring.gpg --import public-key.txt

添加策略配置文件

1
2
sudo mkdir /etc/debsig/policies/96F43D0FD189DD93
sudo vi /etc/debsig/policies/96F43D0FD189DD93/pubring.pol

文件内容如下

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0"?>
<!DOCTYPE Policy SYSTEM "https://www.debian.org/debsig/1.0/policy.dtd">
<Policy>
<Origin Name="AIOYTJ" id="96F43D0FD189DD93" Description="AIO"/>
<Selection>
<Required Type="origin" File="pubring.gpg" id="96F43D0FD189DD93"/>
</Selection>
<Verification MinOptional="0">
<Required Type="origin" File="pubring.gpg" id="96F43D0FD189DD93"/>
</Verification>
</Policy>

4. 给deb包签名

1
debsigs --sign=origin -k 96F43D0FD189DD93 aiodriver_2.2.0.deb

输入上面生成key时的密码。

5. 打开强制签名

1
sudo vi /etc/dpkg/dpkg.cfg

注释掉 no-debsig,即

1
# no-debsig

5. 给lvm扩容

默认安装的情况下,lvm不会把磁盘用完,通过 sudo vgdisplay 查看剩余磁盘如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--- 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 <498.00 GiB
PE Size 4.00 MiB
Total PE 127487
Alloc PE / Size 25600 / 100.00 GiB
Free PE / Size 101887 / <398.00 GiB
VG UUID NxG1O4-6H7r-M76X-5tM9-wBZp-wEHs-nSTwGD

这里的 Free PE / Size 101887 / <398.00 GiB 就是还可以分配的量。
通过 lvdisplay 查看 lvm 名字如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID a0sk4C-TtAv-QqBN-0bZN-QEAx-zhpw-nyTyeG
LV Write Access read/write
LV Creation host, time ubuntu-server, 2022-11-12 23:33:17 +0800
LV Status available
# open 1
LV Size 100.00 GiB
Current LE 25600
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

扩容:

1
lvresize -l +101887 /dev/ubuntu-vg/ubuntu-lv

df -h 看到 /dev/mapper/ubuntu--vg-ubuntu--lv 还是只有100G,扩之:

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