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

在之前的博客我们看了boot分区删除文件后的修复方法,如下:

Linux boot 分区损坏重建 示例

https://www.cndba.cn/dave/article/3534

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

我们这里看一下直接把boot分区删除后的修复过程。 具体步骤如下。https://www.cndba.cn/dave/article/3535

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

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

49e9f0eb3affca31f0bfcdb37d9e2e43.png

2 使用Rescue模式修复

[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~]#

重启系统使分区生效:

[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~]#

[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~]#

[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文件:https://www.cndba.cn/dave/article/3535

[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%]

[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:

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

我这里没有保留/boot/grub/grub.conf 文件, 所有创建一个文件并添加内容,也可以通过ISO镜像来直接创建。https://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]#

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值