事情的起源是使用VMWare虚拟平台克隆一个虚拟机的时候,克隆之前将网络配置全部删掉,然后将虚拟机关机,然后克隆出来一台之后,发现两台都无法正常的开机,症状是监视器会显示一个灰色的7背景,然后虽然没有死机但是也无法进入登录窗口。由于克隆之前网络配置都被删掉了,所以也无法SSH远程登录。使用Ctrl+Alt+F2-6会会出现命令行,但是无法执行任何命令,如下:
开机之后显示转圈圈,然后圈圈消失,然后就没有然后了,一直定格在灰色背景上
此时按下Ctrl+Alt+空格,会出现如下启动日志
此时按下Ctrl+Alt+F6可以输入字符,但是不会执行,F2-5按下以后只有一个光标在闪动。F1为灰色的图形界面
F6如下图
F2-5如下图
重启好多次都是这样,于是当场作出判断,应该是开机启动过程中卡住了。
由于当前的服务器已经完全无法实施任何的操作,所以只能关机之后把虚拟磁盘插到别的虚拟机上拯救一下。
这一台用来实施修复的虚拟机先关机,然后把出问题的虚拟机的硬盘挂上去,如果不关机可能会碰到无法认到硬盘的情况。
另外出问题的Redhat7虚拟机文件系统全部是基于LVM的,用于修复的服务器的操作系统为Redhat 6.7,用的也是LVM,但是这两个LVM中的VG的名字不同,挂载过程还算比较顺利,要是VG名字也相同的话,挂载前要先改名比较麻烦,所以推荐当服务器要挂载外来的LVM硬盘时,要选一台VG名字不同的服务器去挂载,或者选择一个没有开启LVM的服务器去挂载。
下面简单介绍一下挂载方法:
首先选择要用来修复硬盘的Redhat6的虚拟机,这台虚拟机原先已经有两块硬盘了,都是LVM中的磁盘。然后通过添加按钮将出问题的虚拟机磁盘挂载上,出问题的虚拟机要先关机才行,如下图
由于是共享磁盘,所以在“模式”上要勾选“独立”和“持久”
挂上以后就可以开启用于修复的虚拟机了,一般情况下虚拟机会认到这块硬盘但是不会自动挂载
从上图可以看到,Redhat6这台机器原先自己的VG名字为rootvg,坏掉的Redhat7的磁盘VG名字为rhel,已经可以成功的认到这块硬盘/dev/sdc,不过由于是LVM文件系统,图形界面不能很方便的挂载,需要使用shell一步一步的完成
上图可以看到系统已经认出了这块硬盘,如果没关机就挂载,系统可能就认不到,可以参考下文实现对scsi硬盘的热部署
http://zshou.is-programmer.com/posts/39489.html
由于两个VG名字不一样所以不会有什么冲突,比如执行vgdisplay可以看到系统已经成功的认出了两个vg
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 16
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 160.50 GiB
PE Size 4.00 MiB
Total PE 41089
Alloc PE / Size 41088 / 160.50 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID d5sIwc-c8VR-DFEF-ySXP-uex7-zMNx-3jKQgR
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 259.80 GiB
PE Size 4.00 MiB
Total PE 66508
Alloc PE / Size 40908 / 159.80 GiB
Free PE / Size 25600 / 100.00 GiB
VG UUID B8tCHj-NwC4-f6fr-uWIs-05bE-gZeL-J0hK5C
[root@localhost ~]#
如果vgdisplay没有显示受损硬盘,或者由于vg重名导致vgdisplay看不到,可以使用下面文章使用的方法,通过UUID修改VG的名字然后进行挂载
http://blog.csdn.net/qihuanfengyun/article/details/7958031
虽然vgdisplay会显示,但是系统默认是未激活这个新的LVM硬盘的,需要我们手动激活,方法就是使用lvscan查看未激活的设备,然后激活
[root@localhost ~]# lvscan
inactive '/dev/rhel/swap' [16.00 GiB] inherit
inactive '/dev/rhel/tmp' [10.00 GiB] inherit
inactive '/dev/rhel/home' [10.00 GiB] inherit
inactive '/dev/rhel/root' [50.00 GiB] inherit
inactive '/dev/rhel/rpms' [74.50 GiB] inherit
ACTIVE '/dev/rootvg/LogVol01' [151.80 GiB] inherit
ACTIVE '/dev/rootvg/LogVol00' [8.00 GiB] inherit
[root@localhost ~]#
然后执行
vgchange -ay /dev/rhel
进行激活,激活完毕之后,可以再用lvscan查看一下激活状态
[root@localhost ~]# lvscan
ACTIVE '/dev/rhel/swap' [16.00 GiB] inherit
ACTIVE '/dev/rhel/tmp' [10.00 GiB] inherit
ACTIVE '/dev/rhel/home' [10.00 GiB] inherit
ACTIVE '/dev/rhel/root' [50.00 GiB] inherit
ACTIVE '/dev/rhel/rpms' [74.50 GiB] inherit
ACTIVE '/dev/rootvg/LogVol01' [151.80 GiB] inherit
ACTIVE '/dev/rootvg/LogVol00' [8.00 GiB] inherit
[root@localhost ~]#
激活完毕之后就可以使用mount命令挂载了,下面的步骤就和操作普通硬盘差不多了。我把受损系统的 / 挂载到/mnt/repair下面,/mnt/repair目录要事先使用mkdir生成
[root@localhost ~]# mount /dev/rhel/root /mnt/repair/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-LogVol01
150G 53G 89G 38% /
tmpfs 3.9G 80K 3.9G 1% /dev/shm
/dev/sda1 190M 41M 140M 23% /boot
/dev/sr0 3.6G 3.6G 0 100% /media/RHEL-6.7 Server.x86_64
/dev/mapper/rhel-root
50G 45G 2.5G 95% /mnt/repair
[root@localhost ~]#
[root@localhost repair]# ll /mnt/repair/
总用量 2156780
lrwxrwxrwx. 1 root root 7 9月 11 22:50 bin -> usr/bin
drwxr-xr-x. 2 root root 4096 9月 11 22:48 boot
drwxr-xr-x. 2 root root 4096 9月 11 22:48 dev
drwxr-xr-x. 156 root root 12288 12月 14 07:55 etc
drwxr-xr-x. 2 root root 4096 9月 11 22:48 home
lrwxrwxrwx. 1 root root 7 9月 11 22:50 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 9月 11 22:50 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 4096 12月 13 17:24 logs
drwx------. 2 root root 16384 9月 11 22:48 lost+found
drwxr-xr-x. 2 root root 4096 5月 25 2015 media
drwxr-xr-x. 4 root root 4096 9月 13 21:14 mnt
drwxr-xr-x. 3 root root 4096 10月 12 11:18 opt
drwxr-xr-x. 2 root root 4096 9月 11 22:48 proc
dr-xr-x---. 28 root root 4096 12月 13 18:30 root
drwxr-xr-x. 2 root root 4096 10月 12 11:14 rpms
drwxr-xr-x. 2 root root 4096 9月 11 22:48 run
lrwxrwxrwx. 1 root root 8 9月 11 22:50 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 5月 25 2015 srv
drwxr-xr-x. 2 root root 4096 9月 11 22:48 sys
drwxr-xr-x. 2 root root 4096 9月 11 22:48 tmp
drwxr-xr-x. 16 root root 4096 12月 9 09:19 usr
drwxr-xr-x. 23 root root 4096 12月 14 07:55 var
-rw-r--r--. 1 root root 0 10月 12 16:14 weixin.log
[root@localhost repair]#
[root@localhost repair]# cat /mnt/repair/etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
mount -o loop /rpms/rhel-server-7.4-x86_64-dvd.iso /rpms/rhel7
mount -o loop /rpms/rhel-server-6.9-x86_64-dvd.iso /rpms/rhel6
mount -o loop /rpms/CentOS-7-x86_64-Everything-1708.iso /rpms/centos7.4/
/rpms/caddy -port 88
[root@localhost repair]#
[root@localhost repair]# cat /mnt/repair/etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
#mount -o loop /rpms/rhel-server-7.4-x86_64-dvd.iso /rpms/rhel7
#mount -o loop /rpms/rhel-server-6.9-x86_64-dvd.iso /rpms/rhel6
#mount -o loop /rpms/CentOS-7-x86_64-Everything-1708.iso /rpms/centos7.4/
#/rpms/caddy -port 88
[root@localhost repair]#
修改前,默认是DHCP,但是网络里是没有DHCP服务器的,所以去掉
[root@localhost repair]# cat /mnt/repair/etc/sysconfig/network-scripts/ifcfg-eno16780032
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16780032
UUID=fea13a88-a6b6-4496-a4e4-83c83f33818f
DEVICE=eno16780032
ONBOOT=no
[root@localhost repair]#
[root@localhost repair]# cat /mnt/repair/etc/sysconfig/network-scripts/ifcfg-eno16780032
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.59
PREFIX=24
GATEWAY=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16780032
UUID=fea13a88-a6b6-4496-a4e4-83c83f33818f
DEVICE=eno16780032
ONBOOT=yes
[root@localhost repair]#
这次启动红帽7的时候,熟悉的登录界面很快就出来了,修复结束