当前位置: 首页>>技术教程>>正文


如何从ubuntu隐藏(n)(NTFS)分区

, , ,

问题描述

我需要在nautilus中隐藏NTFS分区。我怎样才能做到这一点?

有没有工具可以做到这一点?

如何在ubuntu中隐藏文件(除了。运算符)

最佳解决方法

通过»磁盘«隐藏Nautilus的分区

在Ubuntu 12.10及更高版本中,有一个名为Disks的实用程序,它显示所有可用磁盘并允许修改每个分区的挂载选项。

在各种选项中,您可以决定是否在启动时挂载分区,以及它是否会出现在用户界面中。应用更改需要管理员权限。

partitioning,filesystem,ntfs,ubuntu

次佳解决方法

This指南可以帮助您。

How do you hide disks from showing up in Nautilus?

First, you must know what disks and/or partitions you want to hide. From what I’ve observed, Nautilus will either present these devices by label. If it does not have a label, then the device will be associated with the disk/partition size.

Look at the image below. The ones in the red box don’t have labels. File System is always the current /root partition, while the 45 GB File System is a partition that does not have a label. In this example, it is the /root partition of my Ubuntu 10.10 (I’m running on Natty Narwhal but have kept my Maverick Meerkat as a backup of sorts). The other two – Lucid Lynx and Karmic Koala – are the labels of my 2 NTFS partitions.

enter image description here

The labels are important in case you are not familiar with how Linux refer to these devices. In Windows, whether it is a disk or a partition, they are called by letters – C or D – and so on. Linux has a more specific naming system. It is normally sdaX or hdbY, where X and Y are the numbers of the partitions on the sda or hdb drives, respectively. Thus, if there are 3 partitions on sda drive, then there will be sda1, sda2 and sda3. Windows will more likely just call it C, D, and E.

Now mount all of your drives and/or partitions. You know how to do that, don’t you? Click the name in Nautilus and it will mount it for you. I suggest you unmount and remove all removable drives to avoid confusion.

Once you’ve mounted all, open a terminal by running gnome-terminal. Just type that in dash if you’re using Natty, or find it in the menu if you’re using the classic Ubuntu desktop. The reason why mounting all is the easier way to find out the device names is because mount will literally tell you that device X is mounted at directory Y with the name Z. Easy right? You can look in /proc/partitions or /dev/disks/ but it will only confuse you.

Run the command mount once. From the output, take note of the names of the drive or partitions through its associated label. It will look something like the image below.

enter image description here

On the second image above, you will notice that there is no reference to the mounted 45 GB File System. That is because the latter does not have a label, as I’ve mentioned previously, and the uuid is too long and will look horrible on Nautilus. The underlying system will mount it by its uuid name on /media, while the rest are mounted by its label.

Since the 45 GB File System (/dev/sdb2) really has no business being displayed on Nautilus, I want to hide that. I also want to hide Karmic Koala (/dev/sda1) because it is my Windows C partition. Heaven forbid I delete files from any of these partitions by accident.

Now the hiding begins! But before that, make sure you know which partitions you want to hide (like how I identified them above). You can also list all of your partitions using the command sudo fdisk -l to identify them faster. I’m going to be hiding sda1 and sdb2 in the next steps, but you should substitute your partition names instead.

  1. Create a file named 99-hide-disks.rules using your favorite editor. This file is where we put the rule to tell the Linux kernel to hide the device. I won’t explain why the file name sounds funny. That will be the subject for another post here if I won’t feel too lazy explaining it.

  2. Put the text below in the file you just created, but make sure to change the device name that applies to your case. On mine I want to hide sda1 and sdb2.

    The general format is (this is case sensitive):

    KERNEL=="device name", ENV{UDISKS_PRESENTATION_HIDE}="1" 

    In my case, I will write the following in 99-hide-disks.rules:

    KERNEL=="sda1", ENV{UDISKS_PRESENTATION_HIDE}="1" KERNEL=="sdb2", ENV{UDISKS_PRESENTATION_HIDE}="1" 

    Don’t forget to save when you’re done.

  3. Now copy the file to /etc/udev/rules.d/ with the command,

    sudo cp 99-hide-disks.rules  /etc/udev/rules.d/ 

    Now we’re done. This will have been noticed immediately by the system because udev (the device manage for Linux) looks for changes to the rules folder through inotify (this is a file system event notifier service). However it will not be applied until you reboot. Supposedly you can use the udevadm command to trigger the new rules, but I haven’t really tested it yet. Reboot your Ubuntu and notice how the partitions are no longer visible in Nautilus.

Edit:

At least for Ubuntu 12.10, the lines above don’t work anymore, and should be changed to use this format instead:

KERNEL=="sda1", ENV{UDISKS_IGNORE}="1" KERNEL=="sdb2", ENV{UDISKS_IGNORE}="1" 

第三种解决方法

