Create Partition For Ext3 Filesystem For Usb Mac

Learn Linux, 101

Divide and conquer your disk space

Ext3 - The ext3 file system is based on the ext2 file system and has one main advantage - journaling. Using a journaling file system reduces time spent recovering a file system after a crash as there is no need to check the file system for metadata consistency by running the fsck utility every time a crash occurs. Format USB drive for both Mac and PC use. I bet some of you have this dilemma: you have a USB drive and want to use it on both Mac and PC. If you format the USB drive to HFS+ File System, it will not be supported by Windows computer. And if you format it to NTFS, it will not be fully supported in Mac Operating System.

Content series:

This content is part # of # in the series: Learn Linux, 101

https://www.ibm.com/developerworks/library/?series_title_by=learn+linux,+101

This content is part of the series:Learn Linux, 101

Stay tuned for additional content in this series.

Overview

In this article, learn about disk partitions and Linux filesystems. Learn to:

  • Create a partition
  • Use mkfs commands to set up ext2, ext3, ext4, xfs, Reiser v3,and vfat filesystems
  • Create and manage swap space

This article helps you prepare for Objective 104.1 in Topic 104 of the Linux Professional Institute's Junior Level Administration (LPIC-1) exam 101. The objective has a weight of 2.

Note: This article includes material for the LPI Exam 101: Objective Changes as of July 2, 2012. We have added basic information on ext4 filesystems. We have also added some basic information on the gdisk command and the GUID Partition Table (GPT). The new code listings and figures were all done on a 64-bit Fedora 17 system.

Create

Prerequisites

To get the most from the articles in this series, you should have a basic knowledge of Linux and a working Linux system on which you can practice the commands covered in this article. Sometimes different versions of a program will format output differently, so your results may not always look exactly like the listings and figures shown here.

You should also be familiar with the material in our article, 'Learn Linux 101: Hard disk layout.'

Block devices and partitions

Our article, 'Learn Linux 101: Learn Linux, 101: Hard disk layout,' introduced you to hard drive layouts, partitions, and some basic use of the fdisk and gdisk commands to view partition information. You learned about the Master Boot Record (MBR), partition tables, partitions, including primary, extended, and logical partitions. You were also introduced to GUID Partition Tables (GPT), a new format used to address the size limitations inherent in the MBR layout. Finally, you learned that a Linux filesystem contains files that are arranged on a disk or other block storage device in directories. As with many other systems, directories on a Linux system may contain other directories called subdirectories. That article also discussed the considerations that guide you in making choices about partitioning.

Note: This article focuses on the LPI requirements related to the fdisk command and partitioning using MB layouts. It includes some gdisk command information in Creating an ext4 filesystem. Refer to the earlier article and its resources for more information on GPT.

We'll start this article with a review of block devices and partitions, and then show you more about the fdisk command, which is used to create, modify, or delete partitions on block devices. You will also learn about the various forms of the mkfs command (mkfs stands for make filesystem); mkfs commands are used to format partitions as a particular filesystem type.

Note: In addition to the tools and filesystems required for the LPI exams, you may encounter or need other tools and filesystems. Find a brief summary of some other available tools in Other tools and filesystems.

Block devices

A block device is an abstraction layer for any storage device that can be formatted in fixed-size blocks; individual blocks may be accessed independently of access to other blocks. Such access is often called random access.

The abstraction layer of randomly accessible fixed-size blocks allows programs to use these block devices without worrying about whether the underlying device is a hard drive, floppy, CD, solid-state drive, network drive, or some type of virtual device such as an in-memory file system.

Examples of block devices include the first IDE hard drive on your system (/dev/sda or /dev/hda) or the second SCSI, IDE, or USB drive (/dev/sdb). Use the ls -l command to display /dev entries. The first character on each output line is b for a block device, such as floppy, CD drive, IDE hard drive, or SCSI hard drive; and c for a character device, such as a or terminal (tty) or the null device. See the examples in .

Linux block and character devices

Partitions

