Вы находитесь на странице: 1из 16

English

Sign in (or register)

Technical topics

Evaluation software

Community

Events

Learn Linux, 101: Create partitions and filesystems


Divide and conquer your disk space Ian Shields, Senior Programmer, IBM Summary: Learn how to create partitions on a disk drive and how to format them for use on a Linux system as swap or data space. You can use the material in this article to study for the LPI 101 exam for Linux system administrator certification, or just to learn about partitions and Linux filesystems for your own use. 04 Dec 2012 - This article updated to include material for the LPI Exam 101: Objective Changes as of July 2, 2012. Major updates include information about the ext4 filesystem and occur in this section: Creating filesystems. Minor updates occur in these sections Overview, Block devices and partitions, The ext2 filesystem, The ext3 filesystem, The vfat filesystem, Creating an ext4 filesystem, Partitioning tools, Logical volume manager, and Resources. Date: 04 Dec 2012 (Published 12 Jul 2010) Level: Intermediate PDF: A4 and Letter (448 KB | 24 pages)Get Adobe Reader Also available in: Korean Russian Japanese Portuguese Activity: 180307 views Comments: 6 (View | Add comment - Sign in) Average rating (74 votes) Rate this article

About this series


This series of articles helps you learn Linux system administration tasks. You can also use the material in these articles to prepare for Linux Professional Institute Certification level 1 (LPIC-1) exams. See our developerWorks roadmap for LPIC-1 for a description of and link to each article in this series. The roadmap is in progress and reflects the latest (April 2009 with minor updates in July 2012) objectives for the LPIC-1 exams: as we complete articles, we add them to the roadmap. In the meantime, though, you can find earlier versions of similar material, supporting previous LPIC-1 objectives prior to April 2009, in our LPI certification exam prep tutorials. Overview In this article, learn about disk partitions and Linux filesystems. Learn to: Create a partition Use m k f scommands 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 g d i s kcommand and the GUID Partition Table (GPT). The new code listings and figures were all done on a 64-bit Fedora 17 system. 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

Connect with Ian


Ian is one of our most popular and prolific authors. Browse all of Ian's articles on developerWorks. Check out Ian's profile and connect with him, other authors, and fellow readers in My developerWorks. Our article, "Learn Linux 101: Learn Linux, 101: Hard disk layout," introduced you to hard drive layouts, partitions, and some basic use of the f d i s kand g d i s k commands to view partition information. You learned about the Master Boot Record (MBR), partition tables, partitions, including primary, extended, and logical
www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html 1/16

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 f d i s kcommand and partitioning using MB layouts. It includes some g d i s kcommand 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 f d i s kcommand, which is used to create, modify, or delete partitions on block devices. You will also learn about the various forms of the m k f scommand (mkfs stands for make filesystem ); m k f scommands 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 l s lcommand 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 Listing 1. Listing 1. Linux block and character devices
[ i a n @ e c h i d n a~ ] $l sl/ d e v / l o o p 1/ d e v / n u l l/ d e v / s d [ a b ]/ d e v / s r 0/ d e v / t t y 0 b r w r w .1r o o td i s k 7 , 12 0 1 0 0 6 1 40 7 : 2 5/ d e v / l o o p 1 c r w r w r w .1r o o tr o o t 1 , 32 0 1 0 0 6 1 40 7 : 2 5/ d e v / n u l l b r w r w .1r o o td i s k 8 , 02 0 1 0 0 6 1 40 7 : 2 5/ d e v / s d a b r w r w .1r o o td i s k 8 ,1 62 0 1 0 0 6 1 40 7 : 2 5/ d e v / s d b b r w r w +1r o o tc d r o m1 1 , 02 0 1 0 0 6 1 40 7 : 2 5/ d e v / s r 0 c r w w .1r o o tr o o t 4 , 02 0 1 0 0 6 1 40 7 : 2 5/ d e v / t t y 0

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 f d i s kprogram, 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 f d i s kcommand with the loption 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. Listing 2 shows the partitions on the primary hard drives of two of my systems. Listing 2. Listing partitions with fdisk
[ r o o t @ a t t i c 4~ ] #f d i s kl/ d e v / s d a D i s k/ d e v / s d a :6 4 0 . 1G B ,6 4 0 1 3 5 0 2 8 7 3 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,7 7 8 2 5c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s S e c t o rs i z e( l o g i c a l / p h y s i c a l ) :5 1 2b y t e s/5 1 2b y t e s I / Os i z e( m i n i m u m / o p t i m a l ) :5 1 2b y t e s/5 1 2b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 6 4 a 1 a D e v i c eB o o t / d e v / s d a 1 / d e v / s d a 2 / d e v / s d a 3 * S t a r t 1 1 2 8 4 6 3 4 0 E n d 1 2 7 1 4 0 2 5 6 5 3 8 B l o c k s 1 0 2 0 0 9 6 1 0 2 4 1 4 3 7 + 8 1 9 2 0 0 0 0 I d 8 3 8 2 8 3 S y s t e m L i n u x L i n u xs w a p/S o l a r i s L i n u x

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

2/16

/ d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 / d e v / s d a 8 / d e v / s d a 9

1 4 0 3 1 4 0 3 1 0 4 2 1 1 9 3 4 5 2 8 3 5 1 3 7 3 5 5

4 6 3 3 9 1 0 4 2 0 1 9 3 4 4 2 8 3 5 0 3 7 3 5 4 4 6 3 3 9

3 6 0 9 5 6 4 2 2 7 2 4 3 7 0 5 3 + 7 1 6 8 1 9 9 8 + 7 2 3 4 0 6 6 3 + 7 2 3 2 4 5 9 8 + 7 2 1 7 1 9 8 1

