linux

BIOS 删除空白启动(多于启动项)

  • 显示当前启动信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    user@host 1 17:27 >/usr/sbin/efibootmgr -v
    BootCurrent: 0000
    Timeout: 1 seconds
    BootOrder: 0000,0003,0004,0006,0007
    Boot0000* opensuse HD(1,GPT,xxxx-x-xxx-aaa,0x800,0x327cc)/File(\EFI\OPENSUSE\GRUBX64.EFI)
    Boot0003* debian HD(1,GPT,xxxx-x-xxx,0x800,0x100000)/File(\EFI\DEBIAN\SHIMX64.EFI)
    Boot0004* Windows Boot Manager HD(1,GPT,xxxx-x-xxx-bbb,0x1000,0x96000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)..BO
    Boot0006* UEFI: SanDisk, Partition 2 PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x0)/USB(2,0)/HD(2,MBR,0x61f4c181,0x7280000,0x10000)..BO
    Boot0007* debian HD(1,GPT,xxxx-x-xxx,0x800,0x100000)/File(\EFI\DEBIAN\GRUBX64.EFI)..BO
  • 删除指定的启动信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    user@host 3 17:27 >sudo /usr/sbin/efibootmgr -b 0007 -B
    [sudo] root 的密码:
    BootCurrent: 0000
    Timeout: 1 seconds
    BootOrder: 0000,0003,0004,0006
    Boot0000* opensuse
    Boot0003* debian
    Boot0004* Windows Boot Manager
    Boot0006* UEFI: SanDisk, Partition 2
  • 重新打印删除后的启动信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    user@host 4 17:27 >/usr/sbin/efibootmgr -v
    BootCurrent: 0000
    Timeout: 1 seconds
    BootOrder: 0000,0003,0004,0006
    Boot0000* opensuse HD(1,GPT,xxxx-x-xxx-aaa,0x800,0x327cc)/File(\EFI\OPENSUSE\GRUBX64.EFI)
    Boot0003* debian HD(1,GPT,xxxx-x-xxx,0x800,0x100000)/File(\EFI\DEBIAN\SHIMX64.EFI)
    Boot0004* Windows Boot Manager HD(1,GPT,xxxx-x-xxx-bbb,0x1000,0x96000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)..BO
    Boot0006* UEFI: SanDisk, Partition 2 PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x0)/USB(2,0)/HD(2,MBR,0x61f4c181,0x7280000,0x10000)..BO

添加当前用户sudo权限

Debian 11

root登陆

1
2
3
4
/usr/sbin/usermod -aG root userName
cd /etc/
/usr/sbin/visudo sudoers
userName ALL=(ALL:ALL) ALL

修改内核启动项

openSUSE

默认启动项索引数字是0

2022-09-03_18-50.png

  • 1是系统启动界面的第二个选项通常是高级选项
  • 2是进入高级选项之后要启动的第三个内核 这里的顺序从0开始计算

2022-09-03_18-50_1.png

vim /etc/default/grub
GRUB_DEFAULT=”1>2”

1
2
3
4
5
6
7
8
9
10
# Uncomment to set your own custom distributor. If you leave it unset or empty, the default
# policy is to determine the value from /etc/os-release
GRUB_DISTRIBUTOR=
GRUB_DEFAULT="1>2"
# GRUB_DEFAULT=saved ## 注释掉这行 改为上面那行
GRUB_HIDDEN_TIMEOUT=3
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_CMDLINE_LINUX_DEFAULT="splash=silent quiet mitigations=auto"
GRUB_CMDLINE_LINUX=""

生成配置文件(这里不需要install)

1
grub2-mkconfig -o /boot/grub2/grub.cfg

socks52http

user@host:~$ sudo apt install privoxy

  • 配置ss代理端口

    1
    2
    user@host:~$ grep socks5 -nr /etc/privoxy/config
    forward-socks5t / 127.0.0.1:1080 .
  • 重启服务

    1
    user@host:~$ systemctl restart privoxy.service
  • 终端配置

    1
    2
    user@host:~$ export http_proxy=http://127.0.0.1:8118
    user@host:~$ export https_proxy=$http_proxy
  • 验证

    1
    2
    3
    user@host:~$  curl -I www.google.com
    HTTP/1.1 200 OK
    Content-Type: text/html; charset=ISO-8859-1

关闭ext4文件系统的日志

