Linux 救援 VM 中的 Chroot 环境Chroot environment in a Linux Rescue VM

本文介绍如何排查 Linux 中救援虚拟机 (VM) 上的 chroot 环境问题。This article describes how to troubleshoot the chroot environment in the Rescue virtual machine (VM) in Linux.

Ubuntu 16.x 和 Ubuntu 18.xUbuntu 16.x && Ubuntu 18.x

  1. 停止或解除分配受影响的 VM。Stop or de-allocate the affected VM.

  2. 使用托管磁盘在同一资源组 (RSG) 和位置中创建 OS 版本相同的救援 VM 映像。Create a rescue VM image of the same OS version, in same resource group (RSG) and location using managed disk.

  3. 使用 Azure 门户创建受影响虚拟机的 OS 磁盘的快照。Use the Azure portal to take a snapshot of the affected virtual machine's OS disk.

  4. 基于该 OS 磁盘快照创建一个磁盘,并将该磁盘附加到救援 VM。Create a disk out of the snapshot of the OS disk, and attach it to the Rescue VM.

  5. 创建磁盘后,排查救援 VM 中的 chroot 环境问题。Once the disk has been created, Troubleshoot the chroot environment in the Rescue VM.

    1. 使用以下命令以 root 用户身份访问 VM:Access your VM as the root user using the following command:

      #sudo su -

    2. 使用 dmesg 查找磁盘(用于发现新磁盘的方法可能各不相同)。Find the disk using dmesg (the method you use to discover your new disk may vary). 以下示例使用 dmesg 根据 SCSI 磁盘进行筛选:The following example uses dmesg to filter on SCSI disks:

      dmesg | grep SCSI

      输出类似于以下示例。Your output will be similar to the following example. 在此示例中,我们想要查找 sdc 磁盘:In this example, we want the sdc disk:

      [    0.294784] SCSI subsystem initialized
      [    0.573458] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
      [    7.110271] sd 2:0:0:0: [sda] Attached SCSI disk
      [    8.079653] sd 3:0:1:0: [sdb] Attached SCSI disk
      [ 1828.162306] sd 5:0:0:0: [sdc] Attached SCSI disk
      
    3. 使用以下命令访问 chroot 环境:Use the following commands to access the chroot environment:

      #mkdir /rescue
      #mount /dev/sdc1 /rescue
      #mount /dev/sdc15 /rescue/boot/efi
      #cd /rescue
      
      #mount -t proc proc proc
      #mount -t sysfs sys sys/
      #mount -o bind /dev dev/
      #mount -o bind /dev/pts dev/pts/
      #mount -o bind /run run/
      #chroot /rescue
      
    4. 排查 chroot 环境问题。Troubleshoot the chroot environment.

    5. 使用以下命令退出 chroot 环境:Use the following commands to exit the chroot environment:

      #exit
      
      #umount /rescue/proc/
      #umount /rescue/sys/
      #umount /rescue/dev/pts
      #umount /rescue/dev/
      #umount /rescue/run
      #cd /
      #umount /rescue/boot/efi
      #umount /rescue
      

      备注

      如果收到错误 unable to unmount /rescue,请将 -l 选项添加到 umount 命令。If you receive the error unable to unmount /rescue, add -l option to the umount command.

      示例: umount -l /rescueExample: umount -l /rescue

  6. 从救援 VM 中分离磁盘,并执行与原始 VM 之间的磁盘交换。Detach the disk from the rescue VM and perform a disk swap with the original VM.

  7. 启动原始 VM 并检查其连接状态。Start the original VM and check its connectivity.