For some block devices, such as floppy disks and CD or DVD discs, it is common to use the whole media as a single filesystem. However, with large hard drives, and even with USB memory keys, it is more common to divide, or partition, the available space into several different partitions.

Partitions can be different sizes, and different partitions may have different filesystems on them, so a single disk can be used for many purposes, including sharing it between multiple operating systems. For example, I use test systems with several different Linux distributions and sometimes a Windows® system, all sharing one or two hard drives.

You will recall from the article, 'Learn Linux 101: Learn Linux, 101: Hard disk layout,' that hard drives have a geometry, defined in terms of cylinders, heads, and sectors. Even though modern drives use logical block addressing (LBA), which renders geometry largely irrelevant, the fundamental allocation unit for partitioning purposes is usually still the cylinder.

Displaying partition information

Partition information is stored in a partition table on the disk. The table lists information about the start and end of each partition, information about its type, and whether it is marked bootable or not. To create and delete partitions, you edit the partition table using a program specially designed for the job. For the LPI exam, you need to know about the fdisk program, so that is what is covered here, although several other tools could be used. We will mention some at the end of this article.

The fdisk command with the -l option is used to list partitions. Add a device name, such as /dev/sda, if you want to look at the partitions on a particular drive. Note that partitioning tools require root access. shows the partitions on the primary hard drives of two of my systems.

Listing partitions with fdisk

Notes:

  1. The header information shows the disk size and geometry. Most large disks using LBA have 255 heads per cylinder and 63 sectors per track, making a total of 16065 sectors, or 8225280 bytes per cylinder.
  2. In the second example, the first primary partition (/dev/sda1) is marked bootable (or active). This enables the standard DOS PC master boot record to boot the partition. This flag has no significance for the LILO or GRUB boot loaders. The first example uses GRUB as the boot loader, and the fact that /dev/sda3 is marked bootable is probably an accident of the history of my use of this drive.
  3. The Start and End columns show the starting and ending cylinder for each partition. These must not overlap and should generally be contiguous, with no intervening space.
  4. The Blocks column shows the number of 1K (1024 byte) blocks in the partition. For most disks in use at the time of writing, the sector size is 512 bytes, so the maximum number of blocks in a partition is therefore half of the product of the number of cylinders (End + 1 - Start) and the number of sectors per cylinder. A trailing + sign indicates that not all sectors in the partition are used.
  5. The Id field indicates the intended use of the partition. Type 82 is a Linux swap partition, and type 83 is a Linux data partition. There are approximately 100 different partition types defined. The second disk is shared between several operating systems, including Windows/XP, hence the presence of Windows NTFS (and possibly FAT32) partitions.

Partitioning with fdisk

You have just seen how to display partition information using the fdisk command. This command also provides a menu-driven environment for editing the partition table to create or remove partitions.

Warnings

Before you start modifying partitions, there are some important things to remember. You risk losing your existing data if you do not follow these guidelines.

  1. Back up important data before you start, as with any operation that may cause data loss.
  2. Do not change partitions that are in use. Plan your actions and execute them carefully. Booting a live distribution from CD, DVD, or USB is one good way to ensure that no hard drive partitions are in use.
  3. Know your tool. The fdisk command does not commit any changes to your disk until you tell it to. Other tools, including parted, may commit changes as you go.
  4. Stop if you do make a mistake. Partitioning tools write the partition table. Unless the tool you are using also includes the ability to move, resize, format, or otherwise write to the data area of your disk, your data will not be touched. If you do make a mistake, stop as quickly as possible and seek help. You may still be able to restore your previous partition table definitions and thus recover your partitions and data.

Start fdisk

To start fdisk in interactive mode, simply give the name of a disk, such as /dev/hda or /dev/sdb, as a parameter. The following example boots a Knoppix live DVD. You will need root authority, and you will see output similar to .

Starting interactive fdisk

Most modern disks have more than 1024 cylinders, so you will usually see the warning shown in . Type m to display a list of available one-letter commands as shown in .

Help in fdisk

Use the p command to display the existing partition on this particular disk; shows the output.

