[root@localhost cloudimages]# qemu-img convert -f qcow2 -O raw openEuler-20.03-LTS.aarch64.qcow2 openEuler-20.03-LTS.raw [root@localhost cloudimages]# losetup -f /dev/loop8 [root@localhost cloudimages]# losetup /dev/loop8 openEuler-20.03-LTS.raw [root@localhost cloudimages]# kpartx -av /dev/loop8 add map loop8p1 (253:26): 0 4192256 linear /dev/loop8 2048 add map loop8p2 (253:27): 0 79691776 linear /dev/loop8 4194304
[root@localhost cloudimages]# mount /dev/mapper/loop8p2 /mnt/Neo
[root@localhost cloudimages]# cd /mnt/Neo
[root@localhost Neo]# ls
bin boot dev etc grub.cfg home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@localhost Neo]# mount --bind /dev /mnt/Neo/dev
[root@localhost Neo]# chroot /mnt/Neo /bin/bash
[root@localhost /]# mount -t proc none /proc
[root@localhost /]# mount -t sysfs none /sys
安装cloud init
yum install cloud-init --allowerasing
[root@localhost rules.d]# systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service
[root@localhost rules.d]# cloud-init -v
/usr/bin/cloud-init 17.1
网卡开机自启动
1、cat /usr/lib/systemd/system/dhcp-interface@.service
ubuntu:/lib/systemd/system/
[Unit] Description=DHCP interface %i DefaultDependencies=no After=network.target Before=network-online.target Wants=network-online.target ConditionPathExists=!/etc/sysconfig/network-scripts/ifcfg-%i [Service] Type=oneshot User=root ExecStartPre=/usr/local/sbin/dhcp-all-interfaces.sh %i ExecStart=/sbin/ifup %i RemainAfterExit=true TimeoutStartSec=30s [Install] WantedBy=multi-user.target
2、 cat /usr/local/sbin/dhcp-all-interfaces.sh
#!/bin/bash if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then set -x fi set -eu set -o pipefail INTERFACE=${1:-} #optional, if not specified configure all available interfaces ENI_FILE="/etc/network/interfaces" PATH=/sbin:$PATH if [ -d "/etc/network" ]; then CONF_TYPE="eni" elif [ -d "/etc/sysconfig/network-scripts/" ]; then CONF_TYPE="rhel-netscripts" SCRIPTS_PATH="/etc/sysconfig/network-scripts/" elif [ -d "/etc/sysconfig/network/" ]; then # SUSE network scripts location CONF_TYPE="suse-netscripts" SCRIPTS_PATH="/etc/sysconfig/network/" else echo "Unsupported network configuration type!" exit 1 fi ARGS="$0 $@" function serialize_me() { if [ "$CONF_TYPE" == "eni" ]; then # Serialize runs so that we don't miss hot-add interfaces FLOCKED=${FLOCKED:-} if [ -z "$FLOCKED" ] ; then FLOCKED=true exec flock -x $ENI_FILE $ARGS fi fi } function get_if_link() { cat /sys/class/net/${1}/carrier || echo 0 } function get_if_type() { cat /sys/class/net/${1}/type } function enable_interface() { local interface=$1 serialize_me if [ "$CONF_TYPE" == "eni" ]; then printf "auto $interface iface $interface inet dhcp " >>$ENI_FILE elif [ "$CONF_TYPE" == "rhel-netscripts" ]; then if [ "$(get_if_type $interface)" == "32" ]; then printf "DEVICE="$interface" BOOTPROTO="dhcp" ONBOOT="yes" TYPE="InfiniBand" CONNECTED_MODE="no" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="yes" IPV6INIT="no"" >"${SCRIPTS_PATH}ifcfg-$interface" else printf "DEVICE="$interface" BOOTPROTO="dhcp" ONBOOT="yes" TYPE="Ethernet"" >"${SCRIPTS_PATH}ifcfg-$interface" fi elif [ "$CONF_TYPE" == "suse-netscripts" ]; then printf "BOOTPROTO="dhcp" STARTMODE="auto"" >"${SCRIPTS_PATH}ifcfg-$interface" fi echo "Configured $1" } function config_exists() { local interface=$1 if [[ "$CONF_TYPE" =~ "netscripts" ]]; then if [ -f "${SCRIPTS_PATH}ifcfg-$interface" ]; then return 0 fi else if ifquery $interface >/dev/null 2>&1; then if [ -z "$(ifquery $interface 2>&1)" ]; then return 1 else return 0 fi else return 1 fi fi return 1 } function inspect_interface() { local interface=$1 local mac_addr_type mac_addr_type=$(cat /sys/class/net/${interface}/addr_assign_type) echo -n "Inspecting interface: $interface..." if config_exists $interface; then echo "Has config, skipping." elif [ "$mac_addr_type" != "0" ]; then echo "Device has generated MAC, skipping." else local has_link local tries=30 for ((; tries > 0; tries--)); do # Need to set the link up on each iteration ip link set dev $interface up &>/dev/null has_link=$(get_if_link $interface) [ "$has_link" == "1" ] && break sleep 1 done if [ "$has_link" == "1" ]; then enable_interface "$interface" else echo "No link detected, skipping" fi fi } if [ -n "$INTERFACE" ]; then inspect_interface $INTERFACE else for iface in $(ls /sys/class/net | grep -v ^lo$); do inspect_interface $iface done fi
chmod +x dhcp-all-interfaces.sh
3、添加/etc/udev/rules.d/99-dhcp-all-interfaces.rules
[root@localhost sbin]# cd /etc/udev/rules.d/ [root@localhost rules.d]# ls [root@localhost rules.d]# touch 99-dhcp-all-interfaces.rules [root@localhost rules.d]# ls 99-dhcp-all-interfaces.rules cat /etc/udev/rules.d/99-dhcp-all-interfaces.rules SUBSYSTEM=="net", KERNEL!="lo", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="dhcp-interface@$name.service"
4、添加devuser账号
useradd -m devuser /bin/bash
echo -e 'devuser ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
echo "devuser:xxxxx" | chpasswd
5、cloud init默认登陆用户
useradd -m euleros -s /bin/bash mkdir -p /home/euleros/.ssh touch /home/euleros/.ssh/authorized_keys chown euleros:euleros -R /home/euleros
查看/home/devuser/下是否存在.bash_profile 、.bashrc
[root@localhost rules.d]# cp /etc/skel/.bashrc /home/devuser/
[root@localhost rules.d]# cp /etc/skel/.bash_profile /home/devuser/
退出
[root@localhost rules.d]# umount /proc/ /sys/ /dev/ [root@localhost rules.d]# exit exit