包含 RAW 分区的 Centos 6.x 和 RHEL/Centos 7.xCentos 6.x && RHEL/Centos 7.x with RAW Partitions

  1. 停止或解除分配受影响的 VM。Stop or de-allocate the affected VM.

  2. 使用托管磁盘在同一资源组 (RSG) 和位置中创建 OS 版本相同的救援 VM 映像。Create a Rescue VM image of the same OS version, in same resource group (RSG) and location using managed disk.

  3. 使用 Azure 门户创建受影响虚拟机的 OS 磁盘的快照。Use the Azure portal to take a snapshot of the affected virtual machine's OS disk.

  4. 基于该 OS 磁盘快照创建一个磁盘,并将该磁盘附加到救援 VM。Create a disk out of the snapshot of the OS disk, and attach it to the Rescue VM.

  5. 创建磁盘后,排查救援 VM 中的 chroot 环境问题。Once the disk has been created, Troubleshoot the chroot environment in the Rescue VM.

    1. 使用以下命令以 root 用户身份访问 VM:Access your VM as the root user using the following command:

      #sudo su -

    2. 使用 dmesg 查找磁盘(用于发现新磁盘的方法可能各不相同)。Find the disk using dmesg (the method you use to discover your new disk may vary). 以下示例使用 dmesg 根据 SCSI 磁盘进行筛选:The following example uses dmesg to filter on SCSI disks:

      dmesg | grep SCSI

      输出类似于以下示例。Your output will be similar to the following example. 在此示例中,我们想要查找 sdc 磁盘:In this example, we want the sdc disk:

      [    0.294784] SCSI subsystem initialized
      [    0.573458] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
      [    7.110271] sd 2:0:0:0: [sda] Attached SCSI disk
      [    8.079653] sd 3:0:1:0: [sdb] Attached SCSI disk
      [ 1828.162306] sd 5:0:0:0: [sdc] Attached SCSI disk
      
    3. 使用以下命令访问 chroot 环境:Use the following commands to access the chroot environment:

      #mkdir /rescue
      #mount -o nouuid /dev/sdc2 /rescue
      #mount -o nouuid /dev/sdc1 /rescue/boot/
      #cd /rescue
      
      #mount -t proc proc proc
      #mount -t sysfs sys sys/
      #mount -o bind /dev dev/
      #mount -o bind /dev/pts dev/pts/
      #mount -o bind /run run/
      #chroot /rescue
      
    4. 排查 chroot 环境问题。Troubleshoot the chroot environment.

    5. 使用以下命令退出 chroot 环境:Use the following commands to exit the chroot environment:

      #exit
      
      #umount /rescue/proc/
      #umount /rescue/sys/
      #umount /rescue/dev/pts
      #umount /rescue/dev/
      #umount /rescue/run
      #cd /
      #umount /rescue/boot/
      #umount /rescue
      

      备注

      如果收到错误 unable to unmount /rescue,请将 -l 选项添加到 umount 命令。If you receive the error unable to unmount /rescue, add -l option to the umount command.

      示例: umount -l /rescueExample: umount -l /rescue

  6. 从救援 VM 中分离磁盘,并执行与原始 VM 之间的磁盘交换。Detach the disk from the rescue VM and perform a disk swap with the original VM.

  7. 启动原始 VM 并检查其连接状态。Start the original VM and check its connectivity.

包含 LVM 的 RHEL/Centos 7.xRHEL/Centos 7.x with LVM

备注