5 8 3 8 3 8 3 8 3 8 3

E x t e n d e d L i n u x L i n u x L i n u x L i n u x L i n u x

P a r t i t i o nt a b l ee n t r i e sa r en o ti nd i s ko r d e r [ r o o t @ e c h i d n a~ ] #f d i s kl/ d e v / s d a D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 S t a r t 1 9 6 3 4 9 7 3 1 9 7 3 1 2 0 9 1 8 3 9 6 4 5 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 I d 7 8 3 5 8 3 8 3 8 3 S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u x L i n u x L i n u x

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 f d i s kcommand. 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 f d i s kcommand does not commit any changes to your disk until you tell it to. Other tools, including p a r t e d , 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 f d i s kin 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 Listing 3. Listing 3. Starting interactive fdisk
k n o p p i x @ M i c r o k n o p p i x : ~ $s ur o o t @ M i c r o k n o p p i x : ~ #f d i s k/ d e v / s d a T h en u m b e ro fc y l i n d e r sf o rt h i sd i s ki ss e tt o1 2 1 6 0 1 . T h e r ei sn o t h i n gw r o n gw i t ht h a t ,b u tt h i si sl a r g e rt h a n1 0 2 4 , a n dc o u l di nc e r t a i ns e t u p sc a u s ep r o b l e m sw i t h : 1 )s o f t w a r et h a tr u n sa tb o o tt i m e( e . g . ,o l dv e r s i o n so fL I L O ) 2 )b o o t i n ga n dp a r t i t i o n i n gs o f t w a r ef r o mo t h e rO S s ( e . g . ,D O SF D I S K ,O S / 2F D I S K )

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

3/16

C o m m a n d( mf o rh e l p ) :

Most modern disks have more than 1024 cylinders, so you will usually see the warning shown in Listing 3. Type mto display a list of available one-letter commands as shown in Listing 4. Listing 4. Help in fdisk
C o m m a n d( mf o rh e l p ) :m C o m m a n da c t i o n a t o g g l eab o o t a b l ef l a g b e d i tb s dd i s k l a b e l c t o g g l et h ed o sc o m p a t i b i l i t yf l a g d d e l e t eap a r t i t i o n l l i s tk n o w np a r t i t i o nt y p e s m p r i n tt h i sm e n u n a d dan e wp a r t i t i o n o c r e a t ean e we m p t yD O Sp a r t i t i o nt a b l e p p r i n tt h ep a r t i t i o nt a b l e q q u i tw i t h o u ts a v i n gc h a n g e s s c r e a t ean e we m p t yS u nd i s k l a b e l t c h a n g eap a r t i t i o n ' ss y s t e mi d u c h a n g ed i s p l a y / e n t r yu n i t s v v e r i f yt h ep a r t i t i o nt a b l e w w r i t et a b l et od i s ka n de x i t x e x t r af u n c t i o n a l i t y( e x p e r t so n l y ) C o m m a n d( mf o rh e l p ) :

Use the pcommand to display the existing partition on this particular disk; Listing 5 shows the output. Listing 5. Displaying the existing partition table
C o m m a n d( mf o rh e l p ) :p D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 S t a r t 1 9 6 3 4 9 7 3 1 9 7 3 1 2 0 9 1 8 3 9 6 4 5 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 I d 7 8 3 5 8 3 8 3 8 3 S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u x L i n u x L i n u x

C o m m a n d( mf o rh e l p ) :

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 ncommand to create a new partition; see Listing 6. Listing 6. Creating our first partition
C o m m a n d( mf o rh e l p ) :n C o m m a n da c t i o n l l o g i c a l( 5o ro v e r ) p p r i m a r yp a r t i t i o n( 1 4 ) p

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

4/16

S e l e c t e dp a r t i t i o n4 F i r s tc y l i n d e r( 9 1 1 2 1 2 1 6 0 1 ,d e f a u l t9 1 1 2 ) : U s i n gd e f a u l tv a l u e9 1 1 2 L a s tc y l i n d e r ,+ c y l i n d e r so r+ s i z e { K , M , G }( 9 1 1 2 9 6 3 3 ,d e f a u l t9 6 3 3 ) :+ 5 2 1 C o m m a n d( mf o rh e l p ) :p D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 S t a r t 1 9 6 3 4 9 7 3 1 9 1 1 2 9 7 3 1 2 0 9 1 8 3 9 6 4 5 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 9 6 3 3 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 4 1 9 2 9 6 5 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 I d 7 8 3 5 8 3 8 3 8 3 8 3 S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u x L i n u x L i n u x L i n u x

P a r t i t i o nt a b l ee n t r i e sa r en o ti nd i s ko r d e r C o m m a n d( mf o rh e l p ) :

