如何协调Windows和Ubuntu的双启动设置

如何协调Windows和Ubuntu的双启动设置

Looking for some harmony between Windows 7 and Ubuntu in your dual-boot setup?  Here are a few ways you can make the tense OS situation a little more unified and copacetic.

在双引导设置中寻找Windows 7与Ubuntu之间的和谐? 您可以通过以下几种方法使紧张的操作系统状况更加统一和协调。

背景 (Background)

When we covered How to Choose a Partition Scheme for Your Linux PC, we noticed that some people were wondering how to use a third partition between Linux and Windows to act as a storage partition.

当我们讨论了如何为Linux PC选择分区方案时 ,我们注意到有些人想知道如何在Linux和Windows之间使用第三个分区作为存储分区。

Why It’s Difficult

为什么很难

As a few commenters pointed out, you can’t use an NTFS-formatted partition for /home in Linux.  That’s because NTFS doesn’t preserve all of the properties and permissions used by Linux, and Windows doesn’t even read Linux file systems.  You can readily see this if you view a folder that’s hidden in Windows from within Linux, or a file that Linux sees as hidden in Windows.  What works for one doesn’t work for the other.  Furthermore, there isn’t an incredibly clean way to move the Users folder in Windows without messing with things.  This is why many people with nicer machines end up using virtualization software; it’s easier than forcing the two to co-operate side-by-side.

正如一些评论者指出的那样,您不能在Linux中将NTFS格式的分区用于/ home。 这是因为NTFS不会保留Linux使用的所有属性和权限,并且Windows甚至不会读取Linux文件系统。 如果您从Linux内部查看Windows中隐藏的文件夹,或者Linux在Windows中视为隐藏的文件,则可以轻松地看到这一点。 对一个人有效的方法对另一个人无效。 此外,没有一种非常干净的方法可以在Windows中移动Users文件夹而不会造成混乱。 这就是为什么许多拥有更好机器的人最终都使用虚拟化软件的原因。 这比强迫两者并肩合作要容易。

如何协调Windows和Ubuntu的双启动设置

Image from cellguru.co.cc, assumed fair use

图片来自cellguru.co.cc ,假设是合理使用

A Work-Around

全面工作

There isn’t a way to run your /home directory from a FAT32 or NTFS partition, so your configuration files and scripts will have to remain there.  What you can do is redirect the other commonly used folders like Documents, Downloads, Music, etc. to another partition, one that can be read by Windows.  Then, you can add these folders to your Windows 7 Libraries and mark them as the default save location.

无法从FAT32或NTFS分区运行/ home目录,因此配置文件和脚本必须保留在该目录中。 您可以做的是将其他常用文件夹(如文档,下载,音乐等)重定向到另一个分区,该分区可以由Windows读取。 然后,您可以将这些文件夹添加到Windows 7库中,并将它们标记为默认保存位置。

This isn’t a proper workaround.  Your program-associated configuration files and other user-related settings will not be in the same place for this setup.  If you have to reinstall either OS, you will have to perform a separate backup of your user settings.  That being said, however, most people are really just concerned about their documents, music, videos, and so forth.  This solves that issue by pointing both OSs to look in the same place for them.

这不是一个适当的解决方法。 与该程序相关的配置文件和与用户相关的其他设置将不在此设置的同一位置。 如果必须重新安装任一操作系统,则必须对用户设置进行单独备份。 话虽这么说,但大多数人实际上只关心他们的文档,音乐,视频等。 通过将两个OS指向相同的位置来解决该问题。

Linux has come a long way with regards to reading and writing NTFS, and since it’s much better than FAT32 and tougher to configure this setup with, that’s what we’ll be covering in this guide.

Linux在读取和写入NTFS方面已经走了很长一段路,并且由于它比FAT32好得多,并且用它配置该设置更加困难,因此我们将在本指南中介绍。

Partition Scheme

分区方案

For this to work, you’ll want your hard drive set up in a way similar to this:

为此,您需要以类似以下方式设置硬盘驱动器:

  • Your Windows partition

    您的Windows分区
  • Your Linux partition

    您Linux分区
  • A large partition (or second hard drive!) to store your files

    一个大分区(或第二个硬盘!)来存储文件
  • A small swap partition

    小型交换分区

For later convenience, when you format your storage partition to NTFS, add an easily recognizable label to it.  It’ll be easier to find a drive called “storage” or “media” than by counting partition numbers.

