About Me

My photo
I know the last digit of PI

Friday, August 14, 2015

Updating to Windows 10 when having GRUB 2 bootloader installed in MBR.



Usually when having dualboot of Windows and Linux the GRUB 2 bootloader is installed in MBR. When trying to update to Windows 10 it fails with the following error "We Can't Tell if your PC has enough space to continue".
Well the solution for updating to Windows 10 is simple - restore the hardisk Master Boot Record (MBR) using Windows installation disc (it can be also created via Microsoft's MediaCreationTool - the same tool used for updating to Windows 10. Just on the first screen choose not to update, but "Create installation media for another PC" and write it to DVD/USB).
Boot from the Windows installation DVD/USB and follow instruction until screen that allows you to install windows or "Repair your computer". Choose to "Repair your computer" / "Troubleshoot" / "Advanced options" / "Command prompt"
Execute following command:
bootrec.exe /fixmbr
Reboot and start the update process again. Now the update should be successful.
Now Windows boots successfully but Linux is no longer accessible. One way to make Linux bootable again is to use Windows bootloader to load Linux. I prefer this method because I don't want to face any future problems with windows updates.
We need a copy of the GRUB2 exported as file. For that reason we will install GRUB on Partition Boot Record (PBR) and copy the boot sector to file. First we must access the installed Linux partitions. Create a "Live CD" on DVD/USB and boot from it. The from the shell mount your existing linux installation. Let's assume that /dev/sda3 is the linux boot partition, /dev/sda4 is the root partition. Now mount the volumes:
mount /dev/sda4 /mnt
mount /dev/sda3 /mnt/boot
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
Optionally you may mount home directory
mount /dev/sdaX /mnt/home

Now do chroot:
chroot /mnt
Reinstall grup 2 on boot partition
grub2-install /dev/sda3
You may receive following error:
"warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.
error: will not proceed with blocklists"
Then just use --force
grub2-install --force /dev/sda3
Once the installation complets create a dump of the bootsector:
dd if=/dev/sda3 of=/tmp/linux.bootsector.bin bs=512 count=1
copy the /tmp/linux.bootsector.bin  to some partition accessible by Windows.
mkdir /mnt/c
mount /dev/sda2 /mnt/c
cp /tmp/linux.bootsector.bin /mnt/c
umount /mnt/c
Now reboot and start Windows and we need to create a new BCD entry for Linux
Open administrative command prompt (right click on "command prompt" and choose run as administrator)
bcdedit /create /d “Linux” /application BOOTSECTOR
The command will return GUID e.g. {5474794d-1fe8-4008-a0ae-d10210214f2a}
That GUID will be use in next commands.
Configure new BCD entry's partition and path to the location where linux.bootsector.bin is copied
bcdedit /set {5474794d-1fe8-4008-a0ae-d10210214f2a} device partition=C: 
bcdedit /set {5474794d-1fe8-4008-a0ae-d10210214f2a}  PATH \linux.bootsector.bin
Then configure the new entry to be shown last, and the OS selection menu timeout to be 5 seconds.
bcdedit /displayorder {5474794d-1fe8-4008-a0ae-d10210214f2a}  /addlast
bcdedit /timeout 5
Reboot and now you will be able to boot either Windows or Linux.

Tuesday, August 04, 2015

Windows 10/8/7/Vista administrative shares are not accessible (from linux / windows)

The information is based on Access Denied Trying to Connect to Administrative Shares C$, D$ etc.

Typical error is :

mount -t cifs -o username=superman,password=secret //192.168.22.14/c$ /mnt/c
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
The reason is that described in KB951916 Microsoft introduced as part of UAC a little known feature called “UAC remote restrictions”. It filters the access token for connections made with local user accounts or Microsoft accounts (the latter typically have the format MicrosoftAccount\EMailAddress). In other words it removes the SID for “Administrators”. Connections made with domain accounts remain unchanged. From KB951016:
If the user wants to administer the workstation with a Security Account Manager (SAM) account, the user must interactively log on to the computer that is to be administered with Remote Assistance or Remote Desktop, if these services are available.
UAC remote restrictions can be disabled by setting the DWORD registry value LocalAccountTokenFilterPolicy to 1:
Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Value: LocalAccountTokenFilterPolicy
Data: 1 (to disable, 0 enables filtering)
Type: REG_DWORD (32-bit)
Reboot is not required on Windows 8/10