We took the default for the first cylinder and specified the value of +521 for the number of cylinders. You can see from Listing 6 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 f d i s kwarns 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 nsubcommand 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 f d i s kcalculate the number of cylinders for us. The results are shown in Listing 7. Listing 7. Creating our data partitions
C o m m a n d( mf o rh e l p ) :n F i r s tc y l i n d e r( 5 3 9 0 6 1 1 6 6 7 9 ,d e f a u l t5 3 9 0 6 ) : U s i n gd e f a u l tv a l u e5 3 9 0 6 L a s tc y l i n d e r ,+ c y l i n d e r so r+ s i z e { K , M , G }( 5 3 9 0 6 1 1 6 6 7 9 ,d e f a u l t1 1 6 6 7 9 ) :+ 4 0 G C o m m a n d( mf o rh e l p ) :n F i r s tc y l i n d e r( 5 9 1 2 9 1 1 6 6 7 9 ,d e f a u l t5 9 1 2 9 ) : U s i n gd e f a u l tv a l u e5 9 1 2 9 L a s tc y l i n d e r ,+ c y l i n d e r so r+ s i z e { K , M , G }( 5 9 1 2 9 1 1 6 6 7 9 ,d e f a u l t1 1 6 6 7 9 ) :+ 2 0 0 0 M C o m m a n d( mf o rh e l p ) :p D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 / d e v / s d a 8 / d e v / s d a 9 S t a r t 1 9 6 3 4 9 7 3 1 9 1 1 2 9 7 3 1 2 0 9 1 8 3 9 6 4 5 5 3 9 0 6 5 9 1 2 9 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 9 6 3 3 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 5 9 1 2 8 5 9 3 8 4 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 4 1 9 2 9 6 5 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 4 1 9 5 3 7 1 6 2 0 5 6 2 8 8 + I d 7 8 3 5 8 3 8 3 8 3 8 3 8 3 8 3 S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u x L i n u x L i n u x L i n u x L i n u x L i n u x

P a r t i t i o nt a b l ee n t r i e sa r en o ti nd i s ko r d e r C o m m a n d( mf o rh e l p ) :

Changing partition type Before we leave f d i s k , we will change the partition types for the swap and vfat partitions. We do this using the tsubcommand 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 Las you see in Listing 8.

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

5/16

Listing 8. Changing partition types


C o m m a n d( mf o rh e l p ) :t P a r t i t i o nn u m b e r( 1 9 ) :4 H e xc o d e( t y p eLt ol i s tc o d e s ) :8 2 C h a n g e ds y s t e mt y p eo fp a r t i t i o n4t o8 2( L i n u xs w a p/S o l a r i s ) C o m m a n d( mf o rh e l p ) :t P a r t i t i o nn u m b e r( 1 9 ) :9 H e xc o d e( t y p eLt ol i s tc o d e s ) :b C h a n g e ds y s t e mt y p eo fp a r t i t i o n9t ob( W 9 5F A T 3 2 ) C o m m a n d( mf o rh e l p ) :

Saving our partition table So far, we have just been doing an in-memory edit of a partition table. We could use the qcommand to quit without saving changes. If something is not how you want it, you can use the dcommand to delete one or more partitions so you can redefine them. If you are happy with your setup, use the vcommand to verify your setup, and then the wcommand to write the new partition table and exit. See Listing 9. If you run f d i s klagain, 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, f d i s kshould tell you to do so. Listing 9. Saving the partition table
C o m m a n d( mf o rh e l p ) :v 9 9 9 5 2 1 5 8 0u n a l l o c a t e d5 1 2 b y t es e c t o r s C o m m a n d( mf o rh e l p ) :w T h ep a r t i t i o nt a b l eh a sb e e na l t e r e d ! C a l l i n gi o c t l ( )t or e r e a dp a r t i t i o nt a b l e . W A R N I N G :I fy o uh a v ec r e a t e do rm o d i f i e da n yD O S6 . x p a r t i t i o n s ,p l e a s es e et h ef d i s km a n u a lp a g ef o ra d d i t i o n a l i n f o r m a t i o n . S y n c i n gd i s k s . r o o t @ M i c r o k n o p p i x : ~ #f d i s kl/ d e v / s d a D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 / d e v / s d a 8 / d e v / s d a 9 S t a r t 1 9 6 3 4 9 7 3 1 9 1 1 2 9 7 3 1 2 0 9 1 8 3 9 6 4 5 5 3 9 0 6 5 9 1 2 9 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 9 6 3 3 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 5 9 1 2 8 5 9 3 8 4 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 4 1 9 2 9 6 5 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 4 1 9 5 3 7 1 6 2 0 5 6 2 8 8 + I d 7 8 3 5 8 2 8 3 8 3 8 3 8 3 b S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u xs w a p/S o l a r i s L i n u x L i n u x L i n u x L i n u x W 9 5F A T 3 2

P a r t i t i o nt a b l ee n t r i e sa r en o ti nd i s ko r d e r

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 f d i s kto 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 fsubcommand to switch to expert mode and then the fsubcommand to fix the partition order, as shown in Listing 10. If you just want to see what the new partition order would be without changing it, you can use the qsubcommand to quit as we have done in this example, rather than writing the updated partition table to disk. Listing 10. Fixing the partition table order.
C o m m a n d( mf o rh e l p ) :p D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

6/16

U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 / d e v / s d a 8 / d e v / s d a 9 S t a r t 1 9 6 3 4 9 7 3 1 9 1 1 2 9 7 3 1 2 0 9 1 8 3 9 6 4 5 5 3 9 0 6 5 9 1 2 9 E n d 9 1 1 1 9 7 3 0 1 1 6 6 7 9 9 6 3 3 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 5 9 1 2 8 5 9 3 8 4 B l o c k s 7 3 1 8 4 0 7 6 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 4 1 9 2 9 6 5 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 4 1 9 5 3 7 1 6 2 0 5 6 2 8 8 + I d 7 8 3 5 8 2 8 3 8 3 8 3 8 3 b S y s t e m H P F S / N T F S L i n u x E x t e n d e d L i n u xs w a p/S o l a r i s L i n u x L i n u x L i n u x L i n u x W 9 5F A T 3 2

