5

I used to create two partitions on pendrives that would be used either on Windows or GNU/Linux.

The first partition I'd format with ntfs, the second one with ext4. This way Windows would not see the second partition and would not ask to format when plugged in.

Since one of the last updates to Windows 10, this trick does not work anymore.

These pendrives I'm talking about are given to teachers at schools that use random GNU/Linux distributions but at home use Windows 10. When they get back to the school from home they realize that the ext4 partition is gone, as they just clicked 'yes' when Windows asked to format the partition.

I have tried to hide the second partition with parted, but I don't find the right switch.

What should I do in order to hide/protect the ext4 partition on the pendrive from Windows 10?

sudodus
  • 46,324
  • 5
  • 88
  • 152
Joe
  • 93
  • It seems Microsoft is really trying hard to make it difficult for linux. Is it important that the second partition has ext4 (or some other linux file system)? Do you need to preserve links or permissions? Maybe it would work withUDF? You can try according to this link, http://tanguy.ortolo.eu/blog/article93/usb-udf -- an alternative would be to use USB drive with a mechanical switch (microswitch) to make it read-only. – sudodus Sep 26 '17 at 08:39
  • 2
    This is a windows question and windows problem. Please use http://superuser.com/ And I bet if you are admin on windows 10 you are always allowed to format USB. And thus will always get it prompted. Answer is likely to add ext4 support to windows. – Rinzwind Sep 26 '17 at 08:57
  • 3
    @Rinzwind, It seems to me that the problem is that Windows has changed from ignoring linux partitions to prompting the user the format them. This has happened in my son's Windows 10 too. The problem is how to protect linux file systems. – sudodus Sep 26 '17 at 09:00
  • They started using a different method for adding drive letters it seems. Nothing we can do about that. This needs to be fixed or taken care of on Windows – Rinzwind Sep 26 '17 at 09:05
  • UDF is accepted by Windows (no prompting to format), and it is possible to modify and store linux style permissions. I was testing it a couple of minutes ago. – sudodus Sep 26 '17 at 09:08
  • If you must have ext4, you can put it in a file and loop mount to use it from linux. I don't think that Windows will bother to look in the file. The content will be available via the mount point, for example /mnt/lp1, which means that you and an end user can read and write files and directories, just like an ext4 file system in a partition. But Windows does not prompt the user the format it. -- This is described as item 2 at the end of my answer. – sudodus Sep 26 '17 at 18:01

2 Answers2

5

1. UDF can replace ext4 to protect a partition with linux style

  • The problem is that Windows 10 has changed from ignoring a second partition with the linux ext4 file system to prompting the user the format it.
  • Windows 10 does not prompt the user to format UDF, the Universal Disk Format.

UDF is described in the following links,

UDF provides a workaround that helps protect a partition with linux style

  • links and
  • individual permissions for files and directories.

It is even possible to use UDF in the casper-rw partition of a persistent live drive, illustrated by the following screenshot of Lubuntu 16.04.1 LTS,

enter image description here

Commands

  • Install udftools if necessary

    sudo apt-get install udftools
    
  • Create a partition table with gparted or gnome-disks

  • Erase confusing data with dd (risky!)

    sudo dd if=/dev/zero of=/dev/sdxn bs=1M count=1  # wipe first MiB
    

    where x is the drive letter and n is the partition number. Check and double check that everything is correct before you press the Enter key to run the dd command line!

  • Create UDF file system (risky!)

    sudo mkudffs -b 512 --media-type=hd --lvid=my-label /dev/sdxn
    

    where x is the drive letter and n is the partition number. Check and double check that everything is correct before you press the Enter key!

Backup

But it might be difficult to find good tools to repair UDF. Maybe Windows can fix some errors. So it is important to backup the content regularly, so that the content is not lost, if the file system gets damaged.


2. ext4in a file and loop mount to use it

