签到成功

知道了

CNDBA社区CNDBA社区

Linux boot分区格式化后恢复 示例

2019-08-14 11:38 2363 0 原创 Linux
作者: dave

在之前的博客我们看了boot分区删除文件后的修复方法,如下:
Linux boot 分区损坏重建 示例
https://www.cndba.cn/dave/article/3534

我们这里看一下直接把boot分区删除后的修复过程。 具体步骤如下。

1 删除boot分区

[root@dave ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dave-lv_root
                       26G  3.0G   22G  12% /
tmpfs                 3.8G   72K  3.8G   1% /dev/shm
/dev/sda1             477M   42M  411M  10% /boot
[root@dave ~]# 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): d
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@dave ~]# 
[root@dave ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
[root@dave ~]# reboot

删除分区并重启系统后错误和之前一样:

2 使用Rescue模式修复

用rescure 登录后没有没有boot分区:

[dave@www.cndba.cn~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dave-lv_root
                       26G  3.0G   22G  12% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
[dave@www.cndba.cn~]#

手工创建分区,注意分区的起始位置:

[dave@www.cndba.cn~]# 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-63, default 63): 
Using default value 63

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[dave@www.cndba.cn~]# fdisk -l /dev/sda

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00086488

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          63      506016   83  Linux
/dev/sda2              64        3917    30944256   8e  Linux LVM
[dave@www.cndba.cn~]#

重启系统使分区生效:http://www.cndba.cn/dave/article/3535

[dave@www.cndba.cn~]# mkfs.ext4 /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
126976 inodes, 506016 blocks
25300 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
62 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[dave@www.cndba.cn~]#

将新分区标记为boot分区:

[dave@www.cndba.cn~]# e2label /dev/sda1 /boot
[dave@www.cndba.cn~]# e2label /dev/sda1
/boot
[dave@www.cndba.cn~]# 

[dave@www.cndba.cn~]# 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): a
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[dave@www.cndba.cn~]# fdisk -l /dev/sda
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00086488

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          63      506016   83  Linux
/dev/sda2              64        3917    30944256   8e  Linux LVM
[dave@www.cndba.cn~]#

挂在分区到boot:

[dave@www.cndba.cn~]# mount /dev/sda1 /boot
[dave@www.cndba.cn~]# 

[dave@www.cndba.cn~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dave-lv_root
                       26G  3.0G   22G  12% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             479M  2.3M  452M   1% /boot
[dave@www.cndba.cn~]#

格式化后,新的分区UUID 和/etc/fstab中的会不同,通过blkid查看并修改fstab文件:

[dave@www.cndba.cn~]# blkid
/dev/mapper/vg_dave-lv_root: UUID="7af80925-1650-4b5c-9161-247f05f37923" TYPE="ext4" 
/dev/loop0: TYPE="squashfs" 
/dev/sda1: LABEL="/boot" UUID="011a5170-18ef-4272-be35-bd7f1221c621" TYPE="ext4" 
/dev/sda2: UUID="2K7Cna-zmCT-l1eX-mN6f-3p9Z-5b8j-0onbLN" TYPE="LVM2_member" 
/dev/mapper/vg_dave-lv_swap: UUID="3d592f95-9ad6-41ef-8c53-f30ad47c475e" TYPE="swap" 
[dave@www.cndba.cn~]# 

[dave@www.cndba.cn~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Aug 13 16:23:52 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_dave-lv_root /                       ext4    defaults        1 1
UUID=011a5170-18ef-4272-be35-bd7f1221c621 /boot                   ext4    defaults        1 2
/dev/mapper/vg_dave-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
[dave@www.cndba.cn~]# 

[dave@www.cndba.cn~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[dave@www.cndba.cn~]# rpm -ivh /mnt/Packages/kernel-2.6.32-573.el6.x86_64.rpm --force
warning: /mnt/Packages/kernel-2.6.32-573.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:kernel                 ########################################### [100%]

重建grub:

http://www.cndba.cn/dave/article/3535

[dave@www.cndba.cn~]# grub-install /dev/sda
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(fd0)    /dev/fd0
(hd0)    /dev/sda
(hd1)    /dev/sdb
(hd2)    /dev/sdc
[dave@www.cndba.cn~]#

同步grub:http://www.cndba.cn/dave/article/3535

http://www.cndba.cn/dave/article/3535

[dave@www.cndba.cn~]# sync

我这里没有保留/boot/grub/grub.conf 文件, 所有创建一个文件并添加内容,也可以通过ISO镜像来直接创建。http://www.cndba.cn/dave/article/3535

http://www.cndba.cn/dave/article/3535
http://www.cndba.cn/dave/article/3535

[dave@www.cndba.cngrub]# touch grub.conf
[dave@www.cndba.cngrub]# vim grub.conf 
[dave@www.cndba.cngrub]# cat grub.conf 
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux 6 (2.6.32-573.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/mapper/vg_dave-lv_root rd_LVM_LV=vg_dave/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_dave/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=128M  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-573.el6.x86_64.img
[dave@www.cndba.cngrub]#

重启系统,修复成功。http://www.cndba.cn/dave/article/3535http://www.cndba.cn/dave/article/3535

http://www.cndba.cn/dave/article/3535

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2261
    原创
  • 3
    翻译
  • 578
    转载
  • 191
    评论
  • 访问:7967074次
  • 积分:4346
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