P a r t i t i o nt a b l ee n t r i e sa r en o ti nd i s ko r d e r C o m m a n d( mf o rh e l p ) :x E x p e r tc o m m a n d( mf o rh e l p ) :f D o n e . E x p e r tc o m m a n d( mf o rh e l p ) :r C o m m a n d( mf o rh e l p ) :p D i s k/ d e v / s d a :1 0 0 0 . 2G B ,1 0 0 0 2 0 4 8 8 6 0 1 6b y t e s 2 5 5h e a d s ,6 3s e c t o r s / t r a c k ,1 2 1 6 0 1c y l i n d e r s U n i t s=c y l i n d e r so f1 6 0 6 5*5 1 2=8 2 2 5 2 8 0b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 d e 2 0 f D e v i c eB o o t / d e v / s d a 1 * / d e v / s d a 2 / d e v / s d a 3 / d e v / s d a 4 / d e v / s d a 5 / d e v / s d a 6 / d e v / s d a 7 / d e v / s d a 8 / d e v / s d a 9 S t a r t 1 9 1 1 2 9 6 3 4 9 7 3 1 9 7 3 1 2 0 9 1 8 3 9 6 4 5 5 3 9 0 6 5 9 1 2 9 E n d 9 1 1 1 9 6 3 3 9 7 3 0 1 1 6 6 7 9 2 0 9 1 7 3 9 6 4 4 5 3 9 0 5 5 9 1 2 8 5 9 3 8 4 B l o c k s 7 3 1 8 4 0 7 6 4 1 9 2 9 6 5 7 7 9 1 5 2 + 8 5 9 0 6 7 8 4 2 + 8 9 8 5 9 5 4 6 1 5 0 4 2 4 5 9 6 1 1 4 5 5 1 4 5 1 4 1 9 5 3 7 1 6 2 0 5 6 2 8 8 + I d 7 8 2 8 3 5 8 3 8 3 8 3 8 3 b S y s t e m H P F S / N T F S L i n u xs w a p/S o l a r i s L i n u x E x t e n d e d L i n u x L i n u x L i n u x L i n u x W 9 5F A T 3 2

C o m m a n d( mf o rh e l p ) :q

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.
www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html 7/16

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 m k f scommand to create filesystems and m k s w a p command to make swap space. The m k f scommand is actually a front end to several filesystemspecific commands such as m k f s . e x t 3for ext3, m k f s . e x t 4for ext4 and m k f s . r e i s e r f sfor ReiserFS. What filesystem support is already installed on your system? Use the l s/ s b i n / m k *command to find out. An example is shown in Listing 11. Listing 11. Filesystem creation commands
[ i a n @ e c h i d n a~ ] $l s/ s b i n / m k * / s b i n / m k d o s f s / s b i n / m k f s . e x t 2 / s b i n / m k e 2 f s / s b i n / m k f s . e x t 3 / s b i n / m k f s / s b i n / m k f s . e x t 4 / s b i n / m k f s . b t r f s / s b i n / m k f s . e x t 4 d e v / s b i n / m k f s . c r a m f s / s b i n / m k f s . m s d o s

/ s b i n / m k f s . n t f s / s b i n / m k f s . v f a t / s b i n / m k f s . x f s / s b i n / m k h o m e d i r _ h e l p e r / s b i n / m k s w a p

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 m k f scommands. 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 t y p eoption. Our examples use m k f st y p e , but you may use the other forms directly with equal effect. For example, you may use m k f st y p ee x t 2 ,m k 2 f s , or m k f s . e x t 2 . For the manual pages for a specific filesystem, use the appropriate m k f scommand as the name, for example, m a nm k f s . e x t 3 . Many of the values displayed in the output examples below can be controlled by options to m k f s . 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 m k f scommand as shown in Listing 12. Listing 12. Creating an ext3 filesystem
[ r o o t @ e c h i d n a~ ] #m k f ste x t 3/ d e v / s d a 8 m k e 2 f s1 . 4 1 . 9( 2 2 A u g 2 0 0 9 ) F i l e s y s t e ml a b e l = O St y p e :L i n u x B l o c ks i z e = 4 0 9 6( l o g = 2 ) F r a g m e n ts i z e = 4 0 9 6( l o g = 2 ) 2 6 2 4 4 9 6i n o d e s ,1 0 4 8 8 4 2 9b l o c k s 5 2 4 4 2 1b l o c k s( 5 . 0 0 % )r e s e r v e df o rt h es u p e ru s e r F i r s td a t ab l o c k = 0 M a x i m u mf i l e s y s t e mb l o c k s = 4 2 9 4 9 6 7 2 9 6 3 2 1b l o c kg r o u p s 3 2 7 6 8b l o c k sp e rg r o u p ,3 2 7 6 8f r a g m e n t sp e rg r o u p 8 1 7 6i n o d e sp e rg r o u p S u p e r b l o c kb a c k u p ss t o r e do nb l o c k s : 3 2 7 6 8 ,9 8 3 0 4 ,1 6 3 8 4 0 ,2 2 9 3 7 6 ,2 9 4 9 1 2 ,8 1 9 2 0 0 ,8 8 4 7 3 6 ,1 6 0 5 6 3 2 ,2 6 5 4 2 0 8 , 4 0 9 6 0 0 0 ,7 9 6 2 6 2 4 W r i t i n gi n o d et a b l e s :d o n e C r e a t i n gj o u r n a l( 3 2 7 6 8b l o c k s ) :d o n e W r i t i n gs u p e r b l o c k sa n df i l e s y s t e ma c c o u n t i n gi n f o r m a t i o n :d o n e

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

8/16

T h i sf i l e s y s t e mw i l lb ea u t o m a t i c a l l yc h e c k e de v e r y2 0m o u n t so r 1 8 0d a y s ,w h i c h e v e rc o m e sf i r s t . U s et u n e 2 f sco rit oo v e r r i d e .