liveCD中执行
正在挂载的盘无法关闭

  1. tune2fs -l /dev/sda3 |grep has_journal

    1
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
  2. tune2fs -O ^has_journal /dev/sda3

  3. tune2fs -l /dev/sda3 |grep has_journal 这里无输出内容为关闭

e2fsck

  • 开机出现内核错误 硬盘突然断电 SSD释放trim之后硬盘无法挂载问题等….
    1
    2
    e2fsck -c -y -v /dev/sda3

restic

备份root

这里没有备份单独分区的/boot/efi

1
2
3
4
5
restic -r /mnt/sdd1/restic-debian/ init
sudo restic -r /mnt/sdd1/restic-debian/ backup --one-file-system / --exclude=/home/ --dry-run -v -n # 试运行
sudo restic -r /mnt/sdd1/restic-debian/ backup --one-file-system / --exclude=/home/ -v # 排除/home/

sudo restic -r /mnt/sdd1/restic-debian/ backup --one-file-system / --exclude={"/home/user/.android/cache","/home/user/.android/avd","/home/user/.cache","/home/user/.config/Slack/Cache/*","/home/user/.config/Slack/Service\ Worker/CacheStorage/*","/home/user/.config/Code/Cache/*","/home/user/.dartServer/.analysis-driver/*","/home/user/.gradle/caches/*","/home/user/.gradle/native/*","/home/user/.local/share/TelegramDesktop/tdata/user_data/cache/*","/home/user/Blog/.deploy_git","/home/user/Android/Sdk/platforms/*","/home/user/flutter/.pub-cache/*","/home/user/.pub-cache/*","/home/user/.npm/_cacache/*","/home/user/Download/*"} -v # 全备份
  • 查看备份

    1
    sudo restic -r /mnt/sdd1/restic-debian/ snapshots
  • 列出备份详细

    1
    sudo restic -r /mnt/sdd1/restic-debian/ ls b9bf4ab3

添加tag

为快照b9bf4ab3添加一个名为root的tag

  • 添加之前
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ snapshots
    [sudo] user 的密码:
    enter password for repository:
1
2
3
4
5
6
7
repository d13c80ec opened (repository version 2) successfully, password is correct
ID Time Host Tags Paths
------------------------------------------------------------
b9bf4ab3 2022-09-12 12:02:35 host /
2e7272ea 2022-09-12 12:16:07 host /
------------------------------------------------------------
2 snapshots
  • 添加tag
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ tag –add root b9bf4ab3
    enter password for repository:
1
2
3
repository d13c80ec opened (repository version 2) successfully, password is correct
create exclusive lock for repository
modified tags on 1 snapshots
  • 查看
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ snapshots
    enter password for repository:
    wrong password or no key found. Try again
    enter password for repository:
1
2
3
4
5
6
7
repository d13c80ec opened (repository version 2) successfully, password is correct
ID Time Host Tags Paths
------------------------------------------------------------
2844a1f2 2022-09-12 12:02:35 host root /
2e7272ea 2022-09-12 12:16:07 host /
------------------------------------------------------------
2 snapshots

单独备份home

1
2
3
user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ backup --tag home-none /home/ --exclude={"/home/user/.android/*","/home/user/.cache/*","/home/user/.config/Slack/Cache/*","/home/user/.config/Slack/Service\ Worker/CacheStorage/*","/home/user/.config/Code/Cache/*","/home/user/.dartServer/*","/home/user/.gradle/*","/home/user/.local/share/TelegramDesktop/tdata/user_data/cache/*","/home/user/Blog/.deploy_git","/home/user/Android/*","/home/user/flutter/*","/home/user/.pub-cache/*","/home/user/.npm/*","/home/user/Download/*","/home/user/go/pkg/mod/*","/home/user/android-studio/*","/home/user/Sync/other/*","/home/user/Sync/zysj/*"."/home/user/nfs_share/*"} -v
open repository
enter password for repository:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
repository d13c80ec opened (repository version 2) successfully, password is correct
lock repository
no parent snapshot found, will read all files
load index files
start scan on [/home/]
start backup on [/home/]
scan finished in 15.199s: 40496 files, 30.927 GiB

Files: 40496 new, 0 changed, 0 unmodified
Dirs: 10607 new, 0 changed, 0 unmodified
Data Blobs: 648 new
Tree Blobs: 10256 new
Added to the repository: 95.169 MiB (35.447 MiB stored)

processed 40496 files, 30.927 GiB in 1:53
snapshot 053932fb saved
  • 查看
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ snapshots
    enter password for repository:
1
2
3
4
5
6
7
8
repository d13c80ec opened (repository version 2) successfully, password is correct
ID Time Host Tags Paths
-------------------------------------------------------------
2844a1f2 2022-09-12 12:02:35 host root /
00d40601 2022-09-12 12:16:07 host rootAndHome /
053932fb 2022-09-12 19:33:30 host home-none /home
-------------------------------------------------------------
3 snapshots

check

user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ check

1
2
3
4
5
74 additional files were found in the repo, which likely contain duplicate data.
This is non-critical, you can run `restic prune` to correct this.
check snapshots, trees and blobs
[0:02] 100.00% 3 / 3 snapshots
no errors were found
  • prune
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ prune
    enter password for repository:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
repository d13c80ec opened (repository version 2) successfully, password is correct
loading indexes...
loading all snapshots...
finding data that is still in use for 3 snapshots
[0:02] 100.00% 3 / 3 snapshots
searching used packs...
collecting packs for deletion and repacking
[0:00] 100.00% 2777 / 2777 packs processed

to repack: 0 blobs / 0 B
this removes: 0 blobs / 0 B
to delete: 0 blobs / 1.230 GiB
total prune: 0 blobs / 1.230 GiB
remaining: 463912 blobs / 45.564 GiB
unused size after prune: 0 B (0.00% of remaining size)

deleting unreferenced packs
[0:00] 100.00% 74 / 74 files deleted
done
  • check
    user@host:~$ sudo restic -r /mnt/sdd1/restic-debian/ check
    using temporary cache in /tmp/restic-check-cache-2133091447
    enter password for repository:
1
2
3
4
5
6
7
8
repository d13c80ec opened (repository version 2) successfully, password is correct
created new cache in /tmp/restic-check-cache-2133091447
create exclusive lock for repository
load indexes
check all packs
check snapshots, trees and blobs
[0:02] 100.00% 3 / 3 snapshots
no errors were found

恢复单个文件

1
sudo restic -r /mnt/sdd1/restic-debian/ restore b4e97487 --target / --include /home/user/xxx.tar.gz

使用gpg加密密码文件

  1. 创建一个保存密码的文件并写入备份密码
  2. 使用gpg加密这个文件
  3. 输入gpg密码来备份
    1
    gpg --decrypt gpg加密的密码文件.gpg |  restic -r ......

debug-shell

systemd 系统忘记密码以root登入

1
systemd.debug-shell=1 #Ctrl + F9

40_custom

通过grub2启动iso(clonezilla-live-2.8.1-12-amd64.iso)

查看要启动的iso信息

40custom.png

编写配置文件

1
2
cd /etc/grub.d/
vim 40_custom
  • 40_custom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

# path to the partition holding ISO images (using UUID)
probe -u $root --set=rootuuid
set imgdevpath="/dev/disk/by-uuid/$rootuuid"

menuentry "clonezilla-live-2.8.1-12-amd64.iso" {
set isofile="/iso/clonezilla-live-2.8.1-12-amd64.iso"
load_video
set gfxpayload=keep
# insmod gzip # /boot/grub/x86_64-efi/gzip.mod not found
insmod part_gpt
insmod ext2
loopback aloop (hd3,gpt2)$isofile # (hd3,gpt2)的数字可能会在重启后变化 ls找到就可以
linux (aloop)/live/vmlinuz boot=live findiso=$isofile live-media-path=/live components
initrd (aloop)/live/initrd.img
}
  • 生成grub配置文件
    生成grub.cfg后会在grub启动界面看到clonezilla-live-2.8.1-12-amd64.iso

    1
    sudo grub-mkconfig -o /boot/grub/grub.cfg
  • reboot

设置grub

loopback aloop (hd3,gpt2)$isofile 这里的(hd3,gpt2)是系统重启后对应之前存放clonezilla-live-2.8.1-12-amd64.iso的路径
如果提示iso文件没有找到

  • 先列出一个可能的磁盘路径 如果不是就继续 直到(hdx,gptx)/iso/ 列出clonezilla-live-2.8.1-12-amd64.iso
    1
    ls -l (hd3,gpt1)/
    40custom-grub.png

成功启动

40custom-diff.png


openssl

有效期 day=365
Common Name (e.g. server FQDN or YOUR name) []: 这里写网站 www.example.com

1
2
3
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Certificate request self-signature ok
subject=C = AU, ST = Some-State, O = Internet Widgits Pty Ltd, CN = www.example.top, emailAddress = abc@example.com

推荐文章