恢复原始/home内容

恢复原始/home内容

我怀疑我的电脑上的不同分区上安装了多个 Ubuntu。但我该如何找到它们呢?该使用哪个命令?

输出

 sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

NAME   FSTYPE   SIZE MOUNTPOINT            LABEL
sda           931.5G                       
├─sda1 ext4     660G /home/sda1_mountpoint 709G
├─sda2            1K                       
├─sda5 swap     7.7G [SWAP]                
├─sda6 vfat   123.4G /data124G             132G
├─sda7 ext4    74.3G /data73G              80G
└─sda8 ext4    66.1G /                     
sdb    ext4   931.5G                       
└─sdb1 ext4   931.5G /data1T               data1T
sr0            1024M

和输出

sudo parted -l

Model: ATA TOSHIBA DT01ACA1 (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      32.3kB  709GB   709GB   primary   ext4
 2      709GB   1000GB  291GB   extended
 7      709GB   788GB   79.7GB  logical   ext4
 6      788GB   921GB   132GB   logical   fat32
 8      921GB   992GB   71.0GB  logical   ext4
 5      992GB   1000GB  8266MB  logical   linux-swap(v1)


Model: ATA ST1000DM003-1ER1 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1000GB  1000GB  primary  ext4

背景信息- PC 未重新启动时出现问题。它卡在登录循环发生了类似的错误。我照做了ctrl-alt-f1。我发现用户的主目录不见了,即//home/是空的!我执行了 mkdir/home/user并将旧的备份主目录复制到那里,然后重新启动。它启动正常。后来我sda1在挂载了/home/sda1_mountpoint。它missing superblock出错了。我不得不执行fsck,然后它就挂载了。在 中找到了丢失的主目录sda1

所以我认为问题出在多个安装上。另请注意,lsblk 的输出都不是/home

编辑读完评论后,我安装sda1/home/home/sda1_mountpoint

的输出etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda8 during installation
UUID=10138724-bb55-4d41-b8f8-81fc42ec1a84 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=7d10a86a-3139-45af-bfc5-3dbb26a3e767 none            swap    sw              0       0
# sda1
UUID=b50f72de-3b8b-4453-a743-cc37f06055a5 /home           ext4   defaults    0    2 
# sda6
UUID=DBA5-EDA5 /data124G                                    vfat   defaults 0 0  
# sda7
UUID=01e6d118-230d-4f22-a528-3e7ff06aef39 /data73G          ext4 defaults 0 0
# sdb1
UUID=a92ea8c4-c810-4c06-8586-285bed30ea3f /data1T          ext4 defaults 0 0 

命令的输出mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=12301796k,nr_inodes=3075449,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=2464372k,mode=755)
/dev/sda8 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,relatime)
/dev/sdb1 on /data1T type ext4 (rw,relatime,data=ordered)
/dev/sda6 on /data124G type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/sda7 on /data73G type ext4 (rw,relatime,data=ordered)
/dev/sda1 on /home type ext4 (rw,relatime,data=ordered)
tmpfs on /run/user/108 type tmpfs (rw,nosuid,nodev,relatime,size=2464372k,mode=700,uid=108,gid=114)
gvfsd-fuse on /run/user/108/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=108,group_id=114)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=2464372k,mode=700,uid=1000,gid=1000)

答案1

没有迹象表明您的硬盘上有两个 Ubuntu 安装。如果有多个 Linux 安装,并且您已挂载所有有意义的分区(根据输出,您确实已挂载),如果您尝试查找基本系统文件(通常位于) lsblk,则会得到重复的结果。shadow/etc/

find / -type f -name shadow 2> /dev/null

恢复原始/home内容

您可能唯一重复的是主文件夹:

我发现用户的主目录不见了,即//home/是空的!我执行了 mkdir/home/user并将旧的备份主目录复制到那里,然后重新启动。

不过,您似乎已经发现了正确的解决方案:

后来我挂载sda1/home/sda1_mountpoint。它给出了missing superblock错误。我不得不执行fsck,然后它就挂载了。在 中找到了丢失的主目录sda1

由于该坐骑仍然存在于您/etc/fstab

# sda1
UUID=b50f72de-3b8b-4453-a743-cc37f06055a5 /home           ext4   defaults    0    2

它应该会在下次重新启动时自动挂载。如果没有,UUID 可能已更改,因此您应该在此文件中更新它。您可以使用以下方式获取当前 UUID blkid

sudo blkid /dev/sda1

删除重复的/home内容

剩下的唯一任务就是删除重复的主文件夹内容。/home根分区上的内容仍然存在于磁盘上,尽管它被覆盖了mount。这不是必需的,但数据仍然占用着你的磁盘空间……要访问它们,请将原始内容挂载到其他地方,例如/mnt

sudo mount --bind /home /mnt

然后打开/mnt目录,你应该看到临时文件的内容/home。删除或移动它们并卸载它:

sudo umount /mnt

参考

相关内容