https://wiki.archlinux.org/api.php?action=feedcontributions&user=Sachiru&feedformat=atomArchWiki - User contributions [en]2024-03-28T16:14:05ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Dual_boot_with_Windows/SafeBoot&diff=185258Dual boot with Windows/SafeBoot2012-02-19T01:25:08Z<p>Sachiru: /* Defragment the Windows Partition */</p>
<hr />
<div>[[Category:Security (English)]]<br />
[[Category:File systems (English)]]<br />
[[Category:Boot process (English)]]<br />
{{out of date}}<br />
<br />
This is a discussion about how to create a dual boot setup with Windows when whole disk [http://www.mcafee.com/us/products/data-protection/endpoint-encryption.aspx SafeBoot] (now called [http://www.mcafee.com/us/products/data-protection/endpoint-encryption.aspx McAfee Endpoint Encryption]) encryption is employed. This may be the case particularly if one is issued a company laptop that comes pre-installed with Windows and is encrypted. While one can wipe the drive and install a) Linux alone or b) Linux and an unencrypted version of Windows, some sacrifices and risks may exist. For example, company patches and updates may no longer work properly, IT policies may be violated, data is no longer protected, and, if Linux alone is installed, the capability to share files, access company specific intranet applets, and other limitations may be experienced.<br />
<br />
This article will explain one method for creating a dual boot setup while leaving the company-installed encryption and operating system intact and fully functional.<br />
<br />
{{Note|This author only has experience with Windows 7 and an account created in the Administrator group. It is unknown whether this works with other versions of Windows or with reduced user privileges.}}<br />
<br />
<br />
==Why is a solution needed?==<br />
The situation of a fully encrypted system is a difficult one because even the MBR is encrypted and SafeBoot uses its encrypted bootloader to load the real partition table and load Windows. Thus, if one attempts to simply partition the disk with [c]fdisk, writing the partition table will render one's system unbootable. Likewise, even if there ''is'' a free partition, a) one isn't able to update the partition table with the correct type (which is necessary), b) one can't install the bootloader (e.g. grub) to the MBR, and c) even if one installs the bootloader to the partition instead of the MBR, there is no way to make the system aware that such a bootloader exists via the partition table. It is quite a difficult situation to work with.<br />
<br />
Some are content with using live distributions or running Linux from a flash drive; the primary author of this article found such methods frustrating and limiting. There is also quite a lot of discussion about how to get around this situation, [1] [2] [3] and thus an article seemed relevant after a firsthand experience and success.<br />
<br />
<br />
<br />
==Alternatives Considered==<br />
The primary author of this article has experience with only one successful method, but considered several, including:<br />
* Trying to create a "live clone" (full system backup while Windows was running) in order to possess a decrypted copy of the OS, wiping the drive, and then reinstalling the OS to a partition encrypted with an opensource encryption system. This may prevent company patches from operating successfully and may violate policies if a company mandates a particular encryption method.<br />
* Trying to use dd to simply block-copy everything from one disk onto an external drive, wipe the internal drive and re-partition, and then dd the external drive back to the internal, and dd a backup of the SafeBoot MBR back to the internal drive. This seems a bit risky, and also requires that one have another hard drive at least as big as the original encrypted partition.<br />
* While not really a solution in the dual-boot category, simply running Linux inside of a virtualization program is a perfectly reasonable solution. It is by far the simplest. The primary author simply doesn't like the idea and wanted a fully dual-boot setup, however he does have VirtualBox setup in Windows to avoid excessive reboots if Windows usage is needed heavily for any particular task.<br />
<br />
<br />
<br />
==The Method Proposed==<br />
In brief, the successful setup used by this author is as follows:<br />
* Use Windows 7 build in partition editor to partition the drive<br />
** '''Partition 1:''' Windows<br />
** '''Partition 2:''' Linux /boot<br />
** '''Partition 3:''' Linux /<br />
** '''Partition 4:''' TrueCrypt device for shared files<br />
* Use [http://partitionwizard.com/ Partition Wizard HomeEdition] to tweak some things<br />
* Use [http://neosmart.net/dl.php?id=1 EasyBCD] to add an entry for Arch Linux at boot time<br />
* Install Arch using [[System_Encryption_with_LUKS]]<br />
* Configure grub<br />
* Reboot and hold breath<br />
* Install TrueCrypt on both OSs and create a TrueCrypt volume<br />
<br />
<br />
==Step by Step Walkthrough==<br />
<br />
===Defragment the Windows Partition===<br />
If the issued computer is encrypted with SafeBoot, it will likely contain one primary partition where Windows is installed. We need to shrink this partition in order to make space for Linux. To shrink this partition as much as possible, defragmenting is helpful. Windows 7 comes with a built in defragmenting utility, available through the control panel. Open this program and defrag on the primary drive (probably called C:\). Do this several times, if desired.<br />
<br />
It may be helpful to use an additional program as well. Wikipedia has a list of various options [http://en.wikipedia.org/wiki/List_of_defragmentation_software HERE]. The author of this article used [http://www.auslogics.com/en/software/disk-defrag/ Auslogics Disk Defrag], which worked well and had the ability to view what specific files were unmovable. Such files will hinder the minimum size possible to shrink the volume in the next step.<br />
<br />
* Screenshot of Auslogic Disk Defrag [http://i.imgur.com/XJnZx.png HERE]<br />
* Screenshot showing an unmovable file related to SafeBoot [http://i.imgur.com/fzfOe.png HERE] (click any gray, unmovable square to see details)<br />
<br />
For some other options for maximizing the amount one can shrink a Windows partition, see the article [http://www.howtogeek.com/howto/windows-vista/working-around-windows-vistas-shrink-volume-inadequacy-problems/ HERE]. While it is written for Windows Vista, it contains some applicable suggestions for Windows 7 as well. The author of this article disabled system restore temporarily and was able to shrink the partition another 6 GB.<br />
<br />
{{Note | '''After shrinking the partition in the next step, you should undo any system-critical adjustments you made during this step. In other words, re-enable system recovery, paging file, etc.'''}}<br />
<br />
===Shrink the Windows Partition===<br />
Once defragmenting is complete, open the control panel and either search for "partition" or navigate to System and Security > Administrative Tools > Create and Format Hard Disk Partitions. This will open Windows 7's built-in partition editor as shown [http://i.imgur.com/33WpH.png HERE]. Right click on the Windows 7 partition and choose "Shrink Volume." This will open a dialog prompting you for the amount you want to shrink the volume. The dialog will also inform you of the maximum amount possible to shrink the volume. Shrink the volume by the desired size, or, if unmovable files prevent you from shrinking it as much as you'd like, just shrink it as much as possible. For a more picture-filled walkthrough, see [http://www.howtogeek.com/howto/windows-vista/resize-a-partition-for-free-in-windows-vista/ this article]<br />
<br />
When this step completes, the Windows partition will be smaller and the rest of the partition will be denoted as "Unallocated space." Right click the unallocated section and choose "New Simple Volume." Windows will walk you through the steps necessary to create a new volume. Repeat these steps for the desired number of partitions. On possible setup would be like so:<br />
* Windows 7 (C:\): size will be whatever it was set to in this step<br />
* Linux boot: 64 MB. This is necessary if one wants an encrypted Linux partition<br />
* Linux \: If only the OS will be installed to this partition, perhaps make it ~30-50GB depending on your application needs<br />
* TrueCrypt partition: for shared files between Windows and Linux. Make it take the rest of the unallocated space.<br />
<br />
For each of these drives, the format doesn't really matter because they'll all be reformatted. Choose FAT or NTFS and let Windows create the volumes. For a walkthrough on adding volumes from unallocated space, see [http://techblissonline.com/resize-or-create-disk-partition/ this article].<br />
<br />
{{Note | if the fourth partition added is surrounded by green and denoted as an extended partition, do not worry. Windows 7 does this automatically and we will fix it in the next step.}}<br />
<br />
<br />
===Edit the Partition Table===<br />
It is now necessary to edit the partition table so that it shows the Linux partitions as actual Linux partitions rather than FAT or NTFS (whatever was created in the last step). Since we can't use fdisk to write the partition table, we'll use a tool in Windows itself. This author used [http://partitionwizard.com/ MiniTool Partition Wizard Home Edition], a free partition tool recommended highly by [http://download.cnet.com/Partition-Wizard-Home-Edition/3000-2094_4-10962200.html CNET]. Open the program and right click on a partition that will contain a Linux filesystem. Choose "Change partition type ID" from the drop down menu. Choose the manual ID entry option and set the type to <code>0x83</code>, as shown [http://i.imgur.com/YN4yH.png HERE]. Repeat this with any other partitions that will be formatted with Linux filesystems. For a walkthrough on this step, see [http://www.fanhow.com/knowhow:Change_Partition_Type_ID_in_Windows_7_46298757 this article].<br />
<br />
Lastly, if a fourth partition was created in the previous step, click it, and then go to the Disk menu and choose "Convert dynamic disk to basic disk." This will change the extended partition to a simple one. For a walkthrough on this, see [http://www.partitionwizard.com/help/convert-dynamic-disk-to-basic-disk.html this article].<br />
<br />
When finished, click the "Apply" button in the upper left of the main window.<br />
<br />
<br />
===Add an Option to Boot Linux===<br />
Next, we're going to add a Linux option to the Windows boot options using a free program called [http://neosmart.net/dl.php?id=1 EasyBCD]. Theoretically, this should be possible using Windows 7's built in program, bcdedit, as shown [http://www.windows7home.net/how-to-use-bcdedit-in-windows-7/ HERE]. The author had difficulty attempting this due to privilege errors, and was successful with EasyBCD and thus never retried with bcdedit. Open EasyBCD and click "Add New Entry" on the left. Choose the Linux/BSD tab and set the bootloader type (Grub (legacy)) for Arch and partition. Make sure that if you are going to have a dedicated boot partition that you point EasyBCD to that partition, ''not'' the one that will contain the root filesystem. A screenshot of these settings may be found [http://i.imgur.com/YE79o.png HERE].<br />
<br />
Next view the entry by clicking "View Settings," and make sure everything looks appropriate. For a legacy grub setting pointing toward the second partition on the disk, the boot entry should look like [http://i.imgur.com/5zri9.png THIS].<br />
<br />
<br />
===Backup the SafeBoot MBR===<br />
{{Note | It is '''highly''' recommended that one make a backup of the SafeBoot MBR before proceeding. If anything accidentally happens to it, you can restore it and will have a functioning system. Without a backup, if you use [c]fdisk and write the partition table to the MBR, or install Grub to the MBR, ''you will lose the ability to ever, ever, ever get back to your Windows installation.''}}<br />
<br />
To back up the SafeBoot MBR, boot into a live Linux CD and have a flash drive inserted:<br />
# mount /dev/sdb1 /mnt (or whatever the desired flash drive address is)<br />
# dd if=/dev/sda of=/mnt/safeboot.mbr bs=512 count=1<br />
# umount /dev/sdb1<br />
<br />
If anything happens while installing Arch and you wipe the SafeBoot MBR, you can restore it by reversing the process. Again, boot into a Live CD and insert the flash drive:<br />
# mount /dev/sdb1 /mnt<br />
# dd if=/mnt/safeboot.mbr of=/dev/sda bs=512 count=1<br />
# umount /dev/sdb1<br />
<br />
Now reboot and things should be as they were.<br />
<br />
<br />
<br />
===Install Linux===<br />
With all of these steps completed, reboot into an Arch Install CD. See the [[Official_Arch_Linux_Install_Guide]] if you are unsure about how to install Arch. For an encrypted system, follow the directions covered aptly at [[System_Encryption_with_LUKS]]. Regardless of what method you use for installation, '''do not install the bootloader to the MBR.''' Once you finish installing and configuring files, follow these steps:<br />
* Mount your boot partition if it's not already mounted<br />
<br />
** If you installed manually or know you do not have a filesystem on your boot partition yet, make one<br />
# mkfs.ext2 /dev/sda2<br />
** Then mount the partition<br />
# mount /dev/sda2 /mnt/boot<br />
<br />
* Verify that grub files are present<br />
# ls /mnt/boot/grub/<br />
** If files like stage1 and the like are present, proceed<br />
** If not, make the directory /mnt/boot/grub (if necessary) and copy the necessary files to the grub folder<br />
# mkdir /mnt/boot/grub<br />
# cp -a /usr/lib/grub/i386-pc/* /mnt/boot/grub/<br />
<br />
* Get ready to chroot into the installed system<br />
# mount -t proc /proc /mnt/proc<br />
# mount -t sysfs /sys /mnt/sys<br />
# mount -o bind /dev /mnt/dev<br />
<br />
* Chroot into /mnt<br />
# chroot /mnt<br />
<br />
* Now run grub<br />
# grub<br />
# root (hd0,1)<br />
# setup (hd0,1)<br />
<br />
{{Note | The above example assumes that /boot is on /dev/sda2, which is the second partition on the drive. Since grub starts from 0, this corresponds to (hd0, 1) or first disk (hd0), second partition (,1). See the [[GRUB]] article for more information.}}<br />
<br />
* Depending on the process you took, it's not a bad idea to re-install the kernel26 package if /boot wans't properly mounted during the installation of the base package. Sync pacman from the chroot environment and then reinstall the kernel26 package:<br />
# pacman -Sy<br />
# pacman -S kernel26<br />
<br />
* If using system encryption, be sure to add <code>encrypt</code> to /etc/mkinitcpio and regenerate the initramfs with<br />
# mkinitcpio<br />
See [[System_Encryption_with_LUKS#Configure_System]] for more details.<br />
<br />
* Finally, if /boot/grub/menu.lst does not exist, copy and edit it:<br />
# exit (get out of the chroot)<br />
# cp /boot/grub/menu.lst /mnt/boot/grub/<br />
# nano /mnt/boot/grub/menu.lst<br />
<br />
Edit the entry according to [[GRUB#Dual_booting_with_GNU.2FLinux]] (don't forget to add the required extra options if using an encrypted system. See [[System_Encryption_with_LUKS#Install_Bootloader]] for more details).<br />
<br />
<br />
===Test Configuration===<br />
When satisfied, exit the installer and reboot. Be sure to press any necessary keys to tell the computer to boot from the hard drive if the Arch CD is still in the optical bay; many computers default to booting from media, if present. Windows should now present you with an option to boot either Windows or Linux. Select Linux. If all goes well, you should see the grub boot menu and can select your new installation of Arch to boot. If you get a grub prompt, do not fret: you may still be able to boot. Try entering the grub commands manually:<br />
grub > root (hd0,1)<br />
grub > kernel /vmlinuz26 root=/dev/mapper/map-name cryptdevice=/dev/sda3:map-name ro<br />
grub > initrd /kernel26.img<br />
grub > boot<br />
<br />
It this works, then the issue exists in the EasyBCD entry we made earlier. If it doesn't grub may not have been installed to the right location.<br />
<br />
<br />
===Create a Shared TrueCrypt Volume===<br />
Once your Arch system is setup as desired, TrueCrypt may be used to create a shared device or file for sharing files between Windows and Linux. See the [[TrueCrypt]] article for details. This author created a TrueCrypt volume from Arch, formatted to FAT and then re-formatted to NTFS. Following using the GUI to create the volume, these steps were taken:<br />
$ sudo pacman -S ntfs-3g ntfsprogs<br />
$ sudo truecrypt --filesystem=none --slot=1 /dev/sda4<br />
$ sudo mkfs.ntfs /dev/mapper/truecrypt1<br />
<br />
After this process completes, /dev/mapper/truecrypt1 will be properly formatted and can be mounted to a mountpoint for use:<br />
$ sudo mount /dev/mapper/truecrypt1 /mnt<br />
<br />
NTFS does not use Linux permissions and attributes, so it may be helpful to pass options like the following:<br />
$ sudo mount -o ntfs-3g uid=1000,gid=100,fmask=113,noatime /dev/mapper/truecrypt1 /mnt<br />
<br />
See [[NTFS-3G]] for more information.<br />
<br />
{{Note|TrueCrypt includes its own ability to both map and mount an encrypted file or device in one step, however as of version 7.0a (current Arch version as of 4/19/2011), some have reported problems with NTFS formatted devices and mounting. This author has found that the two-step process outlined above (first, using <code>truecrypt --filesystem<nowiki>=</nowiki>none --slot<nowiki>=</nowiki>1 /dev/sda4</code>, and then the system's mount command, <code>mount /dev/mapper/truecrypt1 /mnt</code>) works reliably. A bug report exists [https://bugs.archlinux.org/task/23184 HERE] and contains a post by this author with more detail.}}<br />
<br />
Finally, reboot into Windows, install TrueCrypt, and attempt to mount the device. Once verified that both OSs can mount the volume, begin adding any files that one desires to share between OSs.<br />
<br />
<br />
==Summary==<br />
If all of the above goes smoothly, one should have a dual-booting, fully encrypted system (if Linux was installed using the LUKS/dm-crypt method) with the exception of a Linu /boot partition. In addition, both Window and Linux can share files via the TrueCrypt volume. The process seems to be advantageous to other methods in that it does not require juggling of the SafeBoot mbr, using dd or other tools to clone the drive and then clone it back after partitioning, does not require extra external hard drives for such cloning, leaves any company-installed components alone (with the exception of shrinking their footprint), and yet maintains a high level of system security.<br />
<br />
==Troubleshooting==<br />
* If one encounters a grub shell but can boot if manually entering the proper commands, reboot into Windows and verify the EasyBCD settings mentioned above. Verify that the bootloader type was correct (grub legacy vs. grub2 vs. others) and that the drive was correct. The drive chosen should be that containing Linux /boot, '''not''' the main Linux OS root partition.<br />
* '''Do not''' attempt to install grub to the root Linux partition, as this will wipe the LUKS/dm-crypt header and render the partition unusable unless you have a backup of the header. In other words, be very careful when issuing the command <code>grub > setup (hd0,'''X''')</code> and make sure that X is the boot partition, '''not''' the encrypted root partition.<br />
* If trying to install grub and one sees an error about an unknown filesystem or partition type and the code <code>0x7</code>, you've either pointed grub to the wrong place (wrong partition number), or did not successfully change the partition type ID. 0x7 is the identifier for NTFS. Reboot back into Windows, open the Partition Wizard discussed above, and manually change the type to <code>0x83</code>. Then reboot and attempt to install grub again. After issuing <code>grub > root (hd0,1)</code>, grub should report back <code>Filesystem type is ext2fs, partition type 0x83</code>. This is what you want.<br />
<br />
==Additional Resources==<br />
<br />
[1] http://ubuntuforums.org/showthread.php?t=1039401<br />
<br />
[2] http://blog.nixpanic.net/2008/06/starting-safeboot-with-grub.html<br />
<br />
[3] http://mbrfde.blogspot.com/2008/11/dual-boot-ubuntu-with-safeboot-fde_19.html<br />
<br />
* Tools<br />
** [http://www.partitionwizard.com/ MiniTool Partition Wizard Home Edition]<br />
** [http://www.auslogics.com/en/software/disk-defrag/ Auslogic Disk Defragmenter]<br />
** [http://neosmart.net/dl.php?id=1 NeoSmart EasyBCD]</div>Sachiru