Note that a journal is created with ext3. If you wish to add a journal to an existing ext2 system, use the t u n e 2 f scommand with the joption. A useful option for ext2, ext3, and ext4 filesystems is the Loption 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 e 2 l a b e lcommand. 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 b l k i dcommand (which does not need root authority) as shown in Listing 13 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. Listing 13. Displaying a UUID using blkid
[ i a n @ e c h i d n a~ ] $b l k i d/ d e v / s d a 8 / d e v / s d a 8 :U U I D = " 8 7 0 4 0 d e f 9 2 0 e 4 5 2 5 9 c 8 1 c 5 8 5 d d c 4 6 3 8 4 "S E C _ T Y P E = " e x t 2 "T Y P E = " e x t 3 "

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 g d i s kcommand. Finally, create an ext4 filesystem on the new partition with the m k f scommand. With g d i s k , 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. Listing 14 shows how g d i s kdisplays information for a drive that is not already in GPT layout. Listing 14. Using gdisk to display information on a non-GPT disk
[ r o o t @ a t t i c 4~ ] #g d i s kl/ d e v / s d c G P Tf d i s k( g d i s k )v e r s i o n0 . 8 . 4 P a r t i t i o nt a b l es c a n : M B R :M B Ro n l y B S D :n o tp r e s e n t A P M :n o tp r e s e n t G P T :n o tp r e s e n t

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * F o u n di n v a l i dG P Ta n dv a l i dM B R ;c o n v e r t i n gM B Rt oG P Tf o r m a t . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * W a r n i n g !M a i np a r t i t i o nt a b l eo v e r l a p st h ef i r s tp a r t i t i o nb y2b l o c k s ! T r yr e d u c i n gt h ep a r t i t i o nt a b l es i z eb y8e n t r i e s . ( U s et h e' s 'i t e mo nt h ee x p e r t s 'm e n u . ) W a r n i n g !S e c o n d a r yp a r t i t i o nt a b l eo v e r l a p st h el a s tp a r t i t i o nb y 3 3b l o c k s ! Y o uw i l ln e e dt od e l e t et h i sp a r t i t i o no rr e s i z ei ti na n o t h e ru t i l i t y . D i s k/ d e v / s d c :6 2 5 3 0 6 2 4s e c t o r s ,2 9 . 8G i B L o g i c a ls e c t o rs i z e :5 1 2b y t e s D i s ki d e n t i f i e r( G U I D ) :D 7 9 0 0 F 1 3 8 3 9 B 4 9 B 2 9 C 4 3 4 3 6 7 5 2 8 D C 3 8 1 P a r t i t i o nt a b l eh o l d su pt o1 2 8e n t r i e s F i r s tu s a b l es e c t o ri s3 4 ,l a s tu s a b l es e c t o ri s6 2 5 3 0 5 9 0 P a r t i t i o n sw i l lb ea l i g n e do n3 2 s e c t o rb o u n d a r i e s T o t a lf r e es p a c ei s0s e c t o r s( 0b y t e s ) N u m b e r S t a r t( s e c t o r ) 1 3 2 E n d( s e c t o r ) S i z e 6 2 5 3 0 6 2 3 2 9 . 8G i B C o d e N a m e 0 7 0 0 M i c r o s o f tb a s i cd a t a

First note that you must run g d i s kas root or use s u d o , depending on how your system is set up. Secondly note that g d i s kwants to convert the existing format to GPT and warns you about this. Because you used the loption to simply list the partitions, no action is performed. Now run g d i s kin 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 g d i s k . Listing 15 shows the interaction. Listing 15. Using gdisk to create a GUID Partition Table (GPT) and a partition
[ r o o t @ a t t i c 4~ ] #g d i s k/ d e v / s d c G P Tf d i s k( g d i s k )v e r s i o n0 . 8 . 4

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

9/16

P a r t i t i o nt a b l es c a n : M B R :M B Ro n l y B S D :n o tp r e s e n t A P M :n o tp r e s e n t G P T :n o tp r e s e n t

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * F o u n di n v a l i dG P Ta n dv a l i dM B R ;c o n v e r t i n gM B Rt oG P Tf o r m a t . T H I SO P E R A T I O NI SP O T E N T I A L L YD E S T R U C T I V E !E x i tb yt y p i n g' q 'i f y o ud o n ' tw a n tt oc o n v e r ty o u rM B Rp a r t i t i o n st oG P Tf o r m a t ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * W a r n i n g !M a i np a r t i t i o nt a b l eo v e r l a p st h ef i r s tp a r t i t i o nb y2b l o c k s ! T r yr e d u c i n gt h ep a r t i t i o nt a b l es i z eb y8e n t r i e s . ( U s et h e' s 'i t e mo nt h ee x p e r t s 'm e n u . ) W a r n i n g !S e c o n d a r yp a r t i t i o nt a b l eo v e r l a p st h el a s tp a r t i t i o nb y 3 3b l o c k s ! Y o uw i l ln e e dt od e l e t et h i sp a r t i t i o no rr e s i z ei ti na n o t h e ru t i l i t y . C o m m a n d( ?f o rh e l p ) :? b b a c ku pG P Td a t at oaf i l e c c h a n g eap a r t i t i o n ' sn a m e d d e l e t eap a r t i t i o n i s h o wd e t a i l e di n f o r m a t i o no nap a r t i t i o n l l i s tk n o w np a r t i t i o nt y p e s n a d dan e wp a r t i t i o n o c r e a t ean e we m p t yG U I Dp a r t i t i o nt a b l e( G P T ) p p r i n tt h ep a r t i t i o nt a b l e q q u i tw i t h o u ts a v i n gc h a n g e s r r e c o v e r ya n dt r a n s f o r m a t i o no p t i o n s( e x p e r t so n l y ) s s o r tp a r t i t i o n s t c h a n g eap a r t i t i o n ' st y p ec o d e v v e r i f yd i s k w w r i t et a b l et od i s ka n de x i t x e x t r af u n c t i o n a l i t y( e x p e r t so n l y ) ? p r i n tt h i sm e n u C o m m a n d( ?f o rh e l p ) :l 0 7 0 0M i c r o s o f tb a s i cd a t a 4 2 0 0W i n d o w sL D Md a t a 7 f 0 0C h r o m e O Sk e r n e l 8 2 0 0L i n u xs w a p 8 e 0 0L i n u xL V M a 5 0 2F r e e B S Ds w a p a 5 0 5F r e e B S DV i n u m / R A I D a 9 0 2N e t B S DF F S a 9 0 5N e t B S De n c r y p t e d a f 0 0A p p l eH F S / H F S + a f 0 3A p p l el a b e l b e 0 0S o l a r i sb o o t b f 0 2S o l a r i ss w a p b f 0 5S o l a r i s/ h o m e b f 0 8S o l a r i sR e s e r v e d2 b f 0 bS o l a r i sR e s e r v e d5 e f 0 0E F IS y s t e m f d 0 0L i n u xR A I D

