MemTotal: 16002428 kB # 内核和系统可以使用的内存大小 MemFree: 12692524 kB # 系统尚未使用的内存 MemAvailable: 14358188 kB # free+可以被回收的内存大小 Buffers: 64908 kB # 块设备的缓存页 Cached: 1990844 kB # 磁盘或文件系统的内存缓存 SwapCached: 0 kB # 交换分区的内存缓存 Active: 955104 kB # 最近比较活跃的内存,可回收的 Inactive: 1851012 kB # 不活跃的内存 Active(anon): 2160 kB # cache里面的匿名的活跃内存 Inactive(anon): 928056 kB # cache里面的匿名的不活跃内存 Active(file): 952944 kB # cache里面的活跃内存 Inactive(file): 922956 kB # cache里面的不活跃内存 Unevictable: 188200 kB # 被内核认为无法回收的内存 Mlocked: 0 kB # mlock锁住的内存 SwapTotal: 902700 kB # swap的内存 SwapFree: 902700 kB # swap的可用内存 Dirty: 0 kB # 等待回写的脏页 Dirty+NFS_Unstable+Writeback=脏页 Writeback: 0 kB # 正在回写的脏页 AnonPages: 938576 kB # 匿名页 Mapped: 434276 kB # 被映射的页,例如库,二进制,mmap过的 Shmem: 191716 kB # 共享内存或tmpfs或devtmpfs KReclaimable: 100012 kB # 内核可被回收的内存 Slab: 202148 kB # SReclaimable+SUnreclaim SReclaimable: 100012 kB # slab中可以被回收的内存 SUnreclaim: 102136 kB # slab中不可以被回收的内存 KernelStack: 9904 kB # 给用户线程分配的内核栈消耗的页 PageTables: 16356 kB # 页表占用内存,内存占用越多使用的页表就越多 NFS_Unstable: 0 kB # 给nfs 服务的缓存 Bounce: 0 kB # 给块设备的bounce buffers WritebackTmp: 0 kB # 给用户文件系统FUSE的临时回写内存 CommitLimit: 8903912 kB # 提交虚拟内存的最大大小,也就是虚拟内存的最大申请内存值 Committed_AS: 4856984 kB # 当前系统的虚拟内存分配量 VmallocTotal: 34359738367 kB # 可用于vmalloc申请的内存大小 VmallocUsed: 33552 kB # 已用的虚拟内存大小 VmallocChunk: 0 kB # 虚拟内存最大的连续块 Percpu: 8896 kB # 给percpu机制申请器使用的内存 HardwareCorrupted: 0 kB # 内核察觉出内存出错的大小计数 AnonHugePages: 2048 kB # 给用户空间的匿名大页 ShmemHugePages: 0 kB # 给shmem和tmpfs的大页 ShmemPmdMapped: 0 kB # 已映射过的shmem大页 FileHugePages: 0 kB # 映射文件的大页 FilePmdMapped: 0 kB # 已映射过的文件的大页 HugePages_Total: 0 # 总共大页内存大小 HugePages_Free: 0 # 剩余的大页大小 HugePages_Rsvd: 0 # 预申请的大页,也就是申请了没有的 HugePages_Surp: 0 # 大页池的剩余 Hugepagesize: 2048 kB # 大页大小 Hugetlb: 0 kB # Hugetlbfs 的大页使用清除 DirectMap4k: 235016 kB # 可以映射4k页面的数量 DirectMap2M: 4624384 kB # 可以映射2M页面的数量 DirectMap1G: 11534336 kB # 可以映射1G页面的数量
https://www.kernel.org/doc/Documentation/filesystems/proc.rst http://linuxperf.com/?p=142 http://www.javashuo.com/article/p-dgjqhxgd-nc.html
随着git项目越来越多,每次环境部署的时候,不可能一个一个去clone仓库,这样太费事了。为了偷懒,我借鉴了android的repo机制,这样可以自行对自己的git仓库搭建一个简单的repo,之后使用这个repo就能方便的管理多个git仓库了。
git clone https://gerrit.googlesource.com/git-repo
由于repo会把repo url默认到
这里需要本地git地址。也可修改成gitlab地址。如下
REPO_URL = 'http://ip/git-repo.git'
git init --bare manifests.git git clone /root/work2/git/manifests.git vim manifests.git <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote fetch="ssh://root@172.25.130.31/root/work2/git" name="origin"/> <default remote="origin" revision="master" sync-j="4"/> <project name="test1" path="test1"/> <project name="test2" path="test2"/> <project name="test3" path="test3"/> </manifest> git add . && git commit -m "first commit" && git push
这里通过编写xml,设置远端的git仓库为root@172.25.130.31/root/work2/git, 远端的分支名字为origin,默认的remote为origin,版本分支为master,一共三个工程,分别为test1 test2 test3,并在本地创建同样的目录名字。
这样即可编写一个最简单的manifests.xml。后续可以使用这个xml来管理整个git仓库
repo init -u root@172.25.130.31:/root/work2/git/manifests.git repo sync
此时可以看到三个仓库被正常的拉取
[root@localhost 3]# ls test1 test2 test3
在repo不断更新的过程中,可以生成快照,实际上就是生成一个xml文件,它保持了当时的repo状态,可供其他人使用。
这个类似于git tag。当需要整体出一个版本的时候,可以直接生成快照。
repo manifest -r -o tag_v1.0.xml <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote fetch="ssh://root@172.25.130.31/root/work2/git" name="origin"/> <default remote="origin" revision="master" sync-j="4"/> <project dest-branch="master" name="test1" revision="831a146ccf46fe060c74f15354e9d68c3e0afbcb" upstream="master"/> <project dest-branch="master" name="test2" revision="829b53cce4538d5ae5919bc42bea7254bc1dcd9b" upstream="master"/> <project dest-branch="master" name="test3" revision="750f8d272da0b85a7bb7c42427fe9f0c72d416be" upstream="master"/> </manifest>
这里就比较显而易见了,快照保持了每个分支的分支信息,commit信息和上游信息
查看分支状态
repo status
为某个分支创建新的branch
repo start bug_1.2 test1
上面这个命令等同于
git checkout -b bug_1.4
查看分支信息
repo branch
查看所有分支的diff
repo diff
默认的xml头
<?xml version="1.0" encoding="UTF-8"?>
顶层manifest元素
<manifest> </manifest>
<remote /> name 这里的name是git remote的那个远程名字,默认是origin。如果是git的remote是其他的,这里填写对应即可 fetch 这里是git的地址,如果是ssh可以是:ssh://root@172.25.130.31/root/work2/git 如果是http或者git,就是github/gitlab上的地址 pushurl 这里是push的地址,当指定该属性的时候,这个值会和<project>标签中的name属性拼成完整的push url路径,这样当我们使用git push命令的时候,就会使用该url。如果不指定该属性,则pushurl和fetch一样。 revision 这里是默认的git branch名字。可以是master或者其他
<default /> remote 这里是remote设置的名字,代表repo拉的分支默认使用哪个remote上的 revision 当一个<project>不指定revision的时候使用该值 dest-branch 默认创建的本地分支,如果不指定,就是revision默认创建的分支 sync-j repo sync的并行数目 sync-c 如果设置为true,则只同步指定的分支(revision 属性指定),而不是所有的ref内容 sync-s 如果设置为true,则会同步git的子项目 sync-tags
<project /> name: 这里是工程名也就是哪个仓库 ${remote_fetch}/${project_name}.git path: 显式声明的存放文件路径 remote: 这里指定的远程分支名字 revision: 这里指定需要获取的git提交点,可以是master, refs/heads/master, tag或者SHA-1值。如果不设置的话,默认下载当前project,当前分支上的最新代码。 upstream: 在哪个git分支可以找到一个SHA1。用于同步revision锁定的manifest(-c 模式
xml可以直接include子xml。通过如下方式 <manifest> <include name="default.xml" /> </manifest>
<project name="test1" path="test1"> <linkfile dest="Readme" src="Readme"/> <copyfile dest="Readme.md1" src="Readme.md"/> </project>
在project下面设置可以设置软连接和拷贝。实际上等效于如下
ln -s test1/Readme Readme cp test1/Readme.md Readme.md1 ``` ## 参考链接 ``` https://gerrit-googlesource.proxy.ustclug.org/git-repo https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md ```
记录一下ssh相关配置,随时查询用
ssh-keygen -C name@mail.com ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip
ssh-keygen ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip vim ~/.ssh/config Host tf HostName 172.25.80.123 Port 22 User root IdentityFile ~/.ssh/id_rsa ssh tf
vim /etc/ssh/sshd_config
增加一行记录:UseDNS no
发现:Next authentication method: gssapi-with-mic
vim /etc/ssh/sshd_config
vim /etc/ssh/ssh_config
修改GSSAPIAuthentication参数为no
dd if=/dev/mmcblk1p4 | ssh root@ip dd of=~/backup.img
tar cvzf - package_dir/ | ssh root@ip "cd ~/backup ;cat >backup_file.tar.gz"
/etc/ssh/sshd_config PermitRootLogin yes
mount devpts /dev/pts -t devpts
ssh-keygen -f "~/.ssh/known_hosts" -R ip
~/.ssh/config Host * KexAlgorithms +diffie-hellman-group1-sha1
AllowTcpForwarding 默认yes,可以no关闭
PermitTunnel 是否允许 tun 设备转发。可用值如下: "yes", "point-to-point", "ethernet", "no"(默认) "yes"同时蕴含着"point-to-point"和"ethernet"
在使用服务器编译代码的时候,因为最近有一个组raid的过程,所以使用的空间是格式化过的。空间虽然大了,但是编译速度却下降很多,十分苦恼。
/dev/sdc1 7.3T 328G 6.6T 5% /root/public-workspace
主要原因是格式化时是直接使用mkfs.ext4命令格式,所以它默认带数据日志的。
ext4 支持多个模式
Data ordering is not preserved, data may be written into the main file system after its metadata has been committed to the journal.
数据和日志写入主文件,但是无顺序的 2. Ordered 模式
All data are forced directly out to the main file system prior to its metadata being committed to the journal.
数据在写日志之前进入主文件
All data are committed into the journal prior to being written into the main file system. Enabling this mode will disable delayed allocation and O_DIRECT support.
所有数据到主文件都是在日志之后
Don't load the journal on mounting. Note that if the filesystem was not unmounted cleanly, skipping the journal replay will lead to the filesystem containing inconsistencies that can lead to any number of problems. 挂载时不加载日志,但是如果文件系统卸载不干净的时候将会导致文件系统的各类问题。
Ext4 can be told to sync all its data and metadata every 'nrsec' seconds. The default value is 5 seconds. This means that if you lose your power, you will lose as much as the latest 5 seconds of work (your filesystem will not be damaged though, thanks to the journaling). This default value (or any low value) will hurt performance, but it's good for data-safety. Setting it to 0 will have the same effect as leaving it at the default (5 seconds). Setting it to very large values will improve performance. 设置commit的时间,默认5s,如果设置提交时间太短,则影响性能,设置时间过长可提高性能,但是异常断电的时候会丢最近nrsec的内容
根据上面的介绍,我可以有两个方式
对于1,我选择60秒同步一次日志,如下设置(/etc/fstab)
LABEL=public-workspace /root/public-workspace ext4 nofail,auto,noatime,data=ordered,commit=60 0 0
对于2,我选择关闭日志,如下设置
LABEL=public-workspace /root/public-workspace ext4 nofail,auto,noatime,noload,norecovery 0 0
最后我选择2,选择权在自己手上,风险自己能把握住就行。
https://www.kernel.org/doc/Documentation/filesystems/ext4.txt
工作需要ubuntu2004的chroot开发环境,故这里记录搭建ubuntu2004的chroot环境。
如下:
mkdir iso && mount ubuntu-20.04.6-desktop-amd64.iso iso/ unsquashfs iso/casper/filesystem.squashfs umount iso && rm -rf iso
为了能够chroot的一些编译工作正常,更真实的模拟实际环境,这里需要和linux启动一致,挂载必要的文件系统如下:
vim 1-chroot #!/bin/bash CHROOT_DIR=/root/sdk/chroot/squashfs-root [ ! -d ${CHROOT_DIR} ] && exit cd ${CHROOT_DIR} mountpoint -q ./proc || mount -t proc proc ./proc mountpoint -q ./sys || mount -t sysfs sysfs ./sys mountpoint -q ./dev || mount -t devtmpfs devtmpfs ./dev mountpoint -q ./dev/pts || mount -t devpts devpts ./dev/pts chroot .
为了能够全局使用,可以放在/usr/local/sbin/下面
mv 1-chroot /usr/local/sbin/
到这里,chroot环境已经基本成型,下面需要针对这个chroot环境做一些易用的改动。
配置源之前先设置dns,这里是chroot环境,所以直接修改resolv.conf文件,这里以114为例
nameserver 114.114.114.114
然后修改源地址为国内,修改文件/etc/apt/sources.list如下
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted deb http://mirrors.aliyun.com/ubuntu/ focal universe deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe deb http://mirrors.aliyun.com/ubuntu/ focal multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted deb http://mirrors.aliyun.com/ubuntu/ focal-security universe deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
最后update一下即可
为了避免reboot和一些低级操作,这里需要处理一下(在特殊情况下会生效),故如下
vim /etc/profile.d/chroot.sh hint_reboot(){ info="Forbidden reboot!" echo -e "\033[31m${info}\033[0m" } hint_poweroff(){ info="Forbidden poweroff!" echo -e "\033[31m${info}\033[0m" } hint_halt(){ info="Forbidden halt!" echo -e "\033[31m${info}\033[0m" } alias reboot='hint_reboot' alias poweroff='hint_poweroff' alias halt='hint_halt'
为了提示自己是在chroot环境中,修改bashrc如下:
vim /root/.bashrc # 1.修改TERM为xterm-color TERM=xterm-color cd source /etc/profile.d/chroot.sh # 2.修改\h为chroot 54 if [ "$color_prompt" = yes ]; then 55 # PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 56 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@chroot\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 57 else 58 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' 59 fi ......
基础开发环境包安装
apt-get install git ssh make gcc libssl-dev liblz4-tool expect \ g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support \ qemu-user-static live-build bison flex fakeroot cmake gcc-multilib \ g++-multilib unzip device-tree-compiler ncurses-dev rsync gdb-multiarch \ openocd qemu-system-arm cargo doxygen apt-get install libgucharmap-2-90-dev bzip2 expat gpgv2 \ cpp-aarch64-linux-gnu libgmp-dev libmpc-dev bc python-is-python3 \ python2 libsqlite3-dev esmtp codespell python-ply mutt tig u-boot-tools \ meson ninja-build u-boot-tools build-essential devscripts breeze-dev \ debhelper extra-cmake-modules libcap-dev libxcb-composite0-dev \ libdrm-dev libgbm-dev libxcb-cursor-dev libxcb-damage0-dev \ libxcb-glx0-dev libxcb-randr0-dev libxcb-util-dev # 可能出现图形化服务器选择lightdm/gdm apt-get install libtool qtmultimedia5-dev \ libdbusmenu-qt5-dev libfcitx-qt5-dev libfcitx5-qt-dev \ libgsettings-qt-dev libkf5bluezqt-dev libkf5networkmanagerqt-dev \ liblightdm-qt5-3-dev libpolkit-qt5-1-dev libpoppler-qt5-dev \ libqt5charts5-dev libqt5opengl5-dev libqt5sensors5-dev \ libqt5svg5-dev libqt5texttospeech5-dev libqt5virtualkeyboard5-dev \ libqt5waylandclient5-dev libqt5webchannel5-dev libqt5webkit5-dev \ libqt5x11extras5-dev libqt5xdg-dev libqt5xdgiconloader-dev \ libqtav-dev libqtav-private-dev qt5-default qtbase5-dev \ qtbase5-dev-tools qtbase5-private-dev qtchooser \ qtconnectivity5-dev qtdeclarative5-dev qtdeclarative5-dev-tools \ qtdeclarative5-private-dev qtlocation5-dev qtmultimedia5-dev \ qtpositioning5-dev qtquickcontrols2-5-dev qtscript5-dev \ qttools5-dev qttools5-dev-tools qtwayland5-dev-tools \ qtwebengine5-dev qtwebengine5-private-dev libkdecorations2-dev \ libkf5xmlgui-dev libkf5crash-dev kscreenlocker-dev kinit-dev pkg-kde-tools
umount dev/pts dev proc sysfs && cd ..
tar cvzf ubuntu-2004-develop.tar.gz squashfs-root/
至此获得ubuntu-2004-develop.tar.gz是可用于x86的ubuntu2004的chroot
docker import ubuntu-2004-develop.tar.gz x86-ubuntu2004-dev:v1
这样docker内也能正常使用此环境