Using the GPT Linux Filesystem Data Type Code

by Rod Smith, rodsmith@rodsbooks.com

Web page created: 2/19/2012; last update: 10/6/2012

I'm a technical writer and consultant specializing in Linux technologies. This Web page is provided free of charge and with no annoying outside ads; however, I did take time to prepare it, and Web hosting does cost money. If you find this Web page useful, please consider making a small donation to help keep this site up and running. Thanks!

Donate $1.00 Donate $2.50 Donate $5.00 Donate $10.00 Donate another amount
Donate with PayPal

A relatively new (June, 2011) partition type code for Linux-native filesystems on GUID Partition Table (GPT) disks holds the promise to reduce the risk of problems on dual-boot Linux/Windows systems. Unfortunately, this type code has not yet (as of October of 2012) been widely adopted by most partitioning software, although it's now "in the pipeline" and so should become used by default on most Linux distributions within a few months. In the meantime, many systems, particularly those that dual-boot Windows and Linux on Unified Extensible Firmware Interface (UEFI) computers, are vulnerable to accidental destruction of their Linux installations from Windows. The solution is simple, and this page describes how to implement the solution even if your distribution hasn't yet adopted it.

What's the Problem?

Disk partition tables include type codes, which are coded names or numbers associated with specific uses of partitions. OSes can use the type codes as they see fit. For the most part, Linux ignores partition type codes, but Windows doesn't—it uses partition type codes as a filter to determine which partitions to attempt to use. Specifically, the Microsoft Basic Data type code (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) identifies a filesystem that Windows can understand, such as FAT or NTFS. Unfortunately, for years Linux has used this same type code to identify its filesystem partitions on GPT disks; however, Windows can't read Linux filesystems without extra drivers. This means that Windows shows Linux filesystem partitions as unformatted disks in its file manager, and if you attempt to access one, Windows asks you if you want to format it, as shown below. This makes it far too easy to accidentally trash your Linux installation from Windows if you place Linux filesystem partitions on a GPT disk. This problem does not affect the older Master Boot Record (MBR) partitioning system, which is the most common partitioning system on pre-2011 computers. Thus, on older Linux/Windows dual-boot systems, Windows won't show the Linux partitions in its file manager. Also, this problem does not apply to Linux swap, LVM, or RAID partitions, even on GPT disks; it only affects Linux filesystem partitions that are given the Microsoft Basic Data partition type code on GPT disks.


Windows lets you trash Linux on GPT disks when you use the Microsoft Basic Data partition type code.

When I first wrote the GPT fdisk (gdisk, cgdisk, and sgdisk) partitioning software, I felt that having Linux share the same filesystem type code as Windows was awkward at best and risky at worst, but I went along with it because I didn't want to deviate from accepted practice. As time went on, though, I began to see problem reports in online forums, and with the explosion of computers that use the UEFI firmware (which in turn uses GPT) in 2011, it became clear to me that something would have to be done. Thus, I modified both GPT fdisk and the other major Linux partitioning software with GPT support, libparted, to use a new Linux-specific type code for Linux filesystem partitions. I called the new filesystem type Linux Filesystem Data, and it has a GUID code of 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (although you may never need to know or use that GUID value directly). I posted to the bug-parted mailing list about the problem, and the ensuing discussions resulted in some further improvements to my libparted patch. This took place in late June of 2011.

GPT fdisk has included support for the new type code since version 0.7.2 (released in June of 2011), and a few other tools, such as busybox, also support the new type code. It took over a year, but in late September of 2012, the libparted "powers that be" have finally accepted my patch, and it should be included in libparted 3.2, which is due out in October of 2012. To use the new code, you have three choices: You can use GPT fdisk to change the type code on your partitions, you can patch a pre-3.2 version of libparted to support the new code, or you can use libparted 3.2. If you have a Linux-only installation, there's no real need to adjust your partition type codes, since the Linux kernel and most other Linux tools ignore partition type codes.

Using GPT fdisk

If you have an existing dual-boot installation and you want the Linux partitions to disappear from the Windows file browser, the easiest way to accomplish this goal is to use GPT fdisk, version 0.7.2 or later. You can use the t command in the gdisk utility to do the job. Change the type code from 0x0700 to 0x8300:

# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.2

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 625142448 sectors, 298.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B58D5E92-7BFB-4488-94B9-2F1BCFDD86DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 625142414
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          514047   250.0 MiB   EF00  EFI System
   2          514048          923647   200.0 MiB   0700  Spare /boot
   3          923648       625142414   297.7 GiB   8E00  Linux LVM