0 c 0 1M i c r o s o f tr e s e r v e d 4 2 0 1W i n d o w sL D Mm e t a d a t a 7 f 0 1C h r o m e O Sr o o t 8 3 0 0L i n u xf i l e s y s t e m a 5 0 0F r e e B S Dd i s k l a b e l a 5 0 3F r e e B S DU F S a 8 0 0A p p l eU F S a 9 0 3N e t B S DL F S a 9 0 6N e t B S DR A I D a f 0 1A p p l eR A I D a f 0 4A p p l e T Vr e c o v e r y b f 0 0S o l a r i sr o o t b f 0 3S o l a r i sb a c k u p b f 0 6S o l a r i sa l t e r n a t es e b f 0 9S o l a r i sR e s e r v e d3 c 0 0 1H P U Xd a t a e f 0 1M B Rp a r t i t i o ns c h e m e

2 7 0 0W i n d o w sR E 7 5 0 1I B MG P F S 7 f 0 2C h r o m e O Sr e s e r v e d 8 3 0 1L i n u xr e s e r v e d a 5 0 1F r e e B S Db o o t a 5 0 4F r e e B S DZ F S a 9 0 1N e t B S Ds w a p a 9 0 4N e t B S Dc o n c a t e n a t e d a b 0 0A p p l eb o o t a f 0 2A p p l eR A I Do f f l i n e a f 0 5A p p l eC o r eS t o r a g e b f 0 1S o l a r i s/ u s r&M a cZ b f 0 4S o l a r i s/ v a r b f 0 7S o l a r i sR e s e r v e d1 b f 0 aS o l a r i sR e s e r v e d4 c 0 0 2H P U Xs e r v i c e e f 0 2B I O Sb o o tp a r t i t i o n

C o m m a n d( ?f o rh e l p ) :o T h i so p t i o nd e l e t e sa l lp a r t i t i o n sa n dc r e a t e san e wp r o t e c t i v eM B R . P r o c e e d ?( Y / N ) :y C o m m a n d( ?f o rh e l p ) :n P a r t i t i o nn u m b e r( 1 1 2 8 ,d e f a u l t1 ) : F i r s ts e c t o r( 3 4 6 2 5 3 0 5 9 0 ,d e f a u l t=2 0 4 8 )o r{ + } s i z e { K M G T P } : L a s ts e c t o r( 2 0 4 8 6 2 5 3 0 5 9 0 ,d e f a u l t=6 2 5 3 0 5 9 0 )o r{ + } s i z e { K M G T P } : C u r r e n tt y p ei s' L i n u xf i l e s y s t e m ' H e xc o d eo rG U I D( Lt os h o wc o d e s ,E n t e r=8 3 0 0 ) : C h a n g e dt y p eo fp a r t i t i o nt o' L i n u xf i l e s y s t e m ' C o m m a n d( ?f o rh e l p ) :p D i s k/ d e v / s d c :6 2 5 3 0 6 2 4s e c t o r s ,2 9 . 8G i B L o g i c a ls e c t o rs i z e :5 1 2b y t e s D i s ki d e n t i f i e r( G U I D ) :B 3 2 1 C 1 C 5 7 9 5 A 4 8 3 6 9 E 1 6 D 7 D 4 5 D D 8 F 3 F 2 P a r t i t i o nt a b l eh o l d su pt o1 2 8e n t r i e s F i r s tu s a b l es e c t o ri s3 4 ,l a s tu s a b l es e c t o ri s6 2 5 3 0 5 9 0 P a r t i t i o n sw i l lb ea l i g n e do n2 0 4 8 s e c t o rb o u n d a r i e s T o t a lf r e es p a c ei s2 0 1 4s e c t o r s( 1 0 0 7 . 0K i B ) N u m b e r S t a r t( s e c t o r ) 1 2 0 4 8 C o m m a n d( ?f o rh e l p ) :q E n d( s e c t o r ) S i z e 6 2 5 3 0 5 9 0 2 9 . 8G i B C o d e N a m e 8 3 0 0 L i n u xf i l e s y s t e m

Your final task is to create an ext4 filesystem on your new partition, /ev/sdc1. With the Loption of m k f s , label the partition and also show the GUID using the b l k i dcommand as you did for the ext3 partition above. Listing 16 illustrates this.
www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html 10/16

Listing 16. Creating an ext4 partition


