Home > Articles

Chapter 3 Linux Filesystem

Linux Filesystem

Partitions

Partitions are used to divide hard drives into sections. A hard drive must have at least one partition and can have up to four. After creating your partitions, you need to format them, which creates the filesystem your operating system uses to store files. These steps are covered in more detail later in this chapter in the section "fdisk."

There are two types of partitions that can be used to store data, primary and extended. A primary partition is formatted and then used to store files. In addition, a computer can be booted only from a primary partition.

Key Concept

There are two types of partitions: primary and extended. An extended partition is divided into one or more logical drives that are used to store data.

An extended partition, on the other hand, cannot be used to store data directly. It is only a container for another structure called a logical drive. An extended partition is divided into one or more logical drives. Each logical drive is then formatted and used for data storage. Logical drives can exist only on extended partitions. You cannot directly use an extended partition. Rather, you use the logical drives contained in the extended partition.

A hard disk can have up to four primary partitions. Or, it can be divided into up to three primary partitions plus one extended partition. Figure 3.1 shows two different partitioning schemes.

Figure 3.1 On the left is a hard drive scheme divided into four primary partitions. The right side shows a hard drive scheme divided into two primary partitions and one extended partition. The extended partition has been divided into logical drives.

Key Concept

There can be a total of no more than four partitions on each disk. These can be all primary or you can have up to three primary and one extended partition.

One more issue must be addressed before you finalize your partition plan. As mentioned in Chapter 2, "Booting Linux," when LILO is used to boot Linux, it does not recognize beyond the 1023rd cylinder of your hard drive. Therefore, if you are using LILO to boot your system, the partition where LILO resides must exist entirely within the first 504MB.

Interpreting Partition Names

Partitions are named according to the type of disk controller the hard disk contains, the partition, and which partition it is on that disk. Under DOS, the first partition of the first drive would be disk(0) partition(1). Linux refers to the same partition as hda1 if it is IDE and sda1 if it's SCSI.

When interpreting partition names, the first letter identifies the type of controller (SCSI or IDE). The d stands for disk; the third letter numbers the disks (the first disk is a, the second is b, and so on); and the last character is the partition number. Table 3.1 shows some partitions.

Table 3.1  Naming Partitions Under Linux

Name

Controller

Disk

Partition

hda1

IDE controller

first disk

first partition

sda1

SCSI controller

first disk

first partition

hdc3

IDE controller

third disk

third partition

sdb4

SCSI controller

second disk

fourth partition


Key Concept

Partition names are based on the type of controller and partition number. Partitions on SCSI drives are referred to as sdan and partitions on IDE drives are named hdan.

How Many and What Size?

Linux will run just fine with only two partitions, root (/) and swap (swap). All files, applications, and so on, are installed on the root partition. The swap partition is used as virtual memory.

Virtual memory refers to a combination of the amount of physical RAM on your computer added to the amount of swap space you have configured. The operating system uses the swap space so it can function more efficiently.

If your system has 8MB of physical memory, a swap partition can give the operating system more memory, which results in a faster system. If you create a swap partition of 16MB, your system will have a total of 24MB of memory to use.

The type of partition you create is specified when using the fdisk utility as discussed later in this chapter. The advantages of using multiple partitions are as follows:

  • If one partition is damaged, the other partitions remain isolated from the damage.

  • If you have to reformat a partition, data on the other partitions are unaffected.

  • Files that grow rapidly, such as log and mail files, can be kept on separate partitions to prevent them from taking all available space.

  • Upgrades are easier to perform because the system and data files are isolated from each other.

  • Backups are easier if system files and data files are located on separate partitions.

  • The time required for filesystem checks at boot can be reduced.

Key Concept

The minimum number of partitions used to install Linux is two: one primary partition as the root (/) and a swap partition.

Your swap partition should be twice the amount of physical RAM installed on your system. The maximum size of a swap partition is 128MB, but you can have up to 16 separate swap partitions. The recommended minimum size is 16MB for the operating system to function at its best.

If space is tight, you can make the size of your swap partition equal to the amount of physical RAM, as long as it is at least 16MB.

Key Concept

A swap partition should be at least 16MB in size. Its maximum allowable size is 128MB. You can have up to 16 separate swap partitions on a single system.

Although a swap partition is more efficient, you can use a swap file if you do not have enough room to create a separate swap partition.

