故障描述:
由于断电导致/boot分区丢失
磁盘情况:
[root@localhost ~]# df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 104G 26G 73G 26% /
tmpfs tmpfs 1.1G 0 1.1G 0% /dev/shm
[root@localhost ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Jan 4 11:44 /dev/sda
brw-rw----. 1 root disk 8, 2 Jan 4 10:52 /dev/sda2
brw-rw----. 1 root disk 8, 3 Jan 4 10:52 /dev/sda3
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1c05
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 12774 102400000 83 Linux
/dev/sda3 12774 13284 4096000 82 Linux swap / Solaris
可以看到现在/dev/sda1已经丢失了,但是通过fdisk能够查看到,现在只能备份下/boot然后把sda1格式化。
结局步骤:(首先找到版本一样的镜像盘进入救援模式)
1、删除sda1,并重新把sda1设为引导分区
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1c05
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 12774 102400000 83 Linux
/dev/sda3 12774 13284 4096000 82 Linux swap / Solaris
Command (m for help): d
Partition number (1-4): 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
1
Invalid partition number for type `1'
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-25, default 25):
Using default value 25
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1c05
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 12774 102400000 83 Linux
/dev/sda3 12774 13284 4096000 82 Linux swap / Solaris
2、删除/boot
[root@localhost ~]# rm -rf /boot/*
3、格式化/dev/sda1
[root@localhost ~]# mkfs.ext3 /dev/sda1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
50200 inodes, 200780 blocks
10039 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3、把sda1挂载到/boot
[root@localhost ~]# mount /dev/sda1 /boot
[root@localhost ~]# ls /boot
lost+found
4、挂载光盘,生成镜像文件,安装内核,生成/boot下文件
[root@localhost ~]# mount /dev/cdrom /root
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]#
[root@localhost ~]# rpm -ivh --force /root/Packages/kernel-2.6.32-431.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:kernel ########################################### [100%]
查看/boot下文件
root@localhost ~]# ls /boot
config-2.6.32-431.el6.x86_64 lost+found System.map-2.6.32-431.el6.x86_64
initramfs-2.6.32-431.el6.x86_64.img symvers-2.6.32-431.el6.x86_64.gz vmlinuz-2.6.32-431.el6.x86_64
5、拷贝grub文件
[root@localhost ~]# mkdir /boot/grub
[root@localhost ~]# cp /usr/share/grub/x86_64-redhat/* /boot/grub/
[root@localhost ~]# ls /boot/grub/
e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 stage2_eltorito xfs_stage1_5
fat_stage1_5 jfs_stage1_5 stage1 ufs2_stage1_5
ffs_stage1_5 minix_stage1_5 stage2 vstafs_stage1_5
6、重新安装grub
[root@localhost ~]# grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub>
grub> root (hd0.^H,0)
root (hd0.,0)
Error 1: Unrecognized device string
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"... 27 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
7、获取sda1的uuid,写到/etc/fstab
[root@localhost ~]# blkid
/dev/sda2: UUID="63e9f9a0-fc0c-42c9-89d3-0ac2fad6dcc9" TYPE="ext4"
/dev/sda3: UUID="e7c45d4f-91a9-4ef2-bba3-7f77b321befc" TYPE="swap"
/dev/loop0: TYPE="squashfs"
/dev/sda1: UUID="37a903cb-f862-4291-b575-e0adb88341ee" TYPE="ext3"
vim /etc/fstab
UUID=37a903cb-f862-4291-b575-e0adb88341ee /boot ext3 defaults 1 2
8、编写/etc/grub/grub.conf文件
efault=10
title CentOS 6
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sda2 quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img
注:kernel文件要和/boot下的kernel文件保持一致
initrd文件也要和/boot下的initrd文件保持一致
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sda2 quiet这句话的root=/dev/sda2
表示挂载到/下,这个名字用df -HT查看这个名称
8.reboot修复下,再次重启即可