22

September
2012

NTFS support

Syslinux bootloader supports NTFS since version 4.06-pre11. Thanks to that, user can install Slax to a NTFS volume in Windows as like he would normally do on FAT. However Slax itself wouldn't be able to write to such boot device, so I've managed to compile ntfs-3g statically and include it in initramfs.

The cleanup script had to be modified though, so it actually doesn't kill the ntfs-3g mounter process during system shutdown.

User comments
Manfred 2012-09-23 01:12

Hi Tomas,

imho it is pretty dangerous to support installation to NTFS with Slax.

As long as you don't prevent users from installing Slax to a
partition on which ntldr, netdetect.com or boot.ini exist,
there will be a lot of postings like "OMG, I've killed my Windows bootloader!".

Just my 2 cents,

Manfred

Tomas M 2012-09-23 02:40

It is pretty dangerous to let people use knifes. They could kill each other. Actually, it's THEIR PROBLEM. :)

But I realize you are very correct, thank you very much for the suggestion. There could be some check and Slax could probably refuse to install on drives with 'Program files' directory or something like that (to autodetect windows). Or probably skip drive C:.

Yet still it may be problematic to detect situations where user has one drive, two partitions (C: and D:) and wants to install Slax on D: - this way I do not know how to detect that the D: drive shares the same MBR with C: drive. Any idea? Perhaps if we could determine drive serial number for C: and D: and find out if they are the same...

Manfred 2012-09-23 04:30

>> Any idea?

Imho you should check for two conditions:

1.

Is the partition Slax is to be installed on formatted with NTFS filesystem AND is it marked as active partition?
(checking for the 'Program Files' folder isn't reliable
as this folder could be on a separate partition)

2.

Is the partition Slax is to be installed on marked active
AND does it contain ntldr ntdetect.com and boot.ini?

Windows only starts from an active partition which holds these files in addition.

If both conditions are met you have found the partition with
the Windows mbr.

Due to my work experience check 2 is the more reliable one.

Be prepared that you will never be able to install Slax into
a Windows7/8 system reliably without using Windows's bcedit bootloader editor...

You may want to 'examine' InA's sourcecode at hxxp://sourceforge.net/projects/ina/files/Sources/
to get an overview of Windows bootloader handling ;)

Manfred

Manfred 2012-09-23 04:35

... the last but one sentence must read:

...you will never be able to install Slax into
a Windows Vista/7 system reliably...

dimitrij 2012-09-23 08:13

A wise man once said:

If you want to install SLAX to HD, use Slackware!

This option should not be exposed to everyone, until fool-proofed. Power should be earned by knowledge.

Manfred 2012-09-23 10:34

>> If you want to install SLAX to HD, use Slackware!

This refers to install Slax as a 'real' system whereas Tomas and me are talking of live mode...

Manfred

aitap 2012-09-23 23:13

Checking for system partition can be done using %SystemDrive% environment variable.

As for detecting system drive, it looks like a more complicated task. An example of solving it is using diskpart in the script:

echo select volume %SelectedLetter% > %TEMP%/diskpart.txt
echo detail disk >>%TEMP%/diskpart.txt
diskpart /s %TEMP%/diskpart.txt | findstr /R System$
If %ERRORLEVEL% EQU 0 (
ECHO The %SelectedLetter% partition lies on the system drive, refusing to continue
GOTO END
)

The bad thing about this script is that diskpart messages can be localized (for example, "Системный" instead of "System"). Perhaps it should be easier using some WINAPI (GetLogicalDrives + GetDrive???).

Manfred 2012-09-24 00:05

@aitap:

Could you please teach me and others how to use the
Windows variable %SystemDrive% and the Windows tool
diskpart in a Linux environment? ROFL

Manfred

aitap 2012-09-24 00:23

@Manfred:
Actually, the %SystemDrive% variable is present under WINE, but it doesn't make much sense.

As long as bootinst.bat is present in Slax, there should be a way to detect the system drive under Windows.

Under Linux everything is easier as we have blkid, fdisk, parted, file, mount, sed, grep and awk and many other tools which all can be used to determine the device from which the system boots. Or maybe everything is more complicated because there is no -m option for syslinux under Linux, and there is no reliable way of determining system boot drive (for example, what if user boots from an SD card containing crypted /boot?)

// :)

Tomas M 2012-09-24 01:24

@aitap:
very good idea, this works! however only for English systems. Could we possibly force the windows console to output text in english?

Tomas M 2012-09-24 01:26

I found 'chcp' command, and some post which explains that using 'chcp 437' will make the console output in English. However I found some other claim that this doesn't work well. I can't try since my windows is EN. Could you please try if you have international windowses? Thank you

aitap 2012-09-24 02:30

I can confirm that 'chcp 437' makes diskpart output English text, at least on Windows 7 Starter with ru-RU localization.

Manfred 2012-09-24 02:58

@Tomas:

chcp 437 doesn't work on my German Windows XP.

Manfred

Tomas M 2012-09-24 03:30

That's exactly what I learned during my research, it works for someone and doesn't for others :)

Manfred 2012-09-24 06:23

remembering some lessons I gave years ago, this is working:

@echo OFF

setlocal ENABLEEXTENSIONS
set KEY1_NAME="HKLM\Software\Microsoft\Windows\CurrentVersion\Setup"
set VALUE1_NAME=BootDir
set KEY2_NAME="HKLM\Software\Microsoft\Windows NT\CurrentVersion"
set VALUE2_NAME=SystemRoot

FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY1_NAME% /v %VALUE1_NAME% 2^>nul`) DO (
set Value1Value=%%C
)

FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY2_NAME% /v %VALUE2_NAME% 2^>nul`) DO (
set Value2Value=%%C
)

@echo System booted from %Value1Value% and installed in %Value2Value%.

Manfred

Manfred 2012-09-24 06:45

with a space between /v and %VALUE it is one line from
"FOR /F.." to "..) DO ("

Tomas M 2012-09-24 07:32

Thank you Manfred. That unfortunately doesn't work on my Windows 7, it echoes System booted from and installed in .

However I found a short VBS script which I was able to tweak a bit so it now returns errorcode 99 if passed arguments (paths) are on the same physical drive. Works on XP and Win7. I'll need to test it on more machines, though.

Manfred 2012-09-24 08:35

>> ...it echoes System booted from and installed in

Thats bad luck - it was tested on XP and below only.

Keep in mind that for running VBS scripts which touch
system settings you might run into problems with
UAC (User Access Control).

You definitely need to test it on systems with UAC turned on.

Tomas M 2012-09-24 09:58

Thank you for the suggestion, I turned UAC on and noticed that even syslinux can't install itself to the MBR of USB drive if it has no privileges. So I've implemented UAC privilege escalation to the bootinst.bat script.