在docker的centos里启用systemd

[MD]

1. 拉取镜像[1]

docker pull centos

2. 创建一个DockerFile文件

vi mydockerfile
# 以下是mydockerfile文件的内容
FROM centos:7
MAINTAINER "Yourname" <[email protected]>
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
# mydockerfile内容结束

3. 将centos镜像打包为新的centos7-systemd镜像

docker build -t centos7-systemd - < mydockerfile

4. 创建并运行docker容器centos7[2]

docker run --name centos7 --net=host --privileged=true -d -e container=docker  -v /sys/fs/cgroup:/sys/fs/cgroup  centos7-systemd

  1. 参考资料:https://serverfault.com/questions/824975/failed-to-get-d-bus-connection-operation-not-permitted ↩︎

  2. 原文为docker run --rm --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup centos7-systemd /usr/sbin/init ↩︎

Linux梭哈

  • acme.sh
  • btpanel-x64
  • docker-x64
  • docker-x64-firefox
  • docker-x64-jellyfin
  • docker-x64-portainer
  • docker-x64-qbittorrent
  • nfs-x64
  • vscode-server-x64
  • xray-x64
  • zerotier-x64
  • btpanel-x64
  • aarch64运行Windows
  • docker-aarch64
  • docker-aarch64-firefox
  • docker-aarch64-portainer
  • docker-aarch64-windows
  • nginx-aarch64
  • novnc-aarch64
  • Oracle Cloud 还原引导盘
  • oracle-vm-virtualbox-aarch64
  • qemu-aarch64
  • vncserver-aarch64
  • wine-aarch64
  • docker-aarch64-pandora-next

Linux磁盘扩容

[MD]

1. 在OCI后台把引导卷从40GB调整为100GB

2.在SSH操作

2.1 lsblk

# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk 
├─sda2   8:2    0    8G  0 part [SWAP]
├─sda3   8:3    0 31.5G  0 part /
└─sda1   8:1    0  512M  0 part /boot/efi

可以看到/对应的分区是sda3

2.2 dd 重新扫描磁盘

# dd iflag=direct if=/dev/sda of=/dev/null count=1
# echo "1" | tee /sys/class/block/sda/device/rescan

2.3 查询系统类型

# lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda                                                      
├─sda2 swap         c20ab25a-797e-4c88-b9b4-bbc5e279a88c [SWAP]
├─sda3 xfs          e8399f69-1f3e-4713-afca-f2b9c8f7bbc6 /
└─sda1 vfat         9BE4-DC71                            /boot/efi

2.4 安装扩容软件

# yum install cloud-utils-growpart
# yum install xfsprogs

sda3的系统类型为xfs,扩容需要安装xfsprogs

2.5 growpart对应的分区

# growpart /dev/sda 3
CHANGED:partition=1 start=...

2.6 扩展分区

# xfs_growfs  /dev/sda3

2.7 验证

# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda2   8:2    0    8G  0 part [SWAP]
├─sda3   8:3    0 91.5G  0 part /
└─sda1   8:1    0  512M  0 part /boot/efi

其他问题:

  1. 报错:Couldn’t find valid filesystem superblock.,resize2fs替换为xfs_growfs
  2. 报错:Warning: the kernel is still using the old partition table.The new table will be used at the next reboot.,运行partprobe重新读取分区表
  3. Oracle Linux的操作lvm:
    dd iflag=direct if=/dev/oracleoci/oraclevda of=/dev/null count=1
    echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevda | cut -d'/' -f 2`/device/rescan
    pvresize /dev/sda3
    lvextend -r -l +100%FREE /dev/ocivolume/root

参考链接:
1.https://blog.csdn.net/shitian0811/article/details/104005374
2.https://docs.oracle.com/en-us/Content/Block/Tasks/rescanningdisk.htm
3.https://guo.work/14.html

centos7中输入ifconfig出现ens33,没有eth0

本文最后更新于(2018-3-6 17:22:30),链接可能失效,内容可能难以复现。请注意甄别。
《centos7中输入ifconfig出现ens33,没有eth0》
© Sunplace,2018 以下是虚拟机安装centos7的操作: 1.设置虚拟机为桥接。 2.把/etc/sysconfig/network-scripts/ifcfg-ens33重命名为ifcfg-eth0。(图形界面点击“其他位置”) 3.设置eth0设置为这样。 4.用SecureCRT连接到192.168.3.203