Displaying the existing partition table

This particular disk is a 1TB disk with a Windows/XP partition of a little under 80GB. It is a primary partition, and it is marked bootable, as is typical for a Windows system.

Adding partitions

Let's now use part of the free space to add some partitions.

  1. We will create a swap partition as /dev/sda4. This will be a primary partition, filling the 521 cylinder gap between the end of /dev/sda1 and the start of /dev/sda2. Don't even begin to wonder what crazy things cause this gap to exist; I created the gap deliberately so I could write this article.
  2. We will create a 40GB logical partition as /dev/sda8.
  3. Finally, we will create a small 2000MB logical partition for sharing data between the Linux and Windows systems. This will eventually be formatted as FAT32 (or vfat). It will be /dev/sda9.

Creating our partitions

Let's start by using the n command to create a new partition; see .

Creating our first partition

We took the default for the first cylinder and specified the value of +521 for the number of cylinders. You can see from that our partition is approximately 4GB in size. Since it is a primary partition, it must be numbered from 1 through 4. It is a good idea to assign partition numbers sequentially; some tools complain if this is not done and fdisk warns us that our partition table entries are no longer in disk order.

Notice also that our new partition was assigned a type of 83, for a Linux data partition. Think of this as an indicator to the operating system of the intended use of the partition. The eventual use should match this, but at this point we don't even have the partition formatted, let alone have any data on it. We'll create out other partitions first, then look at how to change the partition type.

You may have noticed that when we entered the n subcommand to create a new partition, the only choices were 'l' for logical and 'p' for primary. You will only see options for the remaining possible types of partitions. You would see 'e' for extended if the drive did not already have an extended partition. Also note that our extended partition (/dev/sda3) is type 5.

Now let's define the 40GB Linux partition and the 2000MB FAT32 partition. This time we will simply specify sizes of +40G and +2000M, indicating 40GB and 2000MB, respectively. We let fdisk calculate the number of cylinders for us. The results are shown in .

Creating our data partitions

Changing partition type

Before we leave fdisk, we will change the partition types for the swap and vfat partitions. We do this using the t subcommand to set the partition type. We set /dev/sda4 to type 82 (Linux swap) and /dev/sda9 to type 9 (FAT32). If you want to see the full list of supported types, enter L as you see in .

Changing partition types

Saving our partition table

So far, we have just been doing an in-memory edit of a partition table. We could use the q command to quit without saving changes. If something is not how you want it, you can use the d command to delete one or more partitions so you can redefine them. If you are happy with your setup, use the v command to verify your setup, and then the w command to write the new partition table and exit. See . If you run fdisk -l again, you will see that Linux now knows about the new partitions. Unlike in some operating systems, it is not always necessary to reboot to see the changes. A reboot may be required if, for example, /dev/hda3 became /dev/hda2 because the original /dev/hda2 was deleted. If a reboot is needed, fdisk should tell you to do so.

Saving the partition table

More on fdisk

You may notice that we did not change the bootable flag on any partition. As our disk stands now, it still has the Windows Master Boot Record (MBR) and will therefore boot the first primary partition that is marked bootable (the NTFS partition in our example).

Neither LILO nor GRUB uses the bootable flag. If either of these is installed in the MBR, then it can boot the Windows/XP partition. You could also install LILO or GRUB into your /boot partition (/dev/hda2) and mark that partition bootable and remove the bootable flag from /dev/hda1. Leaving the original MBR can be useful if the machine is later returned to being a Windows-only machine.

You can also use fdisk to fix the partition order in the partition table if you need to. This will usually change the partition numbers, so you may have other work to do to restore your system to a working system. To make this change, use the f subcommand to switch to expert mode and then the f subcommand to fix the partition order, as shown in . If you just want to see what the new partition order would be without changing it, you can use the q subcommand to quit as we have done in this example, rather than writing the updated partition table to disk.

Fixing the partition table order.

You have now seen one way to add partitions to a Linux workstation. Other choices you might make are covered in the article, 'Learn Linux, 101: Find and place system files.'