If you must have ext4, you can put it in a file and loop mount to use it from linux. I don't think that Windows will bother to look in the file.

This method is the same as for a casper-rw file for persistence.

Example:

  • Create mount points (only once)

    sudo mkdir -p /mnt/lp1
    sudo mkdir -p /mnt/sd1
    
  • Mount the partition, where you intend to create the file.

    sudo mount /dev/sdxn /mnt/sd1
    

    where x is the drive letter and n is the partition number.

  • Create a file. In the FAT32 file system the maximum file size 4 GB, but in NTFS and UDF, the size is limited by the size of the partition.

    The following command line will make an empty file with the size (bs * count, in this case 1MiB*8KiB) = 8GiB.

    sudo dd if=/dev/zero of=/mnt/sd1/linux-fs bs=1M count=8K
    
  • Create an ext4 file system in the file

    sudo mkfs.ext4 /mnt/sd1/linux-fs
    
  • In order to use the file in linux, loop mount it (you can provide a script or desktop file for the end users),

    sudo mount -o loop /mnt/sd1/linux-fs /mnt/lp1
    

    or maybe you would prefer something like this,

    sudo mount -o defaults,users,loop /mnt/sd1/linux-fs /mnt/lp1
    
  • I assume that you already create a structure of directories, ownerships and permissions in the ext4 partition, and the same structure should work in this ext4 file too.

The content will be available via the mount point /mnt/lp1, which means that you and an end user can read and write files and directories, just like an ext4 file system in a partition. But Windows does not prompt the user the format it.

sudodus
  • 46,324
  • 5
  • 88
  • 152
  • My UDF flash drive seems to work in Windows10 but has not been visible in Ubuntu since was first created? Do I need to loop mount the partition to see it? – C.S.Cameron Sep 26 '17 at 19:30
  • A partition with UDF should be visible in Ubuntu after visiting Windows. You mount it like you mount any partition with sudo mount <device> <mountpoint>, but I'm checking now with my persistent live drive, and it auto-mounts the UDF partition with the label 'casper-rw'; 2. A file system that is inside a file should be loop mounted. I don't think it will auto-mount (unless as part of booting a persistent live system) ; Summary: In both cases, Windows did not prompt to format any of them or destroy them. Linux can see and use them, my test files and directories were there and available.
  • – sudodus Sep 26 '17 at 19:55
  • 1
    Creating the partition in Linux would not automount it when plugging in the device, so I opted to format it in Windwos with "format : /fs:UDF /q" which automounted automaticcaly in Manjaro and Ubuntu.

    Symlinks and permissions are preserved just fine. Anyone interested please note that Windows XP has no UDF support. Thanks a lot!

    – Joe Oct 03 '17 at 11:21
  • @Joe, You found a good solution, and I'm glad I could help you along the way :-) – sudodus Oct 03 '17 at 11:56
  • Now I have a new problem, since files that I hide under windows no longer show up in linux, not even "ls -a", I could probably remount the usb drive with the unhide option, but this is not something I would be able to tell any of the teachers I hand out these usb drives... – Joe Oct 08 '17 at 17:19
  • @Joe, Why and how are you hiding files under Windows? And are you talking about files in UDF? Are there still two file systems - NTFS and UDF, or have you skipped NTFS? – sudodus Oct 08 '17 at 18:05
  • Yes, the files are in the UDF partition. Hidden files in a NTFS partition show up just fine in the file browser. The reason for hiding some of the folders is to prevent confusion. The teachers are supposed to click on a html file that will show all the content, not clicking through the folders to find any of the resources. Anyone interested, the correct command do mount a UDF USB drive and enable the system to see hidden files is – Joe Nov 13 '17 at 10:39
  • sudo mount -t udf -o remount,rw,unhide /dev/sdb /[mountpoint] – Joe Nov 13 '17 at 10:46
  • Thanks for sharing your solution to show hidden files :-) – sudodus Nov 13 '17 at 11:06