日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

發(fā)布時間:2023/12/15 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 恢复boot分区,Linux boot分区格式化后恢复 示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在之前的博客我們看了boot分區(qū)刪除文件后的修復方法,如下:

Linux boot 分區(qū)損壞重建 示例

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

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

我們這里看一下直接把boot分區(qū)刪除后的修復過程。 具體步驟如下。https://www.cndba.cn/dave/article/3535

1 刪除boot分區(qū)

[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

刪除分區(qū)并重啟系統(tǒng)后錯誤和之前一樣:

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

手工創(chuàng)建分區(qū),注意分區(qū)的起始位置:

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

重啟系統(tǒng)使分區(qū)生效:

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

格式化后,新的分區(qū)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 文件, 所有創(chuàng)建一個文件并添加內(nèi)容,也可以通過ISO鏡像來直接創(chuàng)建。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]#

版權聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉載。

總結

以上是生活随笔為你收集整理的linux 恢复boot分区,Linux boot分区格式化后恢复 示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。