Filesystem types

Linux supports several different filesystems. Each has strengths and weaknesses and its own set of performance characteristics. One important attribute of a filesystem is journaling, which allows for much faster recovery after a system crash. Generally, a journaling filesystem is preferred over a non-journaling one when you have a choice. You may also want to consider whether your chosen filesystem supports Security Enhanced Linux (or SELinux). Following is a brief summary of the types you need to know about for the LPI exam. See Resources for additional background information.

The ext2 filesystem

The ext2 filesystem (also known as the second extended filesystem) was developed to address shortcomings in the Minix filesystem used in early versions of Linux. It has been used extensively on Linux for many years. There is no journaling in ext2, and it has largely been replaced by ext3 and more recently ext4.

The ext3 filesystem

The ext3 filesystem adds journaling capability to a standard ext2 filesystem and is therefore an evolutionary growth of a very stable filesystem. It offers reasonable performance under most conditions and is still being improved. Because it adds journaling on top of the proven ext2 filesystem, it is possible to convert an existing ext2 filesystem to ext3 and even convert back again if required.

The ext4 filesystem started as extensions to ext3 to address the demands of ever larger file systems by increasing storage limits and improving performance. To preserve the stability of ext3, it was decided in June 2006 to fork the extensions into a new filesystem, ext4. The ext4 filesystem, was released in December 2008 and included in the 2.6.28 kernel. Some of the changes from ext3 are:

  • File systems up to 1 exabyte with files up to 16 terabytes
  • The use of extents to replace block mapping as a means of improving performance
  • Journal checksums to improve reliability
  • Faster file system checking because unallocated blocks can be skipped during checks.
  • Delayed allocation and multiblock allocators to improve performance and reduce file fragmentation.
  • Timestamp changes that provide finer granularity, a new creation date (which will require eventual updates to many other libraries and utilities to become fully useful). A further timestamp change addresses the year 2038 problem which is caused by storing timestamps as signed 32-bit integers.

The ReiserFS filesystem

ReiserFS is a B-tree-based filesystem that has very good overall performance, particularly for large numbers of small files. ReiserFS also scales well and has journaling. It is no longer in active development, does not support SELinux and has largely been superseded by Reiser4.

The XFS filesystem

XFS is a filesystem with journaling. It comes with robust features and is optimized for scalability. XFS aggressively caches in-transit data in RAM, so an uninterruptible power supply is recommended if you use XFS.

The swap filesystem

Swap space must be formatted for use as swap space, but it is not generally considered a filesystem.

The vfat filesystem

This filesystem (also known as FAT32) is not journaled and lacks many features required for a full Linux filesystem implementation. It is useful for exchanging data between Windows and Linux systems as it can be read by both Windows and Linux. Do not use this filesystem for Linux, except for sharing data between Windows and Linux. If you unzip or untar a Linux archive on a vfat disk, you will lose permissions, such as execute permission, and you will lose any symbolic links that may have been stored in the archive.

The ext3 filesystem is mature and was used as the default filesystem on many distributions. The ext4 filesystem is replacing it as the default filesystem on several distributions, including Red Hat enterprise Linux 6. Fedora 17 and Ubuntu 12.10. The ReiserFS filesystem was used for many years as the default on some distributions, including SUSE, but is less used today.

Creating filesystems

Linux uses the mkfs command to create filesystems and mkswapcommand to make swap space. The mkfs command is actually a front end to several filesystem-specific commands such as mkfs.ext3 for ext3, mkfs.ext4 for ext4 and mkfs.reiserfs for ReiserFS.

What filesystem support is already installed on your system? Use the ls /sbin/mk* command to find out. An example is shown in .

Filesystem creation commands

You will notice various forms of some commands. For example, you will usually find that the files mke2fs, mkfs.ext2, and mkfs.ext3 are identical, as are mkreiserfs and mkfs.reiserfs. Filesystems that may be needed to boot the system will usually use hard links to provide the different names for the same file. Filesystems that cannot be used for the / filesystem in Linux, such as vfat or msdos, may use symbolic links instead. The article 'Learn Linux, 101: Create and change hard and symbolic links' will help you learn about these different kinds of links.

