Skip to content

cmd - 异常关机

::: warning 问题描述 在异常断电或者强制重启,在上电后,linux电脑会启动失败,只启动一个最小的文件系统,报press enter for maintenance日志 :::

使用fsckfilesystem check命令进行修复文件系统.

$ tldr fsck
fsck
Check the integrity of a filesystem or repair it. The filesystem should be unmounted at the time the command is run.More information: https://manned.org/fsck.

 - Check filesystem /dev/sdXN, reporting any damaged blocks:
   sudo fsck {{/dev/sdXN}}

 - Check filesystem /dev/sdXN, reporting any damaged blocks and interactively letting the user choose to repair each one:
   sudo fsck -r {{/dev/sdXN}}

 - Check filesystem /dev/sdXN, reporting any damaged blocks and automatically repairing them:
   sudo fsck -a {{/dev/sdXN}}

::: warning 警告 执行fsck {/dev/sdXN}修复命令之前,需要将该损坏的文件系统umount一下。 :::

上面的fsck /dev/sdXN修复命令对一个分区属于完整文件系统的情况是可以的,但是对于LVM的情况会复杂一点。

对于LVM修复参数对象不再是/dev/sdXN, 而是LVM虚拟出来的LV(逻辑卷), 所以你要执行的命令是fsck /dev/mapper/vgyancy-home

$ sudo lvs -o+devices
  LV     VG       Attr       LSize     Devices         
  home   vgyancy  -wi-ao---- 1000.00g  /dev/sdb1(0)    
  home   vgyancy  -wi-ao---- 1000.00g  /dev/sdc1(0)    
  root   vgubuntu -wi-ao----  317.78g  /dev/sda2(0)    
  root   vgubuntu -wi-ao----  317.78g  /dev/sdc2(0)    
  swap_1 vgubuntu -wi-ao----  980.00m  /dev/sda2(30152)
$ df -h                
Filesystem                 Size  Used Avail Use% Mounted on
tmpfs                      1.6G  2.4M  1.6G   1% /run
/dev/mapper/vgubuntu-root  313G   45G  254G  16% /
/dev/sda1                  511M  5.3M  506M   2% /boot/efi
tmpfs                      7.8G     0  7.8G   0% /run/qemu
/dev/mapper/vgyancy-home   984G  315G  620G  34% /home
$ ls /dev/mapper 
control  vgyancy-home  vgubuntu-root  vgubuntu-swap_1