How all this is accomplished is relatively simple. Linux moves unused pages of memory out to the swap partition, allowing more applications to run simultaneously on your system. However, swapping is slower than using physical RAM. If you have 4MB of RAM or less, you will need to have a swap partition or the installation will fail.

One possible partitioning plan is shown in Table 3.2.

Table 3.2  Sample Partitioning Plan

Partition

Contents

/

Contains applications and configuration files

/var

Contains log files

/usr

Contains system software

/tmp

Contains temp files

/home

Contains users' home directories

swap

Acts as virtual memory


One disadvantage of multiple partitions is that you cannot enlarge a partition dynamically if it should get full. Rather, you would have to delete the partition and then re-create it with a larger size. With the larger hard drives available now, many system administrators use fewer partitions.

Plan your partitioning scheme out on paper. Although you can always blow away your partitions and start all over, having a well thought-out plan before starting the partitioning process will keep you from having to reinstall because of space constraints.

Key Concept

An advantage of multiple partitions is that you can better control the amount of space dynamic files such as log files can consume. On the other hand, a partition cannot be dynamically enlarged if it becomes full.

fips

If you are installing Linux on a computer running another operating system and there is no free space to create a new partition, you can use fips.exe to non-destructively divide a single FAT16 partition in two.

This program does not work with any filesystem except FAT16. Although fips usually works without losing any existing data, be sure to make a complete backup of your system before using it.

fips.exe can be downloaded at http://sunsite.unc.edu/pub/Linux/system/install. Whenever you use a program such as fips, you should always make a full backup and read the documentation before starting.

Copy fips.exe and restorbb.exe to a floppy. A copy of your old Master Boot Record (MBR) will be copied to this floppy during the installation program. This backup copy of your MBR can be used in case you ever need to restore your system to its original state. Be sure to label and date the diskette.

A copy of the old MBR also will be saved on your Linux partition as /boot/boot.0300 (for IDE drives) or /boot/boot.0800 (for SCSI drives). Do not ever delete the original file from your hard disk. If you delete it, you will not be able to restore the old MBR.

Key concept

You can use the fips utility to dynamically divide an existing FAT partition to create space for installing Linux.

fdisk

Be sure to keep good notes while partitioning your drive. You will want to note starting and ending cylinders, partition size in blocks, and any error messages you might get.

Cylinder refers to the total of the tracks that have the same location on each disk's surface. Tracks are the concentric circles on a disk.

When using fdisk, you must enter starting and ending cylinders for each partition. To create a partition, follow these steps:

  1. Size the partition.

  2. Designate its type.

  3. Write it to the partition table.

Using fdisk and each of the previous steps are covered in the following sections.

fdisk takes the name of the disk you want to partition as an argument or value.

For example, to create partitions on the second SCSI drive in your system, you would type

fdisk /dev/sdb

If you use fdisk without an argument, it assumes you want to partition /dev/hda. Some operating systems require that they be installed on the first partition of the first disk. Because Linux does not care what disks you use, you might want to create partitions on different hard disks. Just run fdisk for each hard disk you need to partition.

When using fdisk, you can get a menu of available options by typing m, as in the following example:

Command (m for help): m 
Command action 
   a   toggle a bootable flag 
   d   delete a partition 
   l   list known partition types 
   m   print this menu 
   n   add a new partition  
   p   print the partition table  
   q   quit without saving changes 
   t   change a partition's system id  
   u   change display/entry units 
   v   verify the partition table 
   w   write table to disk and exit 
   x   extrafunctionality 
 
Command (m for help):

If you create logical drives, you must reboot your system and go through the same options as before. However, when fdisk asks if you want to partition your drive the second time, say no.

You should use the Linux version of fdisk only to create or delete partitions for the Linux operating system. If you try to create or delete partitions for other operating systems with this version of fdisk, the other operating system will not recognize the partition.

After creating your partitions, you need to activate your swap partition(s), select the partition to be used as root, and format your partitions.

Key Concept

The fdisk utility can be used to create or delete partitions. It also can be used to view your partition table.

Let's walk through creating a couple partitions. If you have any existing partitions you will not be using, you can use the d command to delete them.

Step 1: Create a Primary Partition

First, type n to create a new partition. The Linux root partition will be 80MB in size. The following is an example:

Command (m for help):  n  
Command action  
    e   extended  
    p   primary partition (1-4) 

When creating a new partition, you are first asked whether you want to create a primary or extended partition.

