如何修复/重建损坏的 fstab Ubuntu 16.04 以重新获得对分区的访问权限

如何修复/重建损坏的 fstab Ubuntu 16.04 以重新获得对分区的访问权限

你好,我是 Ubuntu 新手,想要学习(实际上已经使用了一段时间,但遇到很多挫折,进展缓慢)。

我遇到了一些问题,分区出现在 Nautilus 中,但没有出现在 gksudo nautilus 中。我使用 gksudo nautilus 是因为我没有 root 权限访问我的分区,可能问题与 etc/fstab 有关

我研究了 Ubuntu,发现了一些非常有用的信息。正常的 etc/fstab 看起来应该是这样的:-

/dev/hda2   /              ext2 defaults             1 1
/dev/hdb1   /home          ext2 defaults             1 2
/dev/cdrom  /media/cdrom   auto ro,noauto,user,exec  0 0
/dev/fd0    /media/floppy  auto rw,noauto,user,sync  0 0
proc        /proc          proc defaults             0 0
/dev/hda1   swap           swap pri=42               0 0

但我的看起来像这样:-

# /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/sdc1 during installation
UUID=617469bb-1180-4678-8274-5f88084f7162 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda3 during installation
UUID=fc44ce96-8676-46c6-be06-0113bbc716de none            swap    sw              0       0
# swap was on /dev/sdc2 during installation
UUID=6251911e-b45b-444a-9ac5-c365cb8dca5e none            swap    sw              0       0

大家有什么想法吗

答案1

阅读man fstab。您的fstab没问题。它使用 UUID 来标识分区,而不是/dev/路径。您显示:

/ mounted on UUID 617469bb-1180-4678-8274-5f88084f7162 (was /dev/sdc1 at installation)
swap on UUID fc44ce96-8676-46c6-be06-0113bbc716de (was /dev/sda3 at installation)
swap on UUID 6251911e-b45b-444a-9ac5-c365cb8dca5e (was /dev/sdc2 at installation).

/etc/mtab显示此刻已安装的内容,/etc/fstab显示将要安装的内容。

答案2

看来您混淆了两件事。现在这是正常的(正如您所说的)fstab

cat /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/sda2 during installation
UUID=43bdfb68-9917-4937-aa5a-932bd2a94c98 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=B35B-35B8  /boot/efi       vfat    defaults        0       1
# swap was on /dev/sda3 during installation
UUID=e0ca0a52-fd55-459f-820a-be3531e21800 none            swap    sw              0       0

# file syc between ~/www and /var/www/html
/var/www/html   /home/george/www none bind 0 0
/var/cache/swap/kswap           none      swap     sw     0     0

现在真正安装的是cat /etc/mtab

sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,relatime,size=4031064k,nr_inodes=1007766,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=810344k,mode=755 0 0
/dev/sda2 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs rw,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset,clone_children 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids,release_agent=/run/cgmanager/agents/cgm-release-agent.pids 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event,release_agent=/run/cgmanager/agents/cgm-release-agent.perf_event 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb,release_agent=/run/cgmanager/agents/cgm-release-agent.hugetlb 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
/dev/loop1 /snap/core/1441 squashfs ro,relatime 0 0
/dev/loop0 /snap/core/1577 squashfs ro,relatime 0 0
/dev/loop3 /snap/canonical-livepatch/17 squashfs ro,relatime 0 0
/dev/loop2 /snap/core/1689 squashfs ro,nodev,relatime 0 0
/dev/loop5 /snap/canonical-livepatch/22 squashfs ro,relatime 0 0
/dev/loop4 /snap/canonical-livepatch/21 squashfs ro,relatime 0 0
/dev/sda2 /home/george/www ext4 rw,relatime,errors=remount-ro,data=ordered 0 0
/dev/sda1 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
cgmfs /run/cgmanager/fs tmpfs rw,relatime,size=100k,mode=755 0 0
tmpfs /run/snapd/ns tmpfs rw,nosuid,noexec,relatime,size=810344k,mode=755 0 0
nsfs /run/snapd/ns/canonical-livepatch.mnt nsfs rw 0 0
tmpfs /run/user/117 tmpfs rw,nosuid,nodev,relatime,size=810344k,mode=700,uid=117,gid=128 0 0
vmware-vmblock /run/vmblock-fuse fuse.vmware-vmblock rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other 0 0
/dev/sda2 /var/lib/docker/aufs ext4 rw,relatime,errors=remount-ro,data=ordered 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=810344k,mode=700,uid=1000,gid=1000 0 0
gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0

您可以看到输出完全不同,当您说可以使用 访问它时gksudo,为什么要尝试以这种方式访问​​它以及您想要做什么。要查看您的分区,请使用:

sudo fdisk -l

Disk /dev/loop0: 78.4 MiB, 82153472 bytes, 160456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 78.3 MiB, 82083840 bytes, 160320 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 79.5 MiB, 83349504 bytes, 162792 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop3: 4.3 MiB, 4550656 bytes, 8888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop4: 4.3 MiB, 4550656 bytes, 8888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop5: 4.4 MiB, 4558848 bytes, 8904 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 70742F28-EC54-48F1-B2C8-F0A7F80FD3D1

Device          Start        End    Sectors   Size Type
/dev/sda1        2048    1050623    1048576   512M EFI System
/dev/sda2     1050624 1936889855 1935839232 923.1G Linux filesystem
/dev/sda3  1936889856 1953523711   16633856     8G Linux swap

或者列出更多你的区块:

sudo lsblk -i

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
|-sda1   8:1    0   512M  0 part /boot/efi
|-sda2   8:2    0 923.1G  0 part /
`-sda3   8:3    0     8G  0 part [SWAP]
sr0     11:0    1  1024M  0 rom  
loop0    7:0    0  78.4M  0 loop /snap/core/1577
loop1    7:1    0  78.3M  0 loop /snap/core/1441
loop2    7:2    0  79.5M  0 loop /snap/core/1689
loop3    7:3    0   4.3M  0 loop /snap/canonical-livepatch/17
loop4    7:4    0   4.3M  0 loop /snap/canonical-livepatch/21
loop5    7:5    0   4.4M  0 loop /snap/canonical-livepatch/22

您的 OP 标题How to fix / reconstruct corrupt fstab Ubuntu 16.04 to regain access to partitions,您不能在安装时这样做,您必须卸载它才能获得访问权限。liveCD使用gparted可以实现这一点,但请轻按线程as it appears you quit a novice. Try using a虚拟机`来感受您在尝试此操作时可能遇到的所有麻烦。

警告分区可能与我在此处显示的不同,请运行这些命令,它们将显示您在安装 Ubuntu 时设置的分区

相关内容