[ r o o t @ a t t i c 4~ ] #m k f ste x t 4LI A N U S B 3 2/ d e v / s d c 1 m k e 2 f s1 . 4 2 . 3( 1 4 M a y 2 0 1 2 ) F i l e s y s t e ml a b e l = I A N U S B 3 2 O St y p e :L i n u x B l o c ks i z e = 4 0 9 6( l o g = 2 ) F r a g m e n ts i z e = 4 0 9 6( l o g = 2 ) S t r i d e = 0b l o c k s ,S t r i p ew i d t h = 0b l o c k s 1 9 5 7 8 8 8i n o d e s ,7 8 1 6 3 2 4b l o c k s 3 9 0 8 1 6b l o c k s( 5 . 0 0 % )r e s e r v e df o rt h es u p e ru s e r F i r s td a t ab l o c k = 0 M a x i m u mf i l e s y s t e mb l o c k s = 4 2 9 4 9 6 7 2 9 6 2 3 9b l o c kg r o u p s 3 2 7 6 8b l o c k sp e rg r o u p ,3 2 7 6 8f r a g m e n t sp e rg r o u p 8 1 9 2i n o d e sp e rg r o u p S u p e r b l o c kb a c k u p ss t o r e do nb l o c k s : 3 2 7 6 8 ,9 8 3 0 4 ,1 6 3 8 4 0 ,2 2 9 3 7 6 ,2 9 4 9 1 2 ,8 1 9 2 0 0 ,8 8 4 7 3 6 ,1 6 0 5 6 3 2 ,2 6 5 4 2 0 8 , 4 0 9 6 0 0 0 A l l o c a t i n gg r o u pt a b l e s :d o n e W r i t i n gi n o d et a b l e s :d o n e C r e a t i n gj o u r n a l( 3 2 7 6 8b l o c k s ) :d o n e W r i t i n gs u p e r b l o c k sa n df i l e s y s t e ma c c o u n t i n gi n f o r m a t i o n :d o n e [ r o o t @ a t t i c 4~ ] #b l k i d/ d e v / s d c 1 / d e v / s d c 1 :U U I D = " b 3 a 3 c 2 b c e a 8 d 4 0 c 6 9 6 7 e 9 2 7 0 0 6 f 5 5 4 1 6 "T Y P E = " e x t 4 "L A B E L = " I A N U S B 3 2 "

To see all the parameters that you can specify when creating an ext4 partition, consult the man pages for m k f s . e x t 4 . 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 iparameter. 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. Listing 17. Creating an XFS filesystem
[ r o o t @ e c h i d n a~ ] #m k f stx f sis i z e = 5 1 2/ d e v / s d a 8 m k f s . x f s :/ d e v / s d a 8a p p e a r st oc o n t a i na ne x i s t i n gf i l e s y s t e m( x f s ) . m k f s . x f s :U s et h efo p t i o nt of o r c eo v e r w r i t e . [ r o o t @ e c h i d n a~ ] #m k f stx f sfis i z e = 5 1 2/ d e v / s d a 8 m e t a d a t a = / d e v / s d a 8 i s i z e = 5 1 2 a g c o u n t = 4 ,a g s i z e = 2 6 2 2 1 0 8b l k s = s e c t s z = 5 1 2 a t t r = 2 d a t a = b s i z e = 4 0 9 6 b l o c k s = 1 0 4 8 8 4 2 9 ,i m a x p c t = 2 5 = s u n i t = 0 s w i d t h = 0b l k s n a m i n g = v e r s i o n2 b s i z e = 4 0 9 6 a s c i i c i = 0 l o g = i n t e r n a ll o g b s i z e = 4 0 9 6 b l o c k s = 5 1 2 1 ,v e r s i o n = 2 = s e c t s z = 5 1 2 s u n i t = 0b l k s ,l a z y c o u n t = 1 r e a l t i m e= n o n e e x t s z = 4 0 9 6 b l o c k s = 0 ,r t e x t e n t s = 0 [ r o o t @ e c h i d n a~ ] #b l k i d/ d e v / s d a 8 / d e v / s d a 8 :U U I D = " 1 b 6 7 9 8 f 2 f 0 7 f 4 d 5 e a f 0 6 2 4 7 0 d f 3 7 d d b 3 "T Y P E = " x f s "

You can label an XFS system using the Loption with a name. You can use the x f s _ a d m i ncommand with the Loption to add a label to an existing XFS filesystem. Use the loption of x f s _ a d m i nto 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 m k f scommand with the tr e i s e r f soption or the m k r e i s e r f scommand. ReiserFS does not support SELinux and is being replaced by Resier4 You can label a ReiserFS system using the l(or l a b e l option with a name). You can use the r e i s e r f s t u n ecommand 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. Listing 18. Creating a vfat filesystem
[ r o o t @ e c h i d n a~ ] #m k f stv f a t/ d e v / s d a 9 m k f s . v f a t3 . 0 . 9( 3 1J a n2 0 1 0 )

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

11/16

[ r o o t @ e c h i d n a~ ] #b l k i d/ d e v / s d a 9 / d e v / s d a 9 :L A B E L = " "U U I D = " C F 7 2 9 9 A 8 "T Y P E = " v f a t "

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 d o s f s l a b e l 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 m k s w a pcommand as shown in Listing 19. Listing 19. Creating swap space
[ r o o t @ e c h i d n a~ ] #m k s w a p/ d e v / s d a 4 S e t t i n gu ps w a p s p a c ev e r s i o n1 ,s i z e=4 1 9 2 9 6 0K i B n ol a b e l ,U U I D = 8 f 5 a 3 a 0 5 7 3 e f 4 c 7 8 b c 5 6 0 e 9 b 1 b c c 7 f d b