There are a few common options for all mkfs commands. Options that are specific to the type of filesystem being created are passed to the appropriate creation command, based on the type of filesystem specified in the -type option. Our examples use mkfs -type, but you may use the other forms directly with equal effect. For example, you may use mkfs -type ext2, mk2fs, or mkfs.ext2. For the manual pages for a specific filesystem, use the appropriate mkfs command as the name, for example, man mkfs.ext3. Many of the values displayed in the output examples below can be controlled by options to mkfs.

Now that we have created all our partitions, we will reboot the Fedora 12 system and format the filesystems using that rather than the somewhat slower live Knoppix DVD. Of course, you could continue to use the Knoppix system if you wished. Remember that you need root authority to create filesystems.

Creating an ext3 filesystem

Let's format the /dev/sda8 partition as ext3 using the mkfs command as shown in .

Create Partition For Ext3 Filesystem For Usb Mac Download

Creating an ext3 filesystem

Note that a journal is created with ext3. If you wish to add a journal to an existing ext2 system, use the tune2fs command with the -j option.

A useful option for ext2, ext3, and ext4 filesystems is the -L option with a name, which assigns a label to the partition. This can be used instead of the device name when mounting filesystems; it provides some level of insulation against changes that may need to be reflected in various control files. To display or set a label for an existing ext2, ext3, or ext3 filesystem, use the e2label command. Labels are limited to a maximum size of 16 characters.

A more recent development is to use a Universally Unique Identifier, or UUID, rather than a label. A UUID is a 128-bit identifier usually displayed as 32 hexadecimal digits and four hyphens. Most Linux filesystems generate an UUID automatically when the filesystem is formatted. Use the blkid command (which does not need root authority) as shown in to see the UUID for the partition we just formatted. UUIDs are more likely to be unique than labels and are especially useful for hot-plugged devices such as USB drives.

Displaying a UUID using blkid

Creating an ext4 filesystem

Step outside the traditional MBR layout for a moment and format a USB flash drive using the GUID Partition Table (GPT) layout to learn how it works. Then create a Linux partition on the drive with the gdisk command. Finally, create an ext4 filesystem on the new partition with the mkfs command.

With gdisk, look at a typical USB flash drive (also known as USB thumb drives or USB keys). They are commonly shipped with a FAT32 filesystem spanning the whole drive and they usually are not partitioned. shows how gdisk displays information for a drive that is not already in GPT layout.

Using gdisk to display information on a non-GPT disk

First note that you must run gdisk as root or use sudo, depending on how your system is set up. Secondly note that gdisk wants to convert the existing format to GPT and warns you about this. Because you used the -l option to simply list the partitions, no action is performed.

Now run gdisk in interactive mode. List the available commands, then the known partition types before you create a new empty GUID partition table and finally a Linux partition. You'll display the new information and then quit gdisk. shows the interaction.

Using gdisk to create a GUID Partition Table (GPT) and a partition

Your final task is to create an ext4 filesystem on your new partition, /ev/sdc1. With the -L option of mkfs, label the partition and also show the GUID using the blkid command as you did for the ext3 partition above. illustrates this.

Creating an ext4 partition

To see all the parameters that you can specify when creating an ext4 partition, consult the man pages for mkfs.ext4.

Creating an XFS filesystem

Let's now reformat the partition we just formatted as ext3 using the XFS filesystem. Our Fedora 12 system uses SELinux (Security Enhanced Linux), so we should specify larger inodes than the default of 256 using the -i parameter. Recommended value is 512. Notice that the XFS formatter notifies you if it finds a recognized filesystem already on the partition. Note also that the UUID was reassigned by the XFS format.

Creating an XFS filesystem

You can label an XFS system using the -L option with a name. You can use the xfs_admin command with the -L option to add a label to an existing XFS filesystem. Use the -l option of xfs_admin to display a label. Unlike ext2, ext3, and ReiserFS, XFS labels have a maximum length of 12 characters.