如果原始 VM 的 OS 磁盘包含逻辑卷管理器 (LVM),请在 OS 磁盘上使用包含 Raw 分区的映像创建救援 VM。If your original VM includes Logical Volume Manager (LVM) on the OS Disk, create the Rescue VM using the image with Raw Partitions on the OS Disk.

  1. 停止或解除分配受影响的 VM。Stop or de-allocate the affected VM.

  2. 使用托管磁盘在同一资源组 (RSG) 和位置中创建 OS 版本相同的救援 VM 映像。Create a Rescue VM image of the same OS version, in same resource group (RSG) and location using managed disk.

  3. 使用 Azure 门户创建受影响虚拟机的 OS 磁盘的快照。Use the Azure portal to take a snapshot of the affected virtual machine's OS disk.

  4. 基于该 OS 磁盘快照创建一个磁盘,并将该磁盘附加到救援 VM。Create a disk out of the snapshot of the OS disk, and attach it to the Rescue VM.

  5. 创建磁盘后,排查救援 VM 中的 chroot 环境问题。Once the disk has been created, Troubleshoot the chroot environment in the Rescue VM.

    1. 使用以下命令以 root 用户身份访问 VM:Access your VM as the root user using the following command:

      #sudo su -

    2. 使用 dmesg 查找磁盘(用于发现新磁盘的方法可能各不相同)。Find the disk using dmesg (the method you use to discover your new disk may vary). 以下示例使用 dmesg 根据 SCSI 磁盘进行筛选:The following example uses dmesg to filter on SCSI disks:

      dmesg | grep SCSI

      输出类似于以下示例。Your output will be similar to the following example. 在此示例中,我们想要查找 sdc 磁盘:In this example, we want the sdc disk:

      [    0.294784] SCSI subsystem initialized
      [    0.573458] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
      [    7.110271] sd 2:0:0:0: [sda] Attached SCSI disk
      [    8.079653] sd 3:0:1:0: [sdb] Attached SCSI disk
      [ 1828.162306] sd 5:0:0:0: [sdc] Attached SCSI disk
      
    3. 使用以下命令激活逻辑卷组:Use the following command to activate the logical volume group:

      #vgscan --mknodes
      #vgchange -ay
      #lvscan
      
    4. 使用 lsblk 命令检索 LVM 名称:Use the lsblk command to retrieve the lvm names:

      [user@myvm ~]$ lsblk
      NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
      sda                 8:0    0   64G  0 disk
      ├─sda1              8:1    0  500M  0 part /boot
      ├─sda2              8:2    0   63G  0 part /
      sdb                 8:16   0    4G  0 disk
      └─sdb1              8:17   0    4G  0 part /mnt/resource
      sdc                 8:0    0   64G  0 disk
      ├─sdc1              8:1    0  500M  0 part
      ├─sdc2              8:2    0   63G  0 part
      ├─sdc3              8:3    0    2M  0 part
      ├─sdc4              8:4    0   63G  0 part
        ├─rootvg-tmplv  253:0    0    2G  0 lvm  
        ├─rootvg-usrlv  253:1    0   10G  0 lvm  
        ├─rootvg-optlv  253:2    0    2G  0 lvm  
        ├─rootvg-homelv 253:3    0    1G  0 lvm  
        ├─rootvg-varlv  253:4    0    8G  0 lvm  
        └─rootvg-rootlv 253:5    0    2G  0 lvm
      
    5. 使用以下命令访问 chroot 环境:Use the following commands to access the chroot environment:

      #mkdir /rescue
      #mount /dev/mapper/rootvg-rootlv /rescue
      #mount /dev/mapper/rootvg-varlv /rescue/var
      #mount /dev/mapper/rootvg-homelv /rescue/home
      #mount /dev/mapper/rootvg-usrlv /rescue/usr
      #mount /dev/mapper/rootvg-tmplv /rescue/tmp
      #mount /dev/mapper/rootvg-optlv /rescue/opt
      #mount /dev/sdc2 /rescue/boot/
      #mount /dev/sdc1 /rescue/boot/efi
      #cd /rescue
      
      #mount -t proc proc proc
      #mount -t sysfs sys sys/
      #mount -o bind /dev dev/
      #mount -o bind /dev/pts dev/pts/
      #mount -o bind /run run/
      #chroot /rescue
      
    6. 排查 chroot 环境问题。Troubleshoot the chroot environment.

    7. 使用以下命令退出 chroot 环境:Use the following commands to exit the chroot environment:

      #exit
      
      #umount /rescue/proc/
      #umount /rescue/sys/
      #umount /rescue/dev/pts
      #umount /rescue/dev/
      #umount /rescue/run
      #cd /
      #umount /rescue/boot/efi
      #umount /rescue/boot
      #umount /rescue/home
      #umount /rescue/var
      #umount /rescue/usr
      #umount /rescue/tmp
      #umount /rescue/opt
      #umount /rescue
      

      备注

      如果收到错误 unable to unmount /rescue,请将 -l 选项添加到 umount 命令。If you receive the error unable to unmount /rescue, add -l option to the umount command.

      示例: umount -l /rescueExample: umount -l /rescue

  6. 从救援 VM 中分离磁盘,并执行与原始 VM 之间的磁盘交换。Detach the disk from the rescue VM and perform a disk swap with the original VM.

  7. 启动原始 VM 并检查其连接状态。Start the original VM and check its connectivity.