为了以后使用方便,将存储分区格式化为NTFS时,请在其上添加一个易于识别的标签。 找到一个名为“存储”或“媒体”的驱动器比计算分区号要容易得多。

Notice that we don’t have a separate /home partition this time around.  Since the vast majority of your important/large files will be on a separate partition, this negates the need for that.  You’re welcome to use a separate /home partition to make backing up the Linux-side of things easier, just remember that you can’t exceed four primary partitions per disk.

请注意,这次我们没有单独的/ home分区。 由于您的大部分重要文件/大型文件将位于单独的分区上,因此无需这样做。 欢迎使用单独的/ home分区来简化Linux方面的备份,只是要记住,每个磁盘不能超过四个主分区。

Update: You can use more than four primary partitions if you use GPT instead of MBR.

更新 :如果使用GPT而不是MBR,则可以使用四个以上的主分区。

自动安装您的存储分区(Linux) (Auto-Mount Your Storage Partition (Linux))

Since we’re using NTFS, it’s a good idea to specifically tell your system to mount your storage partition or disk in the same place every time you boot.  To do this, we’ll be editing the /etc/fstab system file, which is the file system table used by Linux, but first, we have some preparations to make.  Open up terminal, and if this makes you nervous, just take a deep breath and relax.  It’ll be okay.

由于我们使用的是NTFS,因此最好在每次引导时明确告诉系统将存储分区或磁盘安装在同一位置。 为此,我们将编辑/ etc / fstab系统文件,这是Linux使用的文件系统表,但是首先,我们需要做一些准备。 打开终端,如果这使您感到紧张,请深呼吸并放松。 没关系的

Prep Work

准备工作

We need to install ntfs-3g, the driver Linux will use to read and write to NTFS.  If you already have it installed, it’ll tell you, so don’t worry.

我们需要安装ntfs-3g,Linux将使用该驱动程序读取和写入NTFS。 如果您已经安装了它,它会告诉您,所以不用担心。

sudo apt-get install ntfs-3g

须藤apt-get install ntfs-3g

If you see “ntfs-3g is already the newest version” then you already have it installed, otherwise you’ll see it work, so wait for it to finish its thing.  Next, let’s create the directory where your partition will mount.  If you want the drive to appear in the “Places” menu by default, you’ll use:

如果您看到“ ntfs-3g已经是最新版本”,则说明您已经安装了它,否则您将看到它可以正常工作,因此请等待它完成它的工作。 接下来,让我们创建分区将挂载的目录。 如果您希望驱动器默认出现在“位置”菜单中,则可以使用:

sudo mkdir /media/storage

须藤mkdir / media / storage

If you don’t want it to appear in “Places” and you want to manually browse to it for whatever reason, you can use this instead:

如果您不希望它出现在“位置”中,并且出于某种原因想要手动浏览到它,则可以改用以下方法:

sudo mkdir /mnt/storage

须藤mkdir / mnt / storage

This will create a “storage” directory in /media.  You can change this to something else if you like, but be sure it does not have any spaces.  Spaces will create a problem when we configure it to automatically mount in the next few steps.

这将在/ media中创建一个“存储”目录。 您可以根据需要将其更改为其他名称,但请确保它没有空格。 当我们将其配置为在接下来的几个步骤中自动挂载时,空格将产生问题。

fstab

fstab

Now, it’s time to edit the fstab file.  First, we’ll create a backup, just in case anything happens.

现在,是时候编辑fstab文件了。 首先,我们将创建一个备份,以防万一。

sudo cp /etc/fstab /etc/fstab.backup

须藤cp / etc / fstab /etc/fstab.backup

It’ll prompt you for your password, so go ahead and enter it.  If, for whatever reason, you need to restore the backup in the future, you would do this:

它将提示您输入密码,因此继续输入。 如果出于某种原因您以后需要恢复备份,则可以执行以下操作:

sudo cp /etc/fstab.backup /etc/fstab

须藤cp /etc/fstab.backup / etc / fstab

Next, you need to find what the UUID of your storage partition is.  The UUID stands for “universally unique identifier” and acts as a proper serial number that will not change until the partition is reformatted.  Run the following command:

接下来,您需要找到存储分区的UUID。 UUID代表“通用唯一标识符”,并充当适当的***,直到重新格式化分区后该***才会更改。 运行以下命令:

sudo blkid

须藤blkid

Enter your password, and you’ll see some output resembling this:

输入密码,您将看到类似以下的输出:

/dev/sda1: UUID=”23A87DBF64597DF1″ TYPE=”ntfs” /dev/sda2: UUID=”2479675e-2898-48c7-849f-132bb6d8f150″ TYPE=”ext4″ /dev/sda5: UUID=”66E53AEC54455DB2″ LABEL=”storage” TYPE=”ntfs” /dev/sda6: UUID=”05bbf608-87fa-4473-9774-cf4b2602d8d6″ TYPE=”swap”

/ dev / sda1:UUID =” 23A87DBF64597DF1” TYPE =“ ntfs” / dev / sda2:UUID =” 2479675e-2898-48c7-849f-132bb6d8f150” TYPE =“ ext4” / dev / sda5:UUID =” 66E53AEC54455DB2” LABEL = “存储” TYPE =“ ntfs” / dev / sda6:UUID =“ 05bbf608-87fa-4473-9774-cf4b2602d8d6” TYPE =“交换”

Find the line that has the correct label to your storage partition (makes things easy, doesn’t it?) and copy the UUID.

找到在存储分区上贴有正确标签的行(使事情变得容易,不是吗?),然后复制UUID。

gedit admin:///etc/fstab

gedit admin:/// etc / fstab

You’ll see gedit open, like so:

您将看到gedit打开,如下所示:

如何协调Windows和Ubuntu的双启动设置

You may see an uglier theme on gedit than usual, but don’t worry it.  Add the following lines to the bottom of fstab, substituting your own UUID instead of mine:

您可能会在gedit上看到比平常更丑陋的主题,但是请不要担心。 将以下行添加到fstab的底部,用您自己的UUID代替我的UUID:

# storage mount UUID=66E53AEC54455DB2 /media/storage/    ntfs-3g        auto,user,rw 0 0

#storage mount UUID = 66E53AEC54455DB2 / media / storage / ntfs-3g auto,user,rw 0 0

The first line is a comment, indicated by the leading hash tag.  The next line tells fstab to look for the partition with the specified UUID, mount it to /media/storage/, and to use the ntfs-3g driver.  Furthermore, it makes sure that it automatically mounts at boot, makes it accessible by users (not just root), gives both read and write privileges, and skip file-system checks (you’ll probably want to use Windows to do that).  Lastly, double-check, and triple-check to make sure you didn’t touch anything else, and that the UUID is correct.

第一行是注释,由前导哈希标签指示。 下一行告诉fstab查找具有指定UUID的分区,将其安装到/ media / storage /,并使用ntfs-3g驱动程序。 此外,它可以确保它在启动时自动挂载,使其可以被用户(不仅限于root用户)访问,提供读取和写入权限,并跳过文件系统检查(您可能想要使用Windows来执行此操作)。 最后,请仔细检查并进行三次检查,以确保您没有碰到其他东西,并且UUID是正确的。

如何协调Windows和Ubuntu的双启动设置

When you’re ready, click save and then reboot.  Don’t skip the reboot, as it’s necessary for the next step as well as to make sure things work.

准备就绪后,单击保存,然后重新启动。 不要跳过重启,因为这对于下一步以及确保一切正常很有必要。

You should be able to boot into Ubuntu as if nothing happened, but you’ll notice that you’ve got “storage” (or whatever you named it) under the Places menu now!  If not, check to make sure you got fstab correct.  See above to restore fstab from your backup, if you need to.

您应该能够启动Ubuntu,就像什么都没发生一样,但是您会注意到,现在在“位置”菜单下已经有了“存储”(或任何您命名的名称)! 如果不是,请检查以确保正确设置了fstab。 如果需要,请参阅上文,从备份中还原fstab。

配置子文件夹(Linux) (Configure Your Subfolders (Linux))

Open up terminal and enter the following command:

打开终端并输入以下命令:

gedit .config/user-dirs.dirs

gedit .config / user-dirs.dirs

This is the file where your “special” folders in your home directory are defined.

这是在主目录中定义“特殊”文件夹的文件。

如何协调Windows和Ubuntu的双启动设置

You can edit this to your liking.  In place of where you see “$HOME/Downloads” you would put in an absolute folder location, like “/media/storage/Downloads”.  Go ahead and create those folders, or whatever folders you’d like to call them, and put the path down for each of these.  Here’s what the finished edit should look like:

您可以根据自己的喜好进行编辑。 取代显示“ $ HOME / Downloads”的位置,您应该放在一个绝对文件夹位置,例如“ / media / storage / Downloads”。 继续创建这些文件夹,或创建任何您想调用的文件夹,并为每个文件夹放置路径。 这是完成的编辑应如下所示:

如何协调Windows和Ubuntu的双启动设置

Click save, and we’re done the crux of the configuration.  You may need to reboot for these changes to take effect, but you can just boot into Windows to finish out the process in the next section.

单击保存,我们完成了配置的关键。 您可能需要重新启动才能使这些更改生效,但是您可以直接引导到Windows以完成下一部分中的过程。

Basically, now when you browse and put files in your “Downloads” folder, they’ll actually go to your storage drive’s “Downloads” folder.  Anything in your home folder itself will stay in /home/yourusername/, not on your storage drive.  A few of the folders, like “Desktop” and “Templates,” probably won’t benefit from this treatment, either.  Templates are rarely used, the desktop usually gets cluttered with shortcuts and the like, and the Windows desktop isn’t elegantly redirected, unfortunately.

基本上,现在当您浏览文件并将其放在“下载”文件夹中时,它们实际上将转到存储驱动器的“下载”文件夹中。 主文件夹本身中的所有内容都将保留在/ home / yourusername /中,而不在存储驱动器中。 某些文件夹(例如“桌面”和“模板”)也可能不会从这种处理中受益。 很少使用模板,不幸的是,桌面通常会出现快捷方式之类的混乱情况,Windows桌面的重定向也不够优雅。

配置子文件夹(Windows) (Configure Your Subfolders (Windows))

Boot into Windows, and you’ll see that there’s another partition called “storage” under “My Computer.”  Windows 7 has the beautiful Libraries feature built-in, so take a look at our article “Understanding the Libraries Feature in Windows 7,” and you’ll see step-by-step directions on how to add your new storage folders to your libraries.

启动Windows,您会看到“我的电脑”下还有另一个分区,称为“存储”。 Windows 7具有内置的精美库功能,因此请阅读我们的文章“ 了解Windows 7中的库功能 ”,您将看到有关如何将新存储文件夹添加到库中的分步指导。

如何协调Windows和Ubuntu的双启动设置

As you can see, my storage drive folders are a part of my libraries.  My storage drive letter is E: because my network share is at D:.  Also, take a look at our “Change the Default Save Folder for Windows 7 Libraries…” article so that when you stick things in your libraries, they automatically get saved to your new storage folders as well.

如您所见,我的存储驱动器文件夹是我的库的一部分。 我的存储驱动器号为E :,因为我的网络共享位于D:。 另外,请看一下我们的“ 更改Windows 7库的默认保存文件夹... ”一文,这样,当您将内容粘贴到库中时,它们也会自动保存到新的存储文件夹中。

如何协调Windows和Ubuntu的双启动设置

The last thing you’ll have to change is the default “Downloads” directory in your preferred web browser(s), which can point to your “Downloads” library.  All done!

您最后需要更改的是首选Web浏览器中的默认“下载”目录,该目录可以指向“下载”库。 全做完了!

It’s also worth mentioning that if you have some know-how, you could even do this with a remotely shared drive on your network, though it may prove to be too slow for actual use.  A better idea is to turn your storage partition into a shared drive that can be accessed by other computers in your network.

还值得一提的是,如果您掌握了一些专门知识,则可以使用网络上的远程共享驱动器来做到这一点,尽管对于实际使用而言可能会太慢。 一个更好的主意是将您的存储分区变成一个共享驱动器,网络中的其他计算机可以访问该共享驱动器。



While there is no perfect solution to the problem of a unified shared drive for dual-booters, this layout works quite elegantly.  Most people mainly care that their downloaded files, documents, and media files can be accessed very easily regardless of which OS they’re using, and you’ll see that this scheme does that fairly well.  If you have any tips, or perhaps a better setup, please share them!

尽管还没有完美的解决方案来解决双引导程序的统一共享驱动器的问题,但这种布局的运行非常优雅。 大多数人主要关心的是,无论他们使用的是哪种操作系统,都可以非常轻松地访问其下载的文件,文档和媒体文件,并且您会发现该方案可以很好地实现这一目标。 如果您有任何建议或更好的设置,请分享!

翻译自: https://www.howtogeek.com/howto/35807/how-to-harmonize-your-dual-boot-setup-for-windows-and-ubuntu/