Creating a ReiserFS filesystem

You create a ReiserFS filesystem using the mkfs command with the -t reiserfs option or the mkreiserfs command. ReiserFS does not support SELinux and is being replaced by Resier4

You can label a ReiserFS system using the -l (or --labeloption with a name). You can use the reiserfstune command to add a label or display the label on an existing ReiserFS filesystem. Labels are limited to a maximum length of 16 characters.

You may need to install the ReiserFS package on your system to use ReiserFS as it may not be included in a default install. See the man or info pages for more details.

Creating a vfat filesystem

We'll now create the FAT32 (vfat) filesystem on /dev/sda9.

Creating a vfat filesystem

UUIDs for vfat filesystems are shorter than normal UUIDs and therefore somewhat less likely to be unique. If you want a label instead, use the dosfslabel command. Labels for DOS partitions are limited to 11 characters in length.

Creating swap space

Now let's create some swap space on the /dev/sda4 partition using the mkswap command as shown in .

Creating swap space

Note that recent versions of mkswap show you the generated UUID.

Unlike regular filesystems, swap partitions aren't mounted. Instead, they are enabled using the swapon command. Your Linux system's startup scripts will take care of automatically enabling your swap partitions.

Other tools and filesystems

The following tools and filesystems are not part of the LPI objectives for this exam. This very brief overview touches on some of the tools and filesystems that you may encounter.

Partitioning tools

Many Linux distributions include the cfdisk or sfdisk commands. The cfdisk command provides a more graphical interface than fdisk, using the ncurses library functions as shown in . The sfdisk command is intended for programmer use and can be scripted. Use it if you know what you are doing.

Using cfdisk

Another popular tool for working with the partition table is parted, which can resize and format many partition types as well as create and destroy them. While parted cannot resize NTFS partitions, ntfsresize can. The qtparted tool uses the Qt toolkit to provide a graphical interface. It includes the parted functions as well as ntfsresize functions.

Ext3

The gparted tool is another graphical partitioning tool, designed for the GNOME desktop. It uses the GTK+GUI library, and is shown in . (See Resources for links to both qtparted and gparted.)

You may have to install the above packages in order to use them as they may not be part of your default install.

Using gparted

Earlier you saw the gdisk command which is quite similar in operation to fdisk. Use the gdisk command for GPT disks and the fdisk command for the more traditional MBR layout. Both parted and gparted can handle GPT layout as well as MBR layout, so you might find it more convenient to use one of these tools to handle both types.

Many distributions allow you to partition your disk, and sometimes shrink an existing Windows NTFS or FAT32 partition, as part of the installation process. Consult the installation documentation for your distribution.

Logical volume manager

The logical volume manager (or LVM) for Linux allows you to combine multiple physical storage devices into a single volume group. For example, you might add a partition to an existing volume group, rather than having to carve out contiguous space large enough for your desired filesystem. The article 'Learn Linux 101: Hard disk layout' has more information and an example of creating filesystems with LVM.

RAID

RAID (Redundant Array of Independent Disks) is a technology for providing a reliable data storage using low-cost disks that are much less expensive than the disks found on high-end systems. There are several different types of RAID, and RAID may be implemented in hardware or software. Linux supports both hardware and software RAID.

More filesystems

You will probably encounter filesystems besides those discussed above.

IBM's Journaled File System (JFS), currently used in IBM enterprise servers, is designed for high-throughput server environments. It is available for Linux and is included in several distributions. To create JFS filesystems, use the mkfs.jfs command.

Create Partition For Ext3 Filesystem For Usb Mac Os

The btrfs (B-Tree file system) was initially developed by Oracle and is available under the GPL license. It is a new copy-on-write filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair, and easy administration. This may not be installed by default, so you will probably have to install a package, such as btrfs-progs to enable btrfs support.

There are other filesystems too, such as the cramfs filesystem often used on embedded devices.

Downloadable resources

Related topics