SUSE-SLES 12 SP4、SUSE-SLES 12 SP4 For SAP 以及 ## SUSE-SLES 15 SP1、SUSE-SLES 15 SP1 For SAPSUSE-SLES 12 SP4, SUSE-SLES 12 SP4 For SAP && ## SUSE-SLES 15 SP1, SUSE-SLES 15 SP1 For SAP

  1. 停止或解除分配受影响的 VM。Stop or de-allocate the affected VM.

  2. 使用托管磁盘在同一资源组 (RSG) 和位置中创建 OS 版本相同的救援 VM 映像。Create a Rescue VM image of the same OS version, in same resource group (RSG) and location using managed disk.

  3. 使用 Azure 门户创建受影响虚拟机的 OS 磁盘的快照。Use the Azure portal to take a snapshot of the affected virtual machine's OS disk.

  4. 基于该 OS 磁盘快照创建一个磁盘,并将该磁盘附加到救援 VM。Create a disk out of the snapshot of the OS disk, and attach it to the Rescue VM.

  5. 创建磁盘后,排查救援 VM 中的 chroot 环境问题。Once the disk has been created, Troubleshoot the chroot environment in the Rescue VM.

    1. 使用以下命令以 root 用户身份访问 VM:Access your VM as the root user using the following command:

      #sudo su -

    2. 使用 dmesg 查找磁盘(用于发现新磁盘的方法可能各不相同)。Find the disk using dmesg (the method you use to discover your new disk may vary). 以下示例使用 dmesg 根据 SCSI 磁盘进行筛选:The following example uses dmesg to filter on SCSI disks:

      dmesg | grep SCSI

      输出类似于以下示例。Your output will be similar to the following example. 在此示例中,我们想要查找 sdc 磁盘:In this example, we want the sdc disk:

      [    0.294784] SCSI subsystem initialized
      [    0.573458] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
      [    7.110271] sd 2:0:0:0: [sda] Attached SCSI disk
      [    8.079653] sd 3:0:1:0: [sdb] Attached SCSI disk
      [ 1828.162306] sd 5:0:0:0: [sdc] Attached SCSI disk
      
    3. 使用以下命令访问 chroot 环境:Use the following commands to access the chroot environment:

      #mkdir /rescue
      #mount -o nouuid /dev/sdc4 /rescue
      #mount -o nouuid /dev/sdc3 /rescue/boot/
      #mount /dev/sdc2 /rescue/boot/efi
      #cd /rescue
      
      #mount -t proc proc proc
      #mount -t sysfs sys sys/
      #mount -o bind /dev dev/
      #mount -o bind /dev/pts dev/pts/
      #mount -o bind /run run/
      #chroot /rescue
      
    4. 排查 chroot 环境问题。Troubleshoot the chroot environment.

    5. 使用以下命令退出 chroot 环境:Use the following commands to exit the chroot environment:

      #exit
      
      #umount /rescue/proc/
      #umount /rescue/sys/
      #umount /rescue/dev/pts
      #umount /rescue/dev/
      #umount /rescue/run
      #cd /
      #umount /rescue/boot/efi
      #umount /rescue/boot
      #umount /rescue
      

      备注

      如果收到错误 unable to unmount /rescue,请将 -l 选项添加到 umount 命令。If you receive the error unable to unmount /rescue, add -l option to the umount command.

      示例: umount -l /rescueExample: umount -l /rescue

  6. 从救援 VM 中分离磁盘,并执行与原始 VM 之间的磁盘交换。Detach the disk from the rescue VM and perform a disk swap with the original VM.

  7. 启动原始 VM 并检查其连接状态。Start the original VM and check its connectivity.

后续步骤Next Steps