LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Formatting a USB partition for use with Windows (https://www.linuxquestions.org/questions/linux-hardware-18/formatting-a-usb-partition-for-use-with-windows-404825/)

conn-fused 01-18-2006 03:45 AM

Formatting a USB partition for use with Windows
 
I have an LG 512MB USB key, divided into three partitions. The first two are ext2 and have a bootable installation of Debian. The third is an msdos partition. I was hoping that I could use this partition to carry files for those times when I'm forced to work with Windows machines at work.

Unfortunately, Windows claims the whole disk is unformatted. It offers me a chance to format it but I decline. We all know how clumsy Windows is ... not understanding ext2, it'd probably erase the first two partitions too.

So my question is this: How can I use Linux or Windows to make the third partition (and only the third partition) on my USB key readable on a Windows machine?

Thanks!

yoron 01-18-2006 04:15 AM

do a partition from XP (unformat your usb first)
Use Fat32.
Then do the rest unformated partition/s from linux.
and mount your Fat32 partition.
I think that would work...

pingu 01-18-2006 04:49 AM

I agree with yoron.
Just a few notes YI:
There are two things that might cause problems:
1) From fdisk's manpage:
Code:

if you use cfdisk or fdisk to change the size of a DOS partition table entry,
then you must also use dd to zero the first 512 bytes of that partition before
using DOS FORMAT to format the partition

I have found this to be necessary with all Windows-partitions, not only DOS6.
2) Windows wants C:\ to be the very first partition . sometimes it works having C:\ as second-or-later, but my advice is to avoid it.
Linux is completely unsensitive as to where partitions are placed (only /boot might have to be primary, and/or before cyl 1024.)

conn-fused 01-18-2006 11:21 AM

Thanks guys, these are helpful posts, but is there any way I can format the third partition as FAT32 without loosing the data on the first two partitions?

If there isn't, could I get some advice on using dd with the usb to make images of these two partitions so I can restore them?

Please keep in mind, if you think I should use the dd route, that the first partition I want to preserve is a /boot partition, and so should probably go at the start of the usb key. Can I actually format the key to FAT32 and then change the start point of the partition? I was under the (possibly false) impression that only the end points of partitions could be altered, but then I am pretty new to working with partitions like this.

conn-fused 01-18-2006 11:25 AM

One more thought. What about vfat? Can Windows understand that? Then maybe a simple "mkfs.vfat /dev/sda3" will solve my problems.

michaelk 01-18-2006 06:11 PM

How were the partitions created and formated?
What did you use to format the msdos partition?
What is the partition ID type for your msdos partition?
Post the output of the command
fdisk -l /dev/sda (that is a small L and you must be root, change sda for the actual device ID if different)

conn-fused 01-19-2006 08:34 AM

OK, here's what I did:

parted /dev/sda "mklabel msdos mkpart primary 0 14 mkpart primary 15 383 mkpart primary 384 -0"
shred -n 1 -v /dev/sdd2
cryptsetup -y create rootfs /dev/sdd2
mkfs.ext2 /dev/mapper/rootfs
mkfs.ext2 /dev/sda2
sync ; sync
mkfs.msdos /dev/sda3

That's only the slightest of variations on the instructions in the following article here (in case anyone else is interested):
http://www.debian-administration.org/articles/179

I think that answers your first question.

As to your second, I did nothing after "mkfs.msdos /dev/sda3". I was under the impression that making the filesystem formatted the partition. Apparently it does not. But in that case, why can I read my ext2 partitions after "mkfs.ext2 /dev/whatever"?

Third: looks like 83 to me ... which is not what I'd have expected. See for yourself in the fdisk output you requested (below):

Disk /dev/sda: 519 MB, 519700480 bytes
255 heads, 63 sectors/track, 63 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 2 16033+ 83 Linux
/dev/sda2 3 49 377527+ 83 Linux
/dev/sda3 50 63 112455 83 Linux

michaelk 01-19-2006 09:03 AM

The mkfs utility does format the filesystem.
Windows does not recognize sda3 because the partition ID type is non DOS i.e. 83 instead of 06 or 0xb. Formating does not modify the ID type.

Use cfdisk or fdisk etc to change the ID type. This will not effect existing data.

conn-fused 01-20-2006 05:09 AM

Thanks michaelk ... I should have remembered to change the ID.

BTW, I've decided to go with vfat instead of msdos (for long filename support). I presume only 0xB (Win95 Fat32) will do for that, but if I'm wrong please post a correction in case anyone else decides that want to follow the procedure we've laid out here.

blimbo 01-20-2006 07:46 AM

Have you tried qtparted? I *think* this can format partitions as fat32..

Matir 01-20-2006 11:02 AM

0x0B should work for vfat (aka fat16). If you really want fat32, you'd need to specifically add '-F 32' to the mkfs.vfat options.

conn-fused 01-20-2006 11:26 AM

Matir: OK, I've tried "mkfs.vfat" and "mkfs.vfat -F 32" with the partition ID set to "b" (0x0b) and tested both combinations on a laptop running XP. In both cases, it insists that the USB key is not formated. I also tried "mkfs.vfat" with partition ID "6" (0x06), to no avail.

Is it possible that XP can't deal with a USB key that has a non-FAT32 partition before a FAT32 one at all? Does anyone else have an empty USB key, an XP and a Linux they can test this with? (ie maybe it's just my key?)

Blimbo: No, I haven't run across qtparted before; thanks for the tip. I'll track down a copy and put my results into this post.

Matir 01-20-2006 11:28 AM

Well, if you haven't found anything, I can test it when I get home this evening. I've done mixed fat/non-fat USB drives before, but the fat partition has always been first.

michaelk 01-20-2006 12:42 PM

Does XP recognize sda3 as a DOS partition with an ID type of 0xb? If so then use XP to format it as FAT32.

Matir 01-20-2006 07:50 PM

Seeing that there has been nothing conclusive so far, I am going to test some different arrangements using a cheap 256MB jumpdrive I have here.

In an effort to make this well-documented, I invite commentary as I perform the tests.

I will be partitioning and formatting the jumpdrive with standard linux tools, whose versions I will list below. I will test the drive using Windows XP Professional SP2. I will test the following arrangements (p1=partition 1, etc.):
  • p1: ext2, type 0x83 p2: fat16, type 0x83 (OP Configuration)
  • p1: ext2, type 0x83 p2: fat16, type 0x0B (Revised Config)
  • p1: fat16, type 0x0B p2: ext2, type 0x83 (Likely to Work)
  • p1: fat16, type 0x83 p2: ext2, type 0x83 (Test if partition type matters)

If anyone else has any other thoughts on what I can test, let me know. I think this will prove interesting. :)

Software versions:
Code:

$ mkfs.vfat
mkfs.vfat 2.11 (12 Mar 2005)
No device specified!
Usage: mkdosfs [-A] [-c] [-C] [-v] [-I] [-l bad-block-file] [-b backup-boot-sector]
      [-m boot-msg-file] [-n volume-name] [-i volume-id]
      [-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs]
      [-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors]
      /dev/name [blocks]
$ mkfs.ext2 -V
mke2fs 1.38 (30-Jun-2005)
        Using EXT2FS Library version 1.38
$ cfdisk -v
cfdisk 2.12r
Copyright (C) 1994-2002 Kevin E. Martin & aeb



All times are GMT -5. The time now is 03:58 AM.