谢谢你,非常方便的教程。我实际上在Ubuntu 14.04中找到了一种更简单的方法

  1. 点击超级/Windows键

  2. 键入并打开磁盘

  3. 选择要隐藏的分区,使其变为橙色

  4. 选择cog /settings /advanced设置图标。单击编辑装载选项

  5. 关闭自动安装

  6. 取消选中“启动时安装”和“用户界面中显示”

  7. 保存&重启

不需要终端,也许这是14.04的新功能?不确定哪种方式更容易和有效。

在此任务完成后,我再次重新启动以重新检查Windows系统,并且双启动工作完美。如果您没有时间来解决问题,或者如果您仍在学习终端命令的精美艺术,那么这是一种很棒的方式:P

希望这可以帮助。

干杯

第四种方法

Tachyons提供了一个great answer,它显示了如何将分区隐藏到udisks应用程序(例如Dolphin)。依赖于固定分区名称的是error-prone,但最好使用分区唯一的UUID。这个答案是用Kubuntu 13.10测试的。

要做到这一点,首先必须找到一个UUID。这可以通过多种方式找到,其中一种方法是运行命令udisksctl info -b /dev/sda1(其中/dev/sda1当然是您的分区)。 UUID在IdUUID下可见,并且分区未标记为隐藏(忽略):


/org/freedesktop/UDisks2/block_devices/sda1:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sda1
    DeviceNumber:               2049
    Drive:                      '/org/freedesktop/UDisks2/drives/...'
    HintAuto:                   false
    HintIconName:
    HintIgnore:                 false
    HintName:
    HintPartitionable:          true
    HintSymbolicIconName:
    HintSystem:                 true
    Id:                         by-id-ata-...-part1
    IdLabel:                    SystemReserved
    IdType:                     ntfs
    IdUUID:                     A10CDE7682786D73
    IdUsage:                    filesystem
    IdVersion:
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sda1
    ReadOnly:                   false
    Size:                       104857600
    Symlinks:                   /dev/disk/by-id/ata-...-part1
                                /dev/disk/by-id/wwn-...-part1
                                /dev/disk/by-label/SystemReserved
                                /dev/disk/by-uuid/A10CDE7682786D73

现在,为了隐藏此分区,请创建一个udev规则,该规则通过此UUID与分区匹配,并将其隐藏在udisks中。例如,如果要隐藏上面的NTFS分区(使用UUID A10CDE7682786D73)和另一个ext4分区(使用UUID faae2c6a-0545-4bfa-a545-440c63467467),则/etc/udev/rules.d/99-hide-partitions.rules文件应包含:


# hide "SystemReserved" partition in UI
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="A10CDE7682786D73", ENV{UDISKS_IGNORE}="1"
# hide /home partition in left panel
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="faae2c6a-0545-4bfa-a545-440c63467467", ENV{UDISKS_IGNORE}="1"

注释是可选的,但建议使UUID变得不那么神奇。一定不要将===混淆,设置变量,另一个与变量进行比较。

创建规则文件后,通过重新引导或运行来应用它:

sudo udevadm control --reload
sudo udevadm trigger --subsystem-match=block

现在再次运行udisksctl info -b /dev/sda1命令,它应该包含:


    HintIgnore:                 true

第五种方法

答案现在应该更新。您可以关注this guide,但有所不同:您不必写这个(原来在其他答案中写的)

KERNEL=="sda1", ENV{UDISKS_PRESENTATION_HIDE}="1"
KERNEL=="sdb2", ENV{UDISKS_PRESENTATION_HIDE}="1"

相反,你应该这样写:

KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"
KERNEL=="sdb2", ENV{UDISKS_IGNORE}="1"

其余的都一样:)

第六种方法

你无法真正隐藏分区,因此它们绝对不能100%安装在Linux中,除非物理上移除它们所在的磁盘。也就是说,我认为你不需要那么高的安全水平。我怀疑你只是不想意外点击一个图标进入NTFS分区。为此,您可以编辑/etc /fstab文件。为要隐藏的每个分区添加这样的条目:

假设您的ntfs分区是dev /sda1然后使用此代码

/dev/sda1  /mnt/hidden  ntfs-3g  noauto,ro  0 0

This configures the system to keep /dev/sda1 from being mounted automatically at boot time (the “noauto” part of the entry). It also sets it up so that it can be mounted manually at /mnt/hidden, but only as a read-only partition (the “ro” option). If you add the “users” option (as in “noauto,ro,users”), ordinary users (that is, you) will be able to mount the partition; but with this option missing, you’ll need to use sudo to mount the partition. It’s your choice how far you want to go with this — you could leave out the “ro” and/or add “users”, for instance.

And how can i hide files in ubuntu (except . operator)?

请参阅this Answer

资源

  1. http://ubuntuforums.org/showthread.php?p=9901316

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2175.html,未经允许,请勿转载。