Key Concept

If you have existing partitions on your drive, your options might be different. Remember, you can have only a maximum of four primary partitions or three primary partitions and one extended partition per hard disk. If you already have four partitions, you will not be able to create a new partition. In addition, if you already have an extended partition, you will not have this option.

For your first partition, you must create a primary partition because operating systems can boot only from primary partitions. After entering the p command, you will be prompted for the partition number and starting and ending cylinders.

Partition number (1-4): 1 
First cylinder (0-788):  0 
Last cylinder or +size or +sizeM or +sizeK (0-788): +80M 

You can specify either the ending cylinder or the size of the partition. In our example, we are instructing fdisk to create an 80MB partition to use as our first partition. If you type +80k, the partition will be 80KB in size. Typing +80 creates an 80-byte partition.

Now, when you issue the p command, fdisk displays the following:

Command (m for help):   p 
 
Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders 
Units = cylinders of 16065 * 512 bytes 
     Device Boot  Begin   Start     End   Blocks   Id  System 
  /dev/hda1   *       1       1     459  3686759   83  Linux native 
Command (m for help): 

Step 2: Create a Swap Partition

Next, you need to create a swap partition. When creating successive partitions, they should start with the next cylinder after the last one ended. Because our primary partition ended at 459, we will start the next one at 460:

Command (m for help): n 
Command action  
    e   extended  
    p   primary partition (1-4)  
p 
Partition number (1-4): 3 
First cylinder (460-788):  460 
Last cylinder or +size or +sizeM or +sizeK (474-683):  +128M 

Display your partition scheme again using the p command and write down this information, especially the size of each partition in blocks.

Command (m for help): p 
 
Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders 
Units = cylinders of 16065 * 512 bytes 
 
     Device Boot  Begin   Start     End   Blocks   Id  System 
  /dev/hda1   *       1       1     459  3686759   83  Linux native 
  /dev/hda2         460     460     475   128488   83  Linux native 

In our example, the swap partition, /dev/hda2, is listed as a Linux native partition. To complete the creation of a swap partition, you must change the type to swap by using the t command:

Command (m for help): t 
Partition number (1-4): 2 
Hex code (type L to list codes): 82 
 
Command (m for help): p 
 
Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders 
Units = cylinders of 16065 * 512 bytes 
 
     Device Boot  Begin   Start     End   Blocks   Id  System 
  /dev/hda1   *       1       1     459  3686759   83  Linux native 
  /dev/hda2         460     460     475   128488   82  Linux swap 

If you typed L instead of 82, you will see that Linux swap is type 82 and Linux native is 83. The type for extended partitions is 5.

Be sure to review your partition table after each change to ensure that the changes you made are what you intended.

It is customary to create your primary and swap partitions before creating an extended partition. However, you can create a primary partition after creating an extended partition as long as there is free space available and you have not reached the four-partition limit.

Step 3: Create an Extended Partition

Next, you should create an extended partition. Use the following:

Command (m for help):  n  
Command action  
    e   extended  
    p   primary partition (1-4) 
e 
First cylinder (476-788):  476 
Last cylinder or +size or +sizeM or +sizeK (474-788):  788 

When your partition table is displayed again, you'll see the following:

Command (m for help): p 
 
Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders 
Units = cylinders of 16065 * 512 bytes 
 
     Device Boot  Begin   Start     End   Blocks   Id  System 
  /dev/hda1   *       1       1     459  3686759   83  Linux native 
  /dev/hda2         460     460     475   128488   82  Linux swap 
  /dev/hda3         476     476     788  2513751    5  Extended 

Next, you will need to create logical drives in your extended partition. When you issue the n command, you will have a new choice:

Command (m for help): n 
Command action 
   l   logical (4 or over) 
   p   primary partition (1-4) 
 
Command (m for help): 

You can elect to divide your extended partition into one or more logical drives by using the l command and then specifying the appropriate size. The starting and ending cylinders for each logical drive must be completely contained within the starting and ending cylinders of the extended partition.

After you have finished defining your partitions, you can quit fdisk and save the changes to the partition table by using the w command. If you decide you don't want to make these changes, use the q command to quit fdisk without saving your changes.

Step 4: Assign Filesystem Names

Next, you must associate the appropriate Linux filesystem names with each of the partitions you are going to use. This is done through the installation program for your specific distribution. Remember, you can install Linux with only the / and swap partitions.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020