Note that recent versions of m k s w a pshow you the generated UUID. Unlike regular filesystems, swap partitions aren't mounted. Instead, they are enabled using the s w a p o ncommand. 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 c f d i s kor s f d i s kcommands. The c f d i s kcommand provides a more graphical interface than fdisk, using the ncurses library functions as shown in Figure 1. The s f d i s kcommand is intended for programmer use and can be scripted. Use it if you know what you are doing. Figure 1. Using cfdisk

Another popular tool for working with the partition table is p a r t e d , which can resize and format many partition types as well as create and destroy them. While p a r t e dcannot resize NTFS partitions, n t f s r e s i z ecan. The q t p a r t e dtool uses the Qt toolkit to provide a graphical interface. It includes the p a r t e dfunctions as well as n t f s r e s i z efunctions. The g p a r t e dtool is another graphical partitioning tool, designed for the GNOME desktop. It uses the GTK+GUI library, and is shown in Figure 2. (See Resources for links to both q t p a r t e dand g p a r t e d .) You may have to install the above packages in order to use them as they may not be part of your default install. Figure 2. Using gparted

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

12/16

Earlier you saw the g d i s kcommand which is quite similar in operation to f d i s k . Use the g d i s kcommand for GPT disks and the f d i s kcommand for the more traditional MBR layout. Both p a r t e dand g p a r t e dcan 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 m k f s . j f scommand. 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.

Resources Learn Use the developerWorks roadmap for LPIC-1 to find the developerWorks articles to help you study for LPIC-1 certification based on the April 2009 objectives. At the LPIC Program site, find detailed objectives, task lists, and sample questions for the three levels of the Linux Professional Institute's Linux system administration certification. In particular, see their April 2009 objectives for LPI exam 101 and LPI exam 102. Always refer to the LPIC Program site for the latest objectives. Note the Exam 101: Objective Changes as of July 2, 2012. Review the entire LPI exam prep series on developerWorks to learn Linux fundamentals and prepare for system administrator certification based on earlier LPI exam objectives prior to April 2009. Visit the home of the Filesystem Hierarchy Standard (FHS). Learn about the Linux Standard Base (LSB), a Free Standards Group (FSG) project to develop a standard binary operating environment. Learn about the Anatomy of ext4. Learn about the btrfs file system (B-Tree file system). Learn about the Reiser4 file system, the successor to ReiserFS. The Linux Documentation Project has a variety of useful documents, especially its HOWTOs. In the developerWorks Linux zone, find hundreds of how-to articles and tutorials, as well as downloads, discussion forums, and a wealth of other resources
www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html 13/16

for Linux developers and administrators. Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics. Attend a free developerWorks Live! briefing to get up-to-speed quickly on IBM products and tools, as well as IT industry trends. Watch developerWorks on-demand demos ranging from product installation and setup demos for beginners, to advanced functionality for experienced developers. Follow developerWorks on Twitter, or subscribe to a feed of Linux tweets on developerWorks. Get products and technologies Evaluate IBM products in the way that suits you best: Download a product trial, try a product online, use a product in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement Service Oriented Architecture efficiently. Discuss Participate in the discussion forum. Get involved in the developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis. About the author

Ian Shields works on a multitude of Linux projects for the developerWorks Linux zone. He is a Senior Programmer at IBM at the Research Triangle Park, NC. He joined IBM in Canberra, Australia, as a Systems Engineer in 1973, and has since worked on communications systems and pervasive computing in Montreal, Canada, and RTP, NC. He has several patents and has published several papers. His undergraduate degree is in pure mathematics and philosophy from the Australian National University. He has an M.S. and Ph.D. in computer science from North Carolina State University. Learn more about Ian in Ian's profile on developerWorks Community. Close [x]

developerWorks: Sign in
IBM ID: Need an IBM ID? Forgot your IBM ID? Password: Forgot your password? Change your password Keep me signed in. By clicking Submit, you agree to the developerWorks terms of use.
Submit Cancel

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time. All information submitted is secure. Close [x]

Choose your display name


The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks. Please choose a display name between 3-31 characters . Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.
www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html 14/16

Display name:

(Must be between 3 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


Submit Cancel

All information submitted is secure. Average rating (74 votes) 1 star 2 stars 3 stars 4 stars 5 stars
Submit

1 star 2 stars 3 stars 4 stars 5 stars

Add comment: Sign in or register to leave a comment. Note: HTML elements are not supported within comments.

Notify me when a comment is added1000 characters left

Post

Total comments (6)

Show: Most recent comments

I admire the greatness of this article. Thanks for this comprehensive article. It helped me a lot. Posted by valiantvimal on 21 July 2012 Report abuse I noticed that no one responded to ThyagSundaramoorthy. The PDF is working now. It may have had a temporary problem when you went to down load it. (editor) Posted by cmw.osdude on 26 March 2012 Report abuse The pdf file is not downloadable. It is missing Posted by ThyagSundaramoorthy on 04 March 2012 Report abuse At the top of each of the LPI articles is a link to our roadmap (http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-map/index.html). The roadmap has instructions for building your own custom feed. Hope this helps. Posted by ishields on 07 March 2011 Report abuse Is there someway how I can subscribe on articles from you, Ian? Posted by fakeid on 07 March 2011 Report abuse
Print this page Share this page Follow developerWorks

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

15/16

About Help Contact us Submit content

Feeds

Report abuse Terms of use IBM privacy IBM accessibility

Faculty Students Business Partners

www.ibm.com/developerworks/library/l-lpic1-v3-104-1/index.html

16/16

Вам также может понравиться