This example shows a GPT disk (as evidenced by the GPT: present line) with a Linux filesystem (Spare /boot) that has a 0x0700 type code—GPT fdisk's way of identifying a Microsoft Basic Data partition. (Since GPT fdisk doesn't scan partitions' contents to identify the filesystem, you'll have to know enough about your disk to know which partitions are actually Linux filesystem partitions.) This disk also has an EFI System Partition (ESP) and a Linux LVM partition. To change the type code of the Linux partition, use the t command to set a code of 0x8300 (GPT fdisk's internal code for the Linux Filesystem Data type):

Command (? for help): t
Partition number (1-3): 2
Current type is 'Microsoft basic data'
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'

To be sure everything is OK, you can view the partition table again, and then save your changes:

Command (? for help): p
Disk /dev/sdb: 625142448 sectors, 298.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B58D5E92-7BFB-4488-94B9-2F1BCFDD86DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 625142414
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          514047   250.0 MiB   EF00  EFI System
   2          514048          923647   200.0 MiB   8300  Spare /boot
   3          923648       625142414   297.7 GiB   8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

After making this change, the Linux partition(s) whose codes you change will disappear from the Windows file manager. If you need more help in using GPT fdisk (including the cgdisk and sgdisk variants), consult the main GPT fdisk Web page.

Patching libparted/GNU Parted

If you're using a pre-3.2 version of libparted and don't want to or can't upgrade it, you may be able to patch the source code or install a patched binary version of libparted. This will enable you to create partitions with the new type code from the start, rather than fix them after the fact. I'm releasing my patch on this page for individual users or for distributions that want to ship a pre-3.2 version of libparted with support for the new type code. You can download the patch in several ways:

Note that my patch was created against parted 3.0, but parted 3.1 was released in March of 2012 (after I wrote the initial version of this page). I don't guarantee that the patch will work against other versions of parted, but it might. I haven't updated the pre-patched versions of the program for parted 3.1; instead, I recommend you wait for parted 3.2 to be released.

Because of the huge number of distributions, I can't make binaries available for all of them. You might be able to get a binary RPM working on a Debian-based system with the help of alien, but I make no promises. If you can't get one of the binary RPMs to install on your system, you may need to compile the source code locally. Also, if your distribution uses a version of parted other than 3.0, switching to my patched parted 3.0 may cause problems or be disallowed by your package manager.

If you need help compiling and installing the program from source code, consult the INSTALL file in the main directory of the source code tarball, or do a Web search for generic instructions on compiling and installing source code.

Using libparted

GNU Parted doesn't give you direct control over partition type codes. Instead, they're set according to the filesystem type you specify. In parted, when you create a new partition and tell it to use a Linux filesystem type (ext2, ext3, ext4, ReiserFS, etc.), the new Linux Filesystem Data type code will be automatically applied. If you create a FAT or NTFS partition, the Microsoft Basic Data type code will be applied. Type codes for Mac OS's HFS+, Linux swap, and other partition types are set in similar ways.

If you run the patched GNU Parted on a disk you've prepared with an unpatched version of libparted or on a disk that contains true FAT or NTFS filesystems, you'll see the partitions that use the Microsoft Basic Data type code marked with a new flag, msftdata:

# parted /dev/sdb
GNU Parted 3.0
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print  
Model: ATA MAXTOR STM332062 (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name         Flags
 1      1049kB  263MB  262MB  fat32        EFI System   boot, hidden
 2      263MB   473MB  210MB  ext2         Spare /boot  msftdata
 3      473MB   320GB  320GB               Linux LVM    lvm

This example shows a disk with a Linux ext2 filesystem incorrectly marked with the Microsoft Basic Data (msftdata) type code. You can remove the flag using the GNU Parted toggle command:

(parted) toggle 2 msftdata  

Note, however, that you cannot toggle this flag off on FAT or NTFS partitions; you can only do so on partitions that hold other filesystem types. (If you try to toggle the msftdata flag off on a FAT or NTFS partition, the command will silently fail.) To verify that the change has been made, type print; the msftdata flag should be gone. You can then quit (parted makes its changes as you type commands, unlike gdisk, which holds them until you explicitly write them with w).

(parted) print
Model: ATA MAXTOR STM332062 (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name         Flags
 1      1049kB  263MB  262MB  fat32        EFI System   boot, hidden
 2      263MB   473MB  210MB  ext2         Spare /boot
 3      473MB   320GB  320GB               Linux LVM    lvm

(parted) quit

If you install a patched libparted on a system that also runs libparted-based programs, such as GParted, they should automatically take advantage of the new functionality. For instance, GParted shows the new flag when the Microsoft Basic Data type code is set:


libparted-based programs should automatically use the new type codes.

Note that GParted shows the msftdata flag as being set on /dev/sda3 in the figure, and the "Manage Flags" feature enables you to unset it. Also, note that GParted must use the version of libparted provided by the patched parted package you install; if it uses another version of the library, GParted will continue to apply the Microsoft Basic Data type code to Linux partitions.

Conclusion

If you're using a version of libparted that lacks support for the Linux Basic Data partition type code, I recommend that you install a patched or upgraded version that includes this support. Without it, the risk of Linux partitions being accidentally trashed in Windows is unacceptably high. In absolute terms, this risk will only increase as more UEFI-booting systems become available. With any luck, now that the support is being added to libparted 3.2, it should begin to migrate down to distributions and be used by default.


copyright © 2012 by Roderick W. Smith

If you have problems with or comments about this Web page, please e-mail me at rodsmith@rodsbooks.com. Thanks.

Return to my main Web page.