
linux
search_star
个人博客seekstar.github.io
展开
-
解决virtualbox安装debian时要下载很久的问题
在创建虚拟机时在网络选项中把高级选项里的“插入网线”给取消掉。这样安装过程就只会读取安装镜像里的东西,就很快了。但是会出现DHCP设置错误。选择“现在不进行网络设置”即可。安装完成后再“接入网线”即可。...原创 2020-03-03 23:09:07 · 1495 阅读 · 0 评论 -
使用apt更改内核版本
有一些代码依赖于特定的内核版本,而如果安装系统之后发现内核版本对不上之后就要更换内核。重新编译内核十分麻烦而且耗时,万幸的是debian系列(ubuntu、mint等)可以使用apt来方便地更改内核版本。先执行apt-cache search linux-image-4.*获得仓库中有哪些版本的第4代linux内核。例如如果想要更换内核版本为4.15.0-70,那么就执行以下命令su...原创 2020-01-19 20:11:18 · 1469 阅读 · 0 评论 -
bash隐藏当前工作目录
详细教程:https://blog.youkuaiyun.com/xjwJava/article/details/8687969查看当前的设置:echo $PS1我的结果:\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$然后把里面的\w去掉就好了:export PS1="\[\e]0;\u@\h: \w\a\]${de原创 2021-10-20 15:56:07 · 421 阅读 · 0 评论 -
Linux pdf编辑软件
XournalFile->Annotate PDF->找到要编辑的PDF文件Tools里选择Pen可以画线,选择Eraser可以擦掉画的线,但是不能擦掉原有内容,选择Highlighter可以当荧光笔用,选择Text可以插入文字,选择Image可以插入图片,选择Select Region可以移动插入的图片。Okular可以插入文本框,可以插入弹出式笔记,可以画线之类的,但是不能插入图片。libreoffice draw打开有些文档会卡死。而且就算能打开,好像里面的字会错位?Scri原创 2021-10-10 10:17:04 · 513 阅读 · 0 评论 -
解决shell脚本中kill -2对后台进程不起作用
问题kill -2就是发送SIGINT信号。我们期望的行为是,进程接收到SIGINT信号后就停止运行。例如:yes >/dev/null &pid=$!echo $pidsleep 2kill -INT $pidsleep 2ps aux | grep yes将其保存为kill.sh,让其直接在当前交互式shell里执行:source kill.sh结果:21505[1]+ 中断 yes > /dev/nullsearc原创 2021-10-04 23:04:07 · 2759 阅读 · 15 评论 -
linux perf得到完整调用关系
一般情况下,在高优化等级时,编译器会把栈帧破坏掉,导致生成的火焰图调用关系是错误的。即使自己的代码用了-fno-omit-frame-pointer来编译,从而使得自己的代码不破坏栈帧,库的代码可能仍然会破坏栈帧。这时就应该使用linux perf的--call-graph=dwarf,这样perf会把一部分栈内存保存下来,然后通过后处理来unwind,从而得到完整的调用栈。参考文献:https://users.rust-lang.org/t/opt-level-2-removes-debug-symb原创 2021-09-20 10:38:42 · 1131 阅读 · 0 评论 -
在服务器上使用vtune
安装在这里选择合适的下载方式:https://software.intel.com/content/www/cn/zh/develop/tools/oneapi/base-toolkit/download.html如果没有GUI,就用Command Line Installation里的命令来下载安装。我的是这样的:wget https://registrationcenter-download.intel.com/akdlm/irc_nas/17769/l_BaseKit_p_2021.2.0.28原创 2021-09-19 15:57:05 · 3170 阅读 · 0 评论 -
perf.data生成火焰图
用perf或者别的东西生成perf.data后,可以用如下方法生成火焰图:先把https://github.com/brendangregg/FlameGraph.git clone到某个目录,然后perf script -i perf.data > perf.unfold/path/to/FlameGraph/stackcollapse-perf.pl perf.unfold > perf.folded/path/to/FlameGraph/flamegraph.pl perf.fol转载 2021-09-16 10:40:41 · 853 阅读 · 0 评论 -
linux获取进程的用户时间 系统时间等
在/proc/[pid]/stat里有该进程的详细信息。其内容的解释可以在man 5 proc里查看(搜/stat)相关部分如下:(14) utime%lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). This includes guest翻译 2021-08-17 15:53:46 · 340 阅读 · 0 评论 -
centos端口转发
比方说监听本地的23333端口,将数据都转发到10.249.40.227的22端口上,可以这样:sudo yum install nmap-ncatncat --sh-exec "ncat 10.249.40.227 22" -l 23333 --keep-open如果要后台运行:nohup ncat --sh-exec "ncat 10.249.40.227 22" -l 23333 --keep-open &然后查看一下23333端口是否开放了:sudo firewall-cmd原创 2021-08-14 19:41:48 · 1565 阅读 · 0 评论 -
deepin设置静态IP
# enp0s2 是网卡名称auto enp0s2iface enp0s2 inet staticaddress 10.249.44.127netmask 255.255.248.0gateway 10.249.40.1dns-nameserver 10.248.98.30网卡名字和当前子网掩码可以通过ip addr看。当前网关可以通过route -n查看。当前dns服务器的IP在/etc/resolv.conf里。重启网络:sudo /etc/init.d/networking r原创 2021-08-14 19:00:46 · 1412 阅读 · 0 评论 -
WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases
/usr/share/doc/tigervnc/HOWTO.md里有新版本的使用方法。这里放一下简单的用法。sudo vim /etc/tigervnc/vncserver.users里面加上一行::1=searchstar其中searchstar是我的用户名,要换成你自己的用户名。设置当前用户的vnc密码:vncpasswdrestorecon -RFv ~/.vnc开启服务:sudo systemctl start vncserver@:1systemctl status vn原创 2021-08-12 21:00:46 · 4427 阅读 · 0 评论 -
centos8编译安装libvirt 7.6
https://bugzilla.redhat.com/show_bug.cgi?id=1894053https://www.cnblogs.com/wrencai/p/4513116.htmlhttps://libvirt.org/sources/https://blog.youkuaiyun.com/zencher/article/details/47316357https://blog.youkuaiyun.com/clever_wr/article/details/102807942原创 2021-08-11 21:50:07 · 2358 阅读 · 12 评论 -
服务器双网口路由问题
如果两个网口都是默认路由,那就会导致一个网口的IP ssh不进去。这时把一个网口设置成非默认路由就好了。方法是修改/etc/sysconfig/network-scripts/ifcfg-要修改的设备名,把里面的DEFROUTE=yes改成DEFROUTE=no,然后重启网络/etc/init.d/network restart。参考:Linux系统下修改IP地址、网关、DNS的基本方法_LINUX_操作系统_脚本之家...原创 2021-08-09 18:48:17 · 1257 阅读 · 0 评论 -
virsh终端访问虚拟机并联网
这里假设domain的名字设置成centos8。先写一个centos8.xml,定义虚拟机的基本属性:<domain type='kvm'> <name>centos8</name> <memory unit='GiB'>1</memory> <os> <type arch='x86_64'>hvm</type> </os> <devices>原创 2021-08-08 05:18:41 · 1016 阅读 · 0 评论 -
total-vm anon-rss file-rss shmem-rss含义
进程被杀了。查一下日志:dmesg | egrep -i -B100 'killed process'[2352218.368085] Out of memory: Kill process 1462 (transaction-exp) score 834 or sacrifice child[2352218.368850] Killed process 1462 (transaction-exp) total-vm:18307836kB, anon-rss:13871180kB, file-rss原创 2021-07-28 14:44:31 · 19013 阅读 · 0 评论 -
CentOS 8创建TAP/TUN设备
CentOS 7还有nux-misc里的tunctl可以用,CentOS 8连那个都没有了。不过可以用ip创建:ip tuntap add tap0 mod tap删除:ip tuntap del tap0 mod tap列出所有:ip tuntap list查看帮助:ip tuntap help参考文献:https://www.mylinuxplace.com/create-taptun-device-centos-7/...原创 2021-07-26 14:57:45 · 916 阅读 · 0 评论 -
qemu-system-x86_64 nographic
即使把图形界面删掉了,仍然是默认输出到显示器上的,这样nographic选项就没啥用。为了使其产生作用,在虚拟机中将/etc/default/grub里的GRUB_CMDLINE_LINUX=""改成GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,9600n8"然后sudo update-grub这样输出就会被重定向到终端了。然后sudo qemu-system-x86_64 -m 4096 -enable-kvm deepin.img -n原创 2021-07-26 14:12:03 · 2070 阅读 · 0 评论 -
Linux服务器重启之后IP改变的一种解决方案
一种方案是改成静态IP,但是有点麻烦。其实还有一种方法,就是让服务器开机之后自动把IP发送给一个已知IP的服务器,这样如果重启之后一直连不上,就可以到另一个已知IP的服务器上查看发送过来的IP,从而得知服务器的新IP。方法就是在/etc/rc.local里加上IPfile=$(mktemp)nohup bash -c "sleep 10 && ip addr > $IPfile && scp -i /home/searchstar/.ssh/id_rsa_get原创 2021-07-25 18:06:01 · 1924 阅读 · 0 评论 -
Linux多线程复制目录
比如有一个目录a需要复制:mkdir atouch a/amkdir a/btouch a/b/ctree aa├── a└── b └── c将其复制为目录d只需要用find找出目录下所有的文件,然后用gnu-parallel开多线程逐个复制即可:mkdir dcd afind . -type f | parallel cp --parents {} ../dtree ../d../d├── a└── b └── c...原创 2021-07-21 13:13:08 · 1126 阅读 · 0 评论 -
xfs开启reflink
这个要在格式化的时候就开启reflink的功能。先备份数据,然后格式化mkfs.xfs -m reflink=1 -f /dev/vdb1然后再重新mount就好了。原创 2021-07-02 10:35:03 · 1471 阅读 · 0 评论 -
Linux创建只读目录链接
相当于让一个可写的目录软链接到另一个地方变成只读的目录,但是原目录仍然保持可写。解决方法是用mount --bind,将目录挂载到目标点,变成只读文件系统。mount --bind -r /path/to/source/ /path/to/dest/umount /path/to/dest/原文:https://askubuntu.com/questions/243380/how-to-create-a-read-only-link-to-a-directory...翻译 2021-07-01 16:55:49 · 790 阅读 · 0 评论 -
linux shell查看实时网速
sudo apt install jnettopjnettop原创 2021-07-01 11:17:57 · 884 阅读 · 0 评论 -
no arrays found in config file or automatically
原因是安装其他操作系统时共用了swap分区,导致uuid变化了。一种方法是重新指定新的uuid:https://blog.youkuaiyun.com/KuXiaoQuShiHuai/article/details/99686620另一种方法是直接把swap分区给禁用掉。sudo rm /etc/mdadm/mdadm.confupdate-initramfs -u然后修改/etc/fstab,把swap分区那行给注释掉# /dev/nvme0n1p3#UUID=2589c54c-1093-43b4原创 2021-06-02 13:13:47 · 3747 阅读 · 1 评论 -
Centos8安装ZFS
查看当前centos版本号cat /etc/redhat-releaseCentOS Linux release 8.3.2011然后sudo dnf install https://zfsonlinux.org/epel/zfs-release.<dist>.noarch.rpmgpg --import --import-options show-only /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux其中<dist>换成版本号,比原创 2021-05-04 17:21:05 · 1151 阅读 · 0 评论 -
screen基础用法
新建screenscreendetach:ctrl+a d重连:screen -lsThere is a screen on: 210569.pts-0.localhost (Detached)1 Socket in /run/screen/S-searchstar.screen -r 210569或者screen -r后按一下tab,会自动帮你补全。上翻:ctrl+a ESC进入复制模式(copy mode),然后就可以按照vim的方式翻页了。...原创 2021-03-20 09:14:23 · 700 阅读 · 0 评论 -
WPS for linux移动云文档
我一度以为WPS for linux无法移动云文档直到看到这篇文章:https://jingyan.baidu.com/article/f3e34a12195113f5ea653545.html点击这里你会看到一个新的界面然后就可以通过ctrl+x ctrl+v或者拖动来移动了。为什么开发团队不直接把这个并到主页上呢。。。...原创 2021-03-12 23:58:48 · 531 阅读 · 0 评论 -
grub-installer fatal error
我把EFI分区的类型从逻辑分区改成主分区就好了。好像除了EFI分区,所有分区都可以是逻辑分区,包括挂载到/的分区。原创 2021-02-04 11:57:32 · 218 阅读 · 0 评论 -
ubuntu清理/var/log
参考:https://askubuntu.com/questions/239455/how-do-i-stop-var-log-kern-log-1-from-consuming-all-my-disk-space/239491sudo rm /var/log/kern* &>/dev/nullsudo rm /var/log/messages* &>/dev/null这些好像基本上是被备份的dmesg。原创 2021-01-31 10:44:45 · 1274 阅读 · 0 评论 -
qemu挂载物理磁盘
参考:https://askubuntu.com/questions/572913/qemu-connect-physical-disk使用选项-hdb /dev/sdX即可。进虚拟机之后就可以看到/dev/sdb了。然后用mount命令挂载即可。原创 2021-01-21 21:37:02 · 2376 阅读 · 0 评论 -
在服务器上用qemu制作虚拟机
GUI虚拟机https://my.oschina.net/kelvinxupt/blog/265108CLI虚拟机sudo apt install qemu qemu-kvmhttps://blog.youkuaiyun.com/richardysteven/article/details/6701181https://zhuanlan.zhihu.com/p/105069730?utm_source=wechat_sessionhttps://01.org/linuxgraphics/gfx-docs/原创 2021-01-21 18:55:15 · 2580 阅读 · 1 评论 -
vnc root窗口无法弹出
参考:https://blog.youkuaiyun.com/xeseo/article/details/11963473sudo xclockX11 connection rejected because of wrong authentication.Error: Can't open display: localhost:10.0先查看当前终端的DISPLAYecho $DISPLAYlocalhost:10.0xauth listsearchstar-PC/unix:0 MIT-MA原创 2021-01-21 09:45:45 · 1020 阅读 · 1 评论 -
vnc通过ssh隧道连接到Linux服务器
参考:http://www.zsythink.net/archives/2450https://blog.youkuaiyun.com/cuma2369/article/details/107668471服务器sudo apt install tightvncservervncserversearchstar@L1707:~$ vncserverYou will require a password to access your desktops.Password: Warning: pass原创 2021-01-20 20:56:41 · 3862 阅读 · 0 评论 -
linux强制重启
参考:https://unix.stackexchange.com/questions/442932/reboot-is-not-workingecho 1 > /proc/sys/kernel/sysrqecho b > /proc/sysrq-trigger这东西好像比reboot -nf还狠。原创 2021-01-15 17:24:03 · 558 阅读 · 0 评论 -
bash计算浮点数
echo "2 / 3" | bc -l.66666666666666666666如果想要前导零echo "2 / 3" | bc -l | xargs printf "%f"这里还有一堆解决方案:https://stackoverflow.com/questions/8402181/how-do-i-get-bc1-to-print-the-leading-zero参考文献https://blog.youkuaiyun.com/hanhaixingchen/article/details/71707原创 2021-01-07 23:55:01 · 339 阅读 · 0 评论 -
Linux服务器查看哪些人在用
w和who只能查看哪些人登陆了,但是如果是用vscode登陆的就看不到,只有一个node进程。而且如果有人在后台跑程序也看不到。所以需要一个可以查看系统中哪些人的进程在跑的命令:ps -e -o uid --no-headers | awk '$1 >= 1000' | sort -u | xargs -i id -nu {}这里只显示uid大于等于1000的用户,因为小于1000的不是真实用户。不过看样子uid大于1000的用户也可能不是真实用户,比如上图的systemd-timesync原创 2021-01-07 19:48:50 · 3562 阅读 · 1 评论 -
chroot时硬链接ldd依赖的脚本
chroot_ln_file.sh#!/bin/bashmkdir -p $(dirname $2/$1)ln $1 $2/$1 &> /dev/nullori=$(readlink $1)if [ -n "$ori" ]; then real=$(realpath -s $ori) if [[ "$real" == "$ori" ]]; then $0 $real $2 else $0 $(dirname $1)/$ori $2 fifichroot_lns原创 2020-06-06 18:32:41 · 249 阅读 · 0 评论 -
bash查询某文件的绝对路径
用realpath即可。searchstar@searchstar-PC:/tmp/test$ lschroot test2.sh test3.sh test4.sh test5.sh test.shsearchstar@searchstar-PC:/tmp/test$ realpath test3.sh /tmp/test/test3.sh原创 2020-06-05 15:13:47 · 648 阅读 · 0 评论 -
sh -c中使用变量
参考链接:https://unix.stackexchange.com/questions/23179/how-to-send-variable-to-an-inline-shell-scriptto=$(pwd)/table.txtsh -c ‘echo 2333 $to’输出2333,没有to指向的路径。解决方案:把to变成环境变量。to=$(pwd)/table.txtsh -c...原创 2019-10-07 13:48:05 · 1203 阅读 · 0 评论 -
非交互从github中下载最新版安装包
这里以drawio-desktop为例。github链接:https://github.com/jgraph/drawio-desktop使用github api来获取这个项目最新的releasecurl -s https://api.github.com/repos/jgraph/drawio-desktop/releases/latest输出一个json,描述了可供下载的一些文件的信息。提取出deb包的url所在的行curl -s https://api.github.com/repos/j原创 2020-10-31 17:26:26 · 548 阅读 · 0 评论