意外地在已经可用的磁盘上运行 mkfs 命令

意外地在已经可用的磁盘上运行 mkfs 命令

我的 Linode 服务器连接了一个 350Gb 的卷。由于空间不足,我从仪表板将其大小调整为 400GB,然后重新启动了服务器。然后我使用 df -h 命令检查磁盘是否已调整大小,但仍显示已使用 96%。

因此,我首先使用卸载了我的卷umount /var/www/disk,然后运行此命令 sudo mkfs -t ext4 /dev/sdc,在重新安装我的卷并使用ls命令检查文件后,除了丢失+找到的文件之外,里面没有任何内容,当我使用 df -h 时,它显示现在磁盘是400GB 和其中 20GB 的磁盘正在使用,但除了丢失+找到的文件之外看不到任何文件。

我仍然连接到我的终端,直到我从仪表板调整音量大小后重新启动服务器,并且我已经复制了我使用的整个命令及其输出向上滚动。请帮助我取回我的数据,因为它非常重要。我将非常感激你。

root@ubuntu:/var/www/html/processing# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdc        345G  315G   15G  96% /var/www/disk

root@ubuntu:/var/www/html/processing# lsblk
NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  1004M  0 disk [SWAP]
sdc    8:32   0   400G  0 disk /var/www/disk
sda    8:0    0    79G  0 disk /

root@ubuntu:/var/www/html/processing# sudo mkfs -t ext4 /dev/sdc
mke2fs 1.42.9 (4-Feb-2014)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sdc is mounted; will not make a filesystem here!
root@ubuntu:/var/www/html/processing# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdc        345G  315G   15G  96% /var/www/disk

root@ubuntu:/var/www/html/processing# sudo mkfs -t ext4 /dev/sdc
mke2fs 1.42.9 (4-Feb-2014)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sdc is mounted; will not make a filesystem here!

root@ubuntu:/var/www/html/processing# sudo killall php screen

root@ubuntu:/var/www/html/processing# sudo umount /disk
umount: /disk: not found

root@ubuntu:/var/www/html/processing# sudo umount /var/www/disk
umount: /var/www/disk: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

root@ubuntu:/var/www/html/processing# fuser -kim /var/www/disk
/var/www/disk:        1206
Kill process 1206 ? (y/N) y

root@ubuntu:/var/www/html/processing# sudo umount /var/www/disk

root@ubuntu:/var/www/html/processing# sudo mkfs -t ext4 /dev/sdc
mke2fs 1.42.9 (4-Feb-2014)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
26214400 inodes, 104857600 blocks
5242880 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3200 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     


root@ubuntu:/var/www/html/processing# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user

root@ubuntu:/var/www/html/processing# lsblk
NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  1004M  0 disk [SWAP]
sdc    8:32   0   400G  0 disk 
sda    8:0    0    79G  0 disk /

root@ubuntu:/var/www/html/processing# sudo mount /dev/sdc/ /var/www/disk

root@ubuntu:/var/www/html/processing# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdc        394G   71M  374G   1% /var/www/disk

root@ubuntu:/var/www/html/processing# cd /var/www/disk

root@ubuntu:/var/www/disk# ls
lost+found

root@ubuntu:/var/www/disk# sudo umount /var/www/disk
umount: /var/www/disk: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

root@ubuntu:/var/www/disk# fuser -kim /var/www/disk
/var/www/disk:        1573c
Kill process 1573 ? (y/N) y
Connection to 45.79.22.163 closed.

zeeshan@zeeshan-VirtualBox:~$ sudo ssh [email protected]
[email protected]'s password: 
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 5.4.10-x86_64-linode132 x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '16.04.6 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Thu Feb 27 07:40:09 2020 from 119.155.0.120

root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdc        394G   71M  374G   1% /var/www/disk

root@ubuntu:~# fuser -kim /var/www/disk

root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        78G   48G   27G  65% /
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            392M  392K  392M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdc        394G   71M  374G   1% /var/www/disk

root@ubuntu:~# sudo killall php screen
php: no process found
screen: no process found

答案1

抱歉,一切都消失了,除非您(或您的托管服务商)有备份,否则无法将其恢复。

恢复起来mkfs确实很困难,但当出现以下消息时就完全不可能了:

Discarding device blocks: done

这样,所有数据就消失了。并且只有当块实际被丢弃时才会显示此消息。在不支持丢弃的设备上,根本不会显示该消息。

mke2fsmkfs.ext4和其他)总是意味着完全丢弃。如果您不希望发生这种情况,则必须明确提供该nodiscard选项。从联机帮助页:

   -E extended-options
   [...]
               discard
                      Attempt to discard blocks at mkfs time (discarding
                      blocks initially is useful on solid state devices
                      and sparse / thin-provisioned storage). When the
                      device advertises that discard also zeroes data (any
                      subsequent read after the discard and before write
                      returns zero), then mark all not-yet-zeroed inode
                      tables as zeroed. This significantly speeds up
                      filesystem initialization. This is set as default.

               nodiscard
                      Do not attempt to discard blocks at mkfs time.

SSD 支持丢弃,但映像文件(在支持稀疏文件的文件系统上)、循环设备和常见的虚拟硬盘驱动器映像也支持丢弃。这允许虚拟机丢弃未使用的块,并且主机将此类未使用的空间用于其他目的。只要您有足够的废弃存储容量,一些托管服务商就允许您创建服务器状态的快照。但这通常是一个手动过程,现在对您没有帮助。


从技术上讲,数据可能仍然存在于不支持丢弃的主机硬盘的“可用空间”中的某个位置。或者主机 SSD(如果稍后发生主机丢弃)fstrim。因此,如果这种情况发生在自托管 VPS(您控制主机服务器)中,您可以尝试对此进行筛选,但在 VPS/云托管服务上,不可能让他们这样做。他们无法区分您丢弃的数据或其他客户丢弃的数据,因此除了无法完成该任务之外,他们还会出于隐私原因拒绝。同一主机上其他客户的持续写入活动也会导致您的数据实际上被覆盖,因此无论哪种情况,这都是一个有争议的问题。

相关内容