Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Linux Disk Partitioning

News

Linux Disk Management

Recommended Links

Reference

Suse hard Drive Partitioning during installation

Ext3 filesystem

Filesystem mount options

LVM Linux Logical Volume Snapshots Loopback filesystem Linux Multipath Grub Booting into Rescue Mode Linux Image-based backups and SystemRescueCD
Repartitioning without LVM Formatting partition to ext3 or ext4 /etc/fstab/ How to create partition HP Smart Array P410 controller Recovering Filesystems from corrupted RAID sets Swap file
Managing Disks by ID Managing Partitions by UUID Partition labels udev Linux Swap filesystem Humor Etc

Introduction

Disk partitioning is a complex issue. Due to this it is important to keep it simple. And that means not use LVM if you do not need to (contrary to standard setup in many distributions).

The second important consideration is the ease of recovery for failed system. For example due to crash harddrive or two harddrives in RAID 5 configuration. That consideration suggest minimizing of number partitions and using on large system partition for /, /opt, /usr and /var so that restoration of a single partition restore the OS. By modern harddrive sizes restoration of  OS (approximately 6Gb of data, uncompressed) is very small recovery operation.  This also simplify the usage of Linux recovery tools such Relax-and-Recover  which are pretty fragile and tricky to use if you do not use them constantly (or train yourself periodically to use them, not to forget what you have learned)

You can generally view the partitions that system recognized via fdisk -l. If LVM is used it produced a lot of extra junk messages that need to be filtered, but still information is usable.

On the desktop PC among the typical reasons that the disk is not visible is that you forget to attach power or interface cable or both :-). During installation, you are asked which partitioning method to use. You are generally better off creating a custom layout based on principles outlined below. 

On old (BIOS controlled) disks Linux uses DOS partitioning scheme  with up to four primary partitions in MBR.  In this case I would recommend to use a single partition for all system directories (Windows -style ;-) and a separate partition for /home (and possibly for /tmp). that means that you have the following partitions: swap, home, system and home. If you have multiple drive use separate physical drives for those partitions. On other drives you can use LVM.  You can also use LVM on partions outside system.

With the sizes of modern harddrives there is no real reason to put any system directories on LVM as they are mostly static (OK /tmp can be made a sesparate partiton as sometimes requirement can be quite large). Var does not need to be big as you can always backup files to a different partitions. Loss of old backups from var is actually not critical in most cases.

Total size of installed RHEL typically is around 6GB so allocating, say 32GB, 64 or 128Gb depending on the level of your paranoia look like a pretty safe option even is you install a ton of packages. If you know how the server will be used you can estimate future needs and double them. That virtually guarantee that your root partition will not run out of space during the lifetime of the server. 

In any case, if you need to install some moster package and do not have enough space, you can always move /opt and /usr to a separate partitions. This is a simple and pretty safe operation that can be performed on runlevel 1 without booting server with the rescue disk. As it is difficult to get a rotating  harddrive less than 300GB those days (as rotating harddrives are cheap you should generally always use separate two disks in RIAD 1 configuration for OS, and all other disks for data; that increases survivability of the server. So if you have 4 disk two Raid 1 virtual disks are better then one raid 10 on a RAID controller. Of couse HP managed to scew up raid 1 implementing it as RAID 10 but this is another story.  "Pure" RAID 1 means that each disk can be put into USB enclosure and booted from. 

300 GB 15K RPM hard drive  cost now around $50 (even HP drives are around $100 ;-) .  So there is stupid to use less then four of those in a server.

The key idea of right partitioning from the performance point of view is putting the key partitions such as swap, /, /tmp, /var (but single / can be used )  near the middle of the rotating drive, for example

BTW some Windows backup tools like Acronis True Image understand and can work with Linux ext3/ext4 partitions.

Three primary partitions are usually created directly. They are

  1. /home
  2. swap

---- center of the drive ---

  1. / (root) partition).

For an extended partition traditionally the Logical Volume Manager (LVM) is used to divide the hard drive, and then the necessary Linux mount points are created. Please note that this is a mixed blessing: in case of corruption recovery is more difficult.

Using separate partitions for valuable data is highly prudent as you can use special attributes, such as read-only, nosuid, noexec, etc on such filesystems. But this is a separate topic. 

On desktops for reliability you can use hardware (for example in external USB 3.0 or iSCSI enclosure) or (more problematic) software RAID 1.

Arguments again using /boot as a separate partition

During my career  as a system administrator I encounters at least two very nasty cases when /boot partition was lost. In one case this due a bug in SLES installer which replaced separate /boot partition with the "parallel" directory at root partition during patches install

In the second case it was result of himan error -- corruption of this particular line in /etc/fstab/. It was in RHEL 6 server in which error was done soon (one week) after the installation. Then the server was not rebooted for two years. After reboot (due to datacenter power outage)  partition became non visible, because fstab like for /boot was corrupted (the line was still present but the second field (/boot) was deleted probably in botched attempt to beautify it). Depressingly no errors was generated in this case.

So updates went to /boot directory of root partition, while booting was performed  from hidden /boot partition with the old kernel. 

So it is better not to have such a partition and just use a directory on a non LVM root portion . That helps with other troubleshooting issues as well.

RAID10 on two disks is fools gold

The small amount of performance enhancement that is achievable by "pseudo RAID10" on two disks is negated by loss of reliability: if with RAID 1 disks are usable even if controller failed or lost configuration, disks configured with RAID 10 are not. Moreover sometimes very bad things can happen with RAID 10 configuration on HP Raid controllers, especially with ancient version of firmware on P410i (1.51 or earlier): controller can lose both disks at once by issuing some internal command that wipes that content in case of hot swapping on one disk.

If you do not touch controller then this configuration works well. But if you do touch them your mileage can vary.

First of all HP in its infinite wisdom propose the most aggressive RAID setting. They advocate striping and propose RAID 10 on two disks by default.  But with cache of 256M controller cache the effect is negligible and with 1GB cache might be negative.  But if RAID 1 contains disks that can be read on other server individually, RAID 10 is more complex beast and loss of configuration in controller lead to real disasters.

All RAID levels which offer striping can get into situation when all of the data on the array are lost when more hard drives fail than the redundancy can handle. Or when the controller loses it s RAID configuration. Which is probably most frequent case with P410i. 

Setting up RAID 10 on 2 disks involves additional magic with "Sections" on the drive to speed up sequential reads.  The gain in unclear and can be negative(Non-standard RAID levels - Wikipedia). Generally Raid 10 requires 4 disks with non-standard implementation existing for three (Nested RAID levels - Wikipedia) ?

RAID 10, as recognized by the storage industry association and as generally implemented by RAID controllers, is a RAID 0 array of mirrors, which may be two- or three-way mirrors,[6] and requires a minimum of four drives. However, a nonstandard definition of "RAID 10" was created for the [7] Linux "RAID 10" can be implemented with as few as two disks. Implementations supporting two disks such as Linux RAID 10 offer a choice of layouts.[7] Arrays of more than four disks are also possible.

Another dangerous proposition is RAID 50:

RAID 50, also called RAID 5+0, combines the straight block-level striping of RAID 0 with the distributed parity of RAID 5.[3] As a RAID 0 array striped across RAID 5 elements, minimal RAID 50 configuration requires six drives. On the right is an example where three collections of 120 GB RAID 5s are striped together to make 720 GB of total storage space.

One drive from each of the RAID 5 sets could fail without loss of data; for example, a RAID 50 configuration including three RAID 5 sets can only tolerate three maximum potential drive failures. Because the reliability of the system depends on quick replacement of the bad drive so the array can rebuild, it is common to include hot spares that can immediately start rebuilding the array upon failure. However, this does not address the issue that the array is put under maximum strain reading every bit to rebuild the array at the time when it is most vulnerable.[13]

RAID 50 improves upon the performance of RAID 5 particularly during writes, and provides better fault tolerance than a single RAID level does. This level is recommended for applications that require high fault tolerance, capacity and random access performance. As the number of drives in a RAID set increases, and the capacity of the drives increase, this impacts the fault-recovery time correspondingly as the interval for rebuilding the RAID set increases.[

How you can recover information is it is distributed on two disks. But novice sysadmin do not ask such questions and accept proposed default. 

Generally using some advanced version of RAID without testing the controller capabilities (and reliability) is very dangerous. Only RAID 1 allow space for errors in this respect. Recovery of 300GB disk can easily cost $15K

See HP Smart Array P410 controller for more information.

LVM: to use or not use

LVM offers an important benefit: the ability to resize partitions dynamically as well as combining multiple hard drives into logical physical devices (on enterprise-class servers the latter function typically is also provided by disk controller so it is not really important.), It also allow dynamically expand logical volume by  adding more disks/partitions to it.

LVM can expand a partition while it is mounted, if the filesystem used on it also supports that ( ext3/4 does support this feature).  LVM can move a partition while it is in use, and will not corrupt your data if it is interrupted.  LVM supports snapshots. It allows you freeze an existing Logical Volume in time, at any moment, even while the system is running. You can continue to use the original volume normally, but the snapshot volume appears to be an image of the original, frozen in time at the moment you created it. You can use this to get a consistent filesystem image to back up, without shutting down the system. You can also use it to save the state of the system, so that you can later return to that state if you mess things up. You can even mount the snapshot volume and make changes to it, without affecting the original.

Flexibility with resizing and moving partitions on the fly is really nice. But if reboot is not a problem then the same flexibility can be achieved by using extra USB or, better, eSCSI drive and moving partitions to it, then resizing partitions of the main drive and moving them back. This is more simple,  transparent and as such more reliable scheme of doing the same things.

LVM is not recommended for root partition unless you understand LVM really well, as it complicates recovery of an unbootable system. In this case having the most recent backup on the root filesystem becomes life and death issue. As a intermediate solution /etc can be tarred to /boot on startup. In this case you will have the copy of /etc/with which the system last booted successfully

LVM is not recommended for root partition unless you understand LVM really well. Root partition is relatively static in most configuration

If you are using multipath then LVM hides perversion connected with Linux device mapper -- I really hate this peace of Linux i/o subsystem. Looks like pretty sloppy engineering to me, yet another level of indirection.

To view a list of partitions on the system, use the fdisk -l command as root. If the system uses LVM or RAID, the fdisk -l output will reflect it.

During installation, the hard drives can be partitioned, given a filesystem type for formatting, and assigned a mount point. Here some funny mistakes are possible. If you allocate boot partition and format to give it a mount point, directory /boot in root partition will be used and this partition will remain empty. And to relocate it if you use multipathing is not that easy, so it better to stay as a directory. Actually it no more make sense to have boot as a separate partition as grub can access directories on ext3 and other linux filesystems, so it is better to merge them into a single partition. If hard drives are added to the system after installation or a hard drive has to be replaced, it is important to understand how to perform these functions post-installation.

Note:  Generally due to absence of snapshot functionality in ext3/ext4 you need to rely on LVM for this feature and merging /, usr, and /var into a single large partition in this case became more attractive (just reserve, say 10 GB for snapshot). You can also temporary reassign your swap partition for snapshots space, but this is more involved.

Caution

Creating Partitions

A partition can be created only from free space on a hard drive. If there is no free space one or several partitions should be deleted before new can be created. You might also add a new hard drive to the system.

There are two partitioning utilities in Red Hat Enterprise Linux: parted and fdisk.

The parted utility includes a resize utility, work with GPT partitions and is a bit more user-friendly.  See parted

For smaller disks most older sysadmin still use fdisk. It has support for BSD disk labels and other non-DOS partition tables. For more information for both utilities, see the man pages (man page for parted is simply horrible, and you need to dig into other posts to understand how it works) .

Fdisk usage

Fdisk usage is well described in Linux Partition HOWTO ( Partitioning with fdisk) and Novell article Manually Partitioning Your Hard Drive with fdisk.

Here is the information from the HOWTO:

This section shows you how to actually partition your hard drive with the fdisk utility. Linux allows only 4 primary partitions. You can have a much larger number of logical partitions by sub-dividing one of the primary partitions. Only one of the primary partitions can be sub-divided.

Examples:

  1. Four primary partitions (see Section 5.2)
  2. Mixed primary and logical partitions (see Section 5.3)

5.1. fdisk usage

fdisk is started by typing (as root) fdisk device at the command prompt. device might be something like /dev/hda or /dev/sda (see Section 2.1.1). The basic fdisk commands you need are:

Changes you make to the partition table do not take effect until you issue the write (w) command. Here is a sample partition table:

Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
 
   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1   *         1       184    370912+  83  Linux
/dev/hdb2           185       368    370944   83  Linux
/dev/hdb3           369       552    370944   83  Linux
/dev/hdb4           553       621    139104   82  Linux swap
The first line shows the geometry of your hard drive. It may not be physically accurate, but you can accept it as though it were. The hard drive in this example is made of 32 double-sided platters with one head on each side (probably not true). Each platter has 621 concentric tracks. A 3-dimensional track (the same track on all disks) is called a cylinder. Each track is divided into 63 sectors. Each sector contains 512 bytes of data. Therefore the block size in the partition table is 64 heads * 63 sectors * 512 bytes er...divided by 1024. (See 4 for discussion on problems with this calculation.) The start and end values are cylinders.

5.2. Four primary partitions

The overview:

Decide on the size of your swap space (see Section 4.4) and where it ought to go (see Section 4.4.3). Divide up the remaining space for the three other partitions.

Example:

I start fdisk from the shell prompt:

# fdisk /dev/hdb 
which indicates that I am using the second drive on my IDE controller. (See Section 2.1.) When I print the (empty) partition table, I just get configuration information.
Command (m for help): p

Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
I knew that I had a 1.2Gb drive, but now I really know: 64 * 63 * 512 * 621 = 1281982464 bytes. I decide to reserve 128Mb of that space for swap, leaving 1153982464. If I use one of my primary partitions for swap, that means I have three left for ext2 partitions. Divided equally, that makes for 384Mb per partition. Now I get to work.
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-621, default 1):<RETURN>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-621, default 621): +384M
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (197-621, default 197):<RETURN>
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M
Now the partition table looks like this:
   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1             1       196    395104   83  Linux
/dev/hdb2           197       262    133056   83  Linux
I set up the remaining two partitions the same way I did the first. Finally, I make the first partition bootable:
Command (m for help): a
Partition number (1-4): 1
And I make the second partition of type swap:
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap)      
Command (m for help): 
	The end result:	
				
Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
 
   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1   *         1       196    395104+  83  Linux
/dev/hdb2           197       262    133056   82  Linux swap
/dev/hdb3           263       458    395136   83  Linux
/dev/hdb4           459       621    328608   83  Linux          
Finally, I issue the write command (w) to write the table on the disk.

Side topics:

5.3. Mixed primary and logical partitions

The overview: create one use one of the primary partitions to house all the extra partitions. Then create logical partitions within it. Create the other primary partitions before or after creating the logical partitions.

Example:

I start fdisk from the shell prompt:

# fdisk /dev/sda
which indicates that I am using the first drive on my SCSI chain. (See Section 2.1.)

First I figure out how many partitions I want. I know my drive has a 183Gb capacity and I want 26Gb partitions (because I happen to have back-up tapes that are about that size).

183Gb / 26Gb = ~7

so I will need 7 partitions. Even though fdisk accepts partition sizes expressed in Mb and Kb, I decide to calculate the number of cylinders that will end up in each partition because fdisk reports start and stop points in cylinders. I see when I enter fdisk that I have 22800 cylinders.

> The number of cylinders for this disk is set to 22800.  There is
> nothing wrong with that, but this is larger than 1024, and could in
> certain setups cause problems with: 1) software that runs at boot
> time (e.g., LILO) 2) booting and partitioning software from other
> OSs  (e.g., DOS FDISK, OS/2 FDISK)
So, 22800 total cylinders divided by seven partitions is 3258 cylinders. Each partition will be about 3258 cylinders long. I ignore the warning msg because this is not my boot drive (Section 4).

Since I have 4 primary partitions, 3 of them can be 3258 long. The extended partition will have to be (4 * 3258), or 13032, cylinders long in order to contain the 4 logical partitions.

I enter the following commands to set up the first of the 3 primary partitions (stuff I type is bold ):

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-22800, default 1): <RETURN>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-22800, default 22800): 3258
Partition number (1-4): 4
First cylinder (9775-22800, default 9775): <RETURN>
Using default value 9775
Last cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): <RETURN>
Using default value 22800
/dev/sda1             1      3258  26169853+  83  Linux
/dev/sda2          3259      6516  26169885   83  Linux
/dev/sda3          6517      9774  26169885   83  Linux
/dev/sda4          9775     22800 104631345    5  Extended
Next I segment the extended partition into 4 logical partitions, starting with the first logical partition, into 3258-cylinder segments. The logical partitions automatically start from /dev/sda5.
Command (m for help):  n
First cylinder (9775-22800, default 9775): <RETURN>
Using default value 9775
Last cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): 13032
The end result is: nt color="#000000">
   Device Boot    Start       End    Blocks   Id  System
/dev/sda1             1      3258  26169853+  83  Linux
/dev/sda2          3259      6516  26169885   83  Linux
/dev/sda3          6517      9774  26169885   83  Linux
/dev/sda4          9775     22800 104631345    5  Extended
/dev/sda5          9775     13032  26169853+  83  Linux
/dev/sda6         13033     16290  26169853+  83  Linux
/dev/sda7         16291     19584  26459023+  83  Linux
/dev/sda8         19585     22800  25832488+  83  Linux
Finally, I issue the write command (w) to write the table on the disk. To make the partitions usable, I will have to format (Section 10.1) each partition and then mount (Section 10.3) it.

5.4. Submitted Examples

I'd like to submit my partition layout, because it works well with any distribution of Linux (even big RPM based ones). I have one hard drive that ... is 10 gigs, exactly. Windows can't see above 9.3 gigs of it, but Linux can see it all, and use it all. It also has much more than 1024 cylenders.

Table 7. Partition layout example
Partition Mount point Size
/dev/hda1 /boot (15 megs)
/dev/hda2 windows 98 partition (2 gigs)
/dev/hda3 extended (N/A)
/dev/hda5 swap space (64 megs)
/dev/hda6 /tmp (50 megs)
/dev/hda7 / (150 megs)
/dev/hda8 /usr (1.5 gigs)
/dev/hda9 /home (rest of drive)

I test new kernels for the USB mass storage, so that explains the large /boot partition. I install LILO into the MBR, and by default I boot windows (I'm not the only one to use this computer).

I also noticed that you don't have any REAL examples of partition tables, and for newbies I HIGHLY suggest putting quite a few up. I'm freshly out of the newbie stage, and partitioning was what messed me up the most.

Creating a Filesystem on a Partition

Next, create a filesystem on the partition. To create an ext3 filesystem (default used during installation), as root, execute the following, where <device> is the device name for the partition such as /dev/sda1:

The utility to do it is called mkfs

mkfs -t ext3 /dev/vg02/data 

If the partition is to be a swap partition, format it with the following command as root:

mkswap <device>

Labeling the Partition

To label the partition, execute the following as root:

e2label <device> <label>

While labeling is not required, partition labels are very useful. For example, when adding the partition to /etc/fstab, the label can be listed instead of the partition device name. This proves useful if the partition number is changed from repartitioning the drive or if the partition is moved.

If the e2label command is used with just the partition device name as an argument, the current label for the partition is displayed.

Creating a Mount Point

Now that the partition is created and has a filesystem, as root, create a directory so it can be mounted:

mkdir <dir-name>

Then, mount the new partition:

mount <device> <dir-name>

such as:

mount /dev/sda5 /data

Access the directory and make sure you can read and write to it.

Finally, add the partition to the /etc/fstab file so it is mounted automatically at boot time. For example:

LABEL=data                 /data                 ext3    defaults        1 2

If a new swap partition is added, be sure to use swap as the filesystem type instead:

LABEL=swap2             swap                    swap    defaults        0 0

Note:

If you move content of the directory to a new partition and then mount this parition on this directory, you need to delete files inside the directory. It is easy to damage the system while trying to delete files from this existing subdirectory. Beware of the side effectsof commans like rm -rf .* or mv -rf .* /newmount

You might benefit from rereading relevant part of Sysadmin Horror Stories

Check results

To check results you can use df command:

# df -h /data 
Filesystem Size Used Avail Use% Mounted on 
/dev/mapper/test--volume-data 
50.0G 33M 5.0G 1% /data

Add it to /etc/fstab

You can create shell function to simplify this task if you need to create many similar partitions like is often the case with Oracle databases. For example:

# Create oracle archive filesystem 
# Parameters: 
# 1 - name of archive 
# 2 - size in gigabytes 
# 3 - name of logical volume (default lv0) 
function make_archive 
{ 
 mkdir -p  /oracle/$1/archive 
 chown oracle:dba /oracle/$1/archive 
 lvcreate -L ${2}G -n archive vg0 
 mkfs -t ext3 /dev/vg0/archive 
 echo "/dev/$3/archive /oracle/$1/archive ext2 defaults 1 2" >> /etc/fstab 
 mount /oracle/$1/archive # that will check the mount point if fstab 
 df -k
}

Resizing Partitions

The simplest way to resize a partition is to make a backup, delete that original partition, create two or more in place of the original and then restore the partition. This is also the safest way.

The parted utility can be used to resize a partition directly with data in it. It is still recommended to make a backup just in case. After all its your data.

You can use use the following command to resize a specific partition (need to be root for obvious reasons):

resize <minor-num> <start> <end>

To determine the <minor-num> for the partition, look at the partition table with the print subcommand of the fdisk command or directly from parted. The <start> and <end> values should be the start and end points of the partition, in megabytes.

Removing Partitions

To use parted to remove a partition, start parted on the desired device as root, and issue the following command at the interactive prompt:

rm <minor-num>

The minor number for the partition is displayed when you execute the print command to list partitions. The data on the partition will no longer be accessible after the partition is removed, so be sure to back up any data you want to keep before removing the partition.

References

The Linux System Administrator's Guide contains several chapters on this theme:

4. Hardware, Devices, and Tools
4.1. Hardware Utilities
4.2. Kernel Modules
5. Using Disks and Other Storage Media
5.1. Two kinds of devices
5.2. Hard disks
5.3. Storage Area Networks - Draft
5.4. Network Attached Storage - Draft
5.5. Floppies
5.6. CD-ROMs
5.7. Tapes
5.8. Formatting
5.9. Partitions
5.10. Filesystems
5.11. Disks without filesystems
5.12. Allocating disk space

Linux Newbie Guide by Stan, Peter and Marie Klimas contains chapter 4.2 about drives

Part 4.2: Drives
Where are my drives, how to access them, configure user access, get the zip drive recognized, set 32-bit hard drive IO, increase the limit on the number of opened files, add a new hardrive, manage the swap space ...


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Jun 12, 2021] 7 'dmesg' Commands for Troubleshooting and Collecting Information of Linux Systems

Jun 09, 2021 | www.tecmint.com

List all Detected Devices

To discover which hard disks has been detected by kernel, you can search for the keyword " sda " along with " grep " like shown below.

[[email protected] ~]# dmesg | grep sda

[    1.280971] sd 2:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB)
[    1.281014] sd 2:0:0:0: [sda] Write Protect is off
[    1.281016] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    1.281039] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    1.359585]  sda: sda1 sda2 < sda5 sda6 sda7 sda8 >
[    1.360052] sd 2:0:0:0: [sda] Attached SCSI disk
[    2.347887] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[   22.928440] Adding 3905532k swap on /dev/sda6.  Priority:-1 extents:1 across:3905532k FS
[   23.950543] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
[   24.134016] EXT4-fs (sda5): mounted filesystem with ordered data mode. Opts: (null)
[   24.330762] EXT4-fs (sda7): mounted filesystem with ordered data mode. Opts: (null)
[   24.561015] EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts: (null)

NOTE : The "˜sda' first SATA hard drive, "˜sdb' is the second SATA hard drive and so on. Search with "˜hda' or "˜hdb' in the case of IDE hard drive.

[May 06, 2020] Creating and managing partitions in Linux with parted Enable Sysadmin by Tyler Carrigan

Apr 30, 2020 | www.redhat.com

Red Hat Sysddmin

Listing partitions with parted

The first thing that you want to do anytime that you need to make changes to your disk is to find out what partitions you already have. Displaying existing partitions allows you to make informed decisions moving forward and helps you nail down the partition names will need for future commands. Run the parted command to start parted in interactive mode and list partitions. It will default to your first listed drive. You will then use the print command to display disk information.

[root@rhel ~]# parted /dev/sdc
    GNU Parted 3.2
    Using /dev/sdc
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print                                                            
    Error: /dev/sdc: unrecognised disk label
    Model: ATA VBOX HARDDISK (scsi)                                           
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: unknown
    Disk Flags:
    (parted)

Creating new partitions with parted

Now that you can see what partitions are active on the system, you are going to add a new partition to /dev/sdc . You can see in the output above that there is no partition table for this partition, so add one by using the mklabel command. Then use mkpart to add the new partition. You are creating a new primary partition using the ext4 architecture. For demonstration purposes, I chose to create a 50 MB partition.

(parted) mklabel msdos                                                    
    (parted) mkpart                                                           
    Partition type?  primary/extended? primary                                
    File system type?  [ext2]? ext4                                           
    Start? 1                                                                  
    End? 50                                                                   
    (parted)                                                                  
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  50.3MB  49.3MB  primary  ext4         lba

Modifying existing partitions with parted

Now that you have created the new partition at 50 MB, you can resize it to 100 MB, and then shrink it back to the original 50 MB. First, note the partition number. You can find this information by using the print command. You are then going to use the resizepart command to make the modifications.

(parted) resizepart                                                       
    Partition number? 1                                                       
    End?  [50.3MB]? 100                                                       
        
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End    Size    Type     File system  Flags
     1      1049kB  100MB  99.0MB  primary

You can see in the above output that I resized partition number one from 50 MB to 100 MB. You can then verify the changes with the print command. You can now resize it back down to 50 MB. Keep in mind that shrinking a partition can cause data loss.

    (parted) resizepart                                                       
    Partition number? 1                                                       
    End?  [100MB]? 50                                                         
    Warning: Shrinking a partition can cause data loss, are you sure you want to
    continue?
    Yes/No? yes                                                               
    
    (parted) print
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  50.0MB  49.0MB  primary

Removing partitions with parted

Now, let's look at how to remove the partition you created at /dev/sdc1 by using the rm command inside of the parted suite. Again, you will need the partition number, which is found in the print output.

NOTE: Be sure that you have all of the information correct here, there are no safeguards or are you sure? questions asked. When you run the rm command, it will delete the partition number you give it.

    (parted) rm 1                                                             
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start  End  Size  Type  File system  Flags

[Nov 02, 2019] Raid-5 is obsolete if you use large drives , such as 2TB or 3TB disks. You should instead use raid-6 ( two disks can fail)

Notable quotes:
"... RAID5 can survive a single drive failure. However, once you replace that drive, it has to be initialized. Depending on the controller and other things, this can take anywhere from 5-18 hours. During this time, all drives will be in constant use to re-create the failed drive. It is during this time that people worry that the rebuild would cause another drive near death to die, causing a complete array failure. ..."
"... If during a rebuild one of the remaining disks experiences BER, your rebuild stops and you may have headaches recovering from such a situation, depending on controller design and user interaction. ..."
"... RAID5 + a GOOD backup is something to consider, though. ..."
"... Raid-5 is obsolete if you use large drives , such as 2TB or 3TB disks. You should instead use raid-6 ..."
"... RAID 6 offers more redundancy than RAID 5 (which is absolutely essential, RAID 5 is a walking disaster) at the cost of multiple parity writes per data write. This means the performance will be typically worse (although it's not theoretically much worse, since the parity operations are in parallel). ..."
Oct 03, 2019 | hardforum.com

RAID5 can survive a single drive failure. However, once you replace that drive, it has to be initialized. Depending on the controller and other things, this can take anywhere from 5-18 hours. During this time, all drives will be in constant use to re-create the failed drive. It is during this time that people worry that the rebuild would cause another drive near death to die, causing a complete array failure.

This isn't the only danger. The problem with 2TB disks, especially if they are not 4K sector disks, is that they have relative high BER rate for their capacity, so the likelihood of BER actually occurring and translating into an unreadable sector is something to worry about.

If during a rebuild one of the remaining disks experiences BER, your rebuild stops and you may have headaches recovering from such a situation, depending on controller design and user interaction.

So i would say with modern high-BER drives you should say:

So essentially you'll lose one parity disk alone for the BER issue. Not everyone will agree with my analysis, but considering RAID5 with today's high-capacity drives 'safe' is open for debate.

RAID5 + a GOOD backup is something to consider, though.

  1. So you're saying BER is the error count that 'escapes' the ECC correction? I do not believe that is correct, but i'm open to good arguments or links.

    As i understand, the BER is what prompt bad sectors, where the number of errors exceed that of the ECC error correcting ability; and you will have an unrecoverable sector (Current Pending Sector in SMART output).

    Also these links are interesting in this context:

    http://blog.econtech.selfip.org/200...s-not-fully-readable-a-lawsuit-in-the-making/

    The short story first: Your consumer level 1TB SATA drive has a 44% chance that it can be completely read without any error. If you run a RAID setup, this is really bad news because it may prevent rebuilding an array in the case of disk failure, making your RAID not so Redundant. Click to expand...
    Not sure on the numbers the article comes up with, though.

    Also this one is interesting:
    http://lefthandnetworks.typepad.com/virtual_view/2008/02/what-does-data.html

    BER simply means that while reading your data from the disk drive you will get an average of one non-recoverable error in so many bits read, as specified by the manufacturer. Click to expand...
    Rebuilding the data on a replacement drive with most RAID algorithms requires that all the other data on the other drives be pristine and error free. If there is a single error in a single sector, then the data for the corresponding sector on the replacement drive cannot be reconstructed, and therefore the RAID rebuild fails and data is lost. The frequency of this disastrous occurrence is derived from the BER. Simple calculations will show that the chance of data loss due to BER is much greater than all other reasons combined. Click to expand...
    These links do suggest that BER works to produce un-recoverable sectors, and not 'escape' them as 'undetected' bad sectors, if i understood you correctly.
  1. parityOCP said:
    That's guy's a bit of a scaremonger to be honest. He may have a point with consumer drives, but the article is sensationalised to a certain degree. However, there are still a few outfits that won't go past 500GB/drive in an array (even with enterprise drives), simply to reduce the failure window during a rebuild. Click to expand...
    Why is he a scaremonger? He is correct. Have you read his article? In fact, he has copied his argument from Adam Leventhal(?) that was one of the ZFS developers I believe.

    Adam's argument goes likes this:
    Disks are getting larger all the time, in fact, the storage increases exponentially. At the same time, the bandwidth is increasing not that fast - we are still at 100MB/sek even after decades. So, bandwidth has increased maybe 20x after decades. While storage has increased from 10MB to 3TB = 300.000 times.

    The trend is clear. In the future when we have 10TB drives, they will not be much faster than today. This means, to repair an raid with 3TB disks today, will take several days, maybe even one week. With 10TB drives, it will take several weeks, maybe a month.

    Repairing a raid stresses the other disks much, which means they can break too. Experienced sysadmins reports that this happens quite often during a repair. Maybe because those disks come from the same batch, they have the same weakness. Some sysadmins therefore mix disks from different vendors and batches.

    Hence, I would not want to run a raid with 3TB disks and only use raid-5. During those days, if only another disk crashes you have lost all your data.

    Hence, that article is correct, and he is not a scaremonger. Raid-5 is obsolete if you use large drives, such as 2TB or 3TB disks. You should instead use raid-6 (two disks can fail). That is the conclusion of the article: use raid-6 with large disks, forget raid-5. This is true, and not scaremongery.

    In fact, ZFS has therefore something called raidz3 - which means that three disks can fail without problems. To the OT: no raid-5 is not safe. Neither is raid-6, because neither of them can not always repair nor detect corrupted data. There are cases when they dont even notice that you got corrupted bits. See my other thread for more information about this. That is the reason people are switching to ZFS - which always CAN detect and repair those corrupted bits. I suggest, sell your hardware raid card, and use ZFS which requires no hardware. ZFS just uses JBOD.

    Here are research papers on raid-5, raid-6 and ZFS and corruption:
    http://hardforum.com/showpost.php?p=1036404173&postcount=73

  1. brutalizer said:
    The trend is clear. In the future when we have 10TB drives, they will not be much faster than today. This means, to repair an raid with 3TB disks today, will take several days, maybe even one week. With 10TB drives, it will take several weeks, maybe a month. Click to expand...
    While I agree with the general claim that the larger HDDs (1.5, 2, 3TBs) are best used in RAID 6, your claim about rebuild times is way off.

    I think it is not unreasonable to assume that the 10TB drives will be able to read and write at 200 MB/s or more. We already have 2TB drives with 150MB/s sequential speeds, so 200 MB/s is actually a conservative estimate.

    10e12/200e6 = 50000 secs = 13.9 hours. Even if there is 100% overhead (half the throughput), that is less than 28 hours to do the rebuild. It is a long time, but it is no where near a month! Try to back your claims in reality.

    And you have again made the false claim that "ZFS - which always CAN detect and repair those corrupted bits". ZFS can usually detect corrupted bits, and can usually correct them if you have duplication or parity, but nothing can always detect and repair. ZFS is safer than many alternatives, but nothing is perfectly safe. Corruption can and has happened with ZFS, and it will happen again.

Is RAID5 safe with Five 2TB Hard Drives ? | [H]ard|Forum Your browser indicates if you've visited this link

https://hardforum.com /threads/is-raid5-safe-with-five-2tb-hard-drives.1560198/

Hence, that article is correct, and he is not a scaremonger. Raid-5 is obsolete if you use large drives , such as 2TB or 3TB disks. You should instead use raid-6 ( two disks can fail). That is the conclusion of the article: use raid-6 with large disks, forget raid-5 . This is true, and not scaremongery.

RAID 5 Data Recovery How to Rebuild a Failed RAID 5 - YouTube

RAID 5 vs RAID 10: Recommended RAID For Safety and ... Your browser indicates if you've visited this link

https://www.cyberciti.biz /tips/raid5-vs-raid-10-safety-performance.html

RAID 6 offers more redundancy than RAID 5 (which is absolutely essential, RAID 5 is a walking disaster) at the cost of multiple parity writes per data write. This means the performance will be typically worse (although it's not theoretically much worse, since the parity operations are in parallel).

Unix-Linux Disk Partitioning Guide

Until around 2008, there was very little to gain by not using a standard layout. However modern systems now support many per-filesystem features, including security and robustness related mount options such as preventing SUID (or even executables) on data-only filesystems. Today there is little to be gained by limiting the number of filesystems you create to 5 or so, merely to satisfy a historical limit. Using logical volume management, one can create as many filesystems as makes sense in a given situation.

Standard Unix systems are traditionally limited to 8 slices per disk, some of which have pre-defined uses. So standard Unix and Solaris disk layouts for many years worked around that limit by using best practices that didn't need more. However modern Unix systems (including Solaris 10) allows for a form of logical volume management, either with ZFS pools or by using Solaris Volume Management (SVM). So you shouldn't be afraid to define additional filesystems if they do make sense.

Of course just because you can partition a disk doesn't mean you should! The more partitions you create, the more there is to manage. If you guess wrong on the space required, you may have to later grow a partition (not the big deal it used to be). So you shouldn't make extra partitions unless you consider the extra work they create to be worth the additional protections they provide.

Here are some reasons to create extra partitions. If you choose not to follow some vendor-recommended standard disk layout, see which of these apply to your situation to decide which partitions to create:

Some reasons not to partition a disk include:

When Things Go Wrong

A problem with having many partitions is that you can run out of space in one partition while another has excess capacity. When the partition plan fails you may have to create a new plan, backup all existing data in archives, re-format the disk, and restore all the data. Obviously this should be avoided if at all possible. (Newer partitioning tools such as a live CD for gparted makes it much easier to modify a disk layout.) One commonly used technique to handle this situation is to use symbolic links rather than re-partition. Suppose for example you need to install a nifty word processor application in /opt/nifty, only the /opt partition (which might be the root partition) doesn't have enough free space. How annoying! But if /var partition does have extra space, you can create a symlink to use it:
# mkdir /var/nifty; ln -s /var/nifty /opt/nifty

The problem with this approach is that too many such symlinks (sometimes referred to as a symlink farm) can make maintenance difficult. Quotas, backups, logging, and monitoring can all be affected. So adding such symlinks should be considered a hack and not a substitute for proper planning.

Modern Unix systems have virtual partitions called logical volumes or LVM. A logical volume should be thought of the same way traditional partitions and slices are. However, a volume can be composed of one or more physical partitions, possibly on separate drives. When a volume runs out of space, you can just add more disk space to an existing volume to grow it. Then any filesystem in that volume can be grown as well. Although logical volumes may be grown (or shrunk) much more easily than with traditional partitions, using volumes well still requires careful planning of both the logical partitions and the underlying physical partitions. (See about LVM for more information.)

Sizing Partitions

A frequently asked question is how large should the XYZ partition be? Unfortunately there is no simple answer. Consider a partition for /var/log. This needs to be sized to hold your logging data. But how much data is stored? If you have a central log server (loghost) you may not store any log data on some other host. Otherwise you may need to store only a little log data (say for a printer server, anonymous FTP server, or a static content web server). But if this host is your central log server or if you don't have a central log server and plan to keep 6 months of log data on-line, you will need a lot more space than a host that only keeps 1-4 days of log data. So the size might be zero, less than 50 megabytes, or more than 10 gigabytes (or more; consider Apache access logs on a busy server).

Other partitions have similar considerations. You may need no separate partition at all, a very small one, or a huge one. If you have a separate partition for your database files, how much data do you plan to keep on-line? For a web server's files, is this a home user's hobby web server, or a training site with gigabytes of video clips? If you don't have a separate partition to hold crash dumps these end up in the swap partition, so that must be at least as big as your physical RAM. (This is needed to support hibernate too.)

Consider sizing partitions on a mail server. The critical partition will be the one holding the user's mail. This may be stored in mailbox files in /var/mail or within the users' home directories. Or even elsewhere in a database. You need to estimate how much email will be kept on-line by your users, and also allow enough space for spam or a sudden burst of email traffic (or storage over a break between semesters, when faculty rarely log in to read email). A good guideline might be to use the same size limits per user as some other email servers, such as Yahoo! mail or Google's gmail. (If you can afford such large disks as Google.) So, how large is the sum of your mailbox sizes? Whatever it is, add sufficient space for growth and multiple by the expected number of users. At HCC, it might be reasonable to expect 10 MiB per student, and 100,000 students (counting current, future, and past students), or one TiB total.

If using some sort of LVM, it is usually not difficult to grow and shrink partitions later so there is little reason to worry about getting the size wrong. Still you should be able to make a reasonable estimate on the initial size of your partitions:

A final consideration is that there are modern alternatives to per server disks (or DAS). Using storage technologies such as NAS and SAN may mean your servers have no disks or just a small disk for booting only. Even with these technologies you still need to plan the number and purpose of filesystems. Organizing your storage well depends on available budget, technology, and local expertise.

Planning Disk Layouts

If you plan to use Solaris live upgrade, you must duplicate all slices that contain files added by the installer/patch manager. If you use mirrored disks there is no problem but on a single disk you must either keep all system standard paths on the root slice or duplicate both / (root), /var, and so on. Thus, best advice is to not sub-partition any standard paths in /var or /usr. It is okay to create new directories such as /website and make those separate slices.

The best advice today is to keep the boot disk small and simple, using a standard layout. (But not the default layout for Solaris 10, it is known to not work as of 4/2008 for most disks!) Use other disks (or use a SAN or NAS if possible) for additional filesystems as needed. Keep in mind the max number of partitions possible on a disk for a given OS.

If you only have one disk (possibly because you're using hardware RAID), the most flexible disk map will reserve one slice/partition for LVM. Then you can create additional filesystems later as needed without re-formatting the disk.

Tools for partitioning

Tools for partitioning DOS/MBR disks include fdisk, cfdisk (like fdisk but with a curses UI), sfdisk (scriptable fdisk replacement that does more), format, Disk Druid, parted, gparted, and qtparted, fips.exe (A DOS program, used to split a FAT partition into two. Then, delete the 2nd partition, and use the freed space for Linux), and Partition Magic. A live CD/USB for this (works with NFTS but not LVM) is gparted.sourceforge.net.

Only a few of those tools have been updated to support EFI/GPT disks. However you can use gdisk, cgdisk, and sgdisk for such disks.

If the partition table on a disk gets corrupted (and you don't have a backup) you can use gpart (not [g]parted) to scan a disk and guess the partition map. This be then be written to the MBR to recover the disk.

Choosing number and type of partitions: 16MB for swap (minimum), rest for / (a.k.a. the root disk). Reasons for extra partitions as discussed above include security, quotas, and backups. Older motherboards' BIOS has 1024 cylinder limit to locate bootable partitions, so make small (~24-150 MiB) bootable partition near front of disk: /boot (Linux), /kernel (Solaris), or /stand (BSD). Consider /tmp, /var, /var/log, and /home, for separate partitions. (Show on YborStudent: df -h.)

One of the most critical decisions when installing Unix or Linux is how to best make use of limited disk space. Even with today's large hard disks, servers with hundreds of gigabytes of pictures, video, sound, database, and other data are common. Multi-user machines may require protection such as read-only partitions, disk quotas, etc. Sizing partitions is not easy, and there are few standard answers. Make swap at least as large as the physical RAM. /tmp should be ≥1.5 the amount of virtual memory. (Often, a RAM disk is used for that instead.)

Partitioning Scheme Documentation

A partitioning scheme (commonly called a partition map, partition plan, or disk layout) for your system must be well documented or it is useless. Later on you will need to refer to this information and it may be difficult to recall details six or twelve months from now.

Your partition map should be neatly typed and include a description of your disk partitioning map and the scenario it is based on. (That is the scenario might be this is a partitioning map for an at-home workstation, ... for a web server, ... for a multi-user development platform, etc.)

You must justify the choices you make. (For example, for a student server: We have 5 classes of less than 30 students each, and low graphic web pages, Perl scripts, and general Unix shell scripting means each student is likely to need less than 5 MiB, so /home needs 30 * 5 * 5MiB = 750MiB minimum, and to allow room for additional classes in the future 1GiB will be used.)

[Nov 22, 2012] Re-read The Partition Table Without Rebooting Linux System by nixCraf

May 8, 2006 | nixCraf | 25 comments

If you are using hot swappable hard disk and created new partition using fdisk then you need to reboot Linux based system to get partition recognized. Without reboot you will NOT able to create filesystem on your newly created or modified partitions with the mke2fs command.

However with partprobe command you should able to create a new file system without rebooting the box. It is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.

After the fdisk command session (which makes changes to partition table) just type the following command:
# partprobe
OR
# partprobe /dev/sdX
Replace /dev/sdX or /dev/hdX with actual device name. Now you will able to create filesystem on new partition with the mke2fs command.

[Aug 12, 2010] Learn Linux, 101 Create partitions 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 Listing 1.


Listing 1. Linux block and character devices
[ian@echidna ~]$ ls -l /dev/loop1 /dev/null /dev/sd[ab] /dev/sr0 /dev/tty0
brw-rw----. 1 root disk   7,  1 2010-06-14 07:25 /dev/loop1
crw-rw-rw-. 1 root root   1,  3 2010-06-14 07:25 /dev/null
brw-rw----. 1 root disk   8,  0 2010-06-14 07:25 /dev/sda
brw-rw----. 1 root disk   8, 16 2010-06-14 07:25 /dev/sdb
brw-rw----+ 1 root cdrom 11,  0 2010-06-14 07:25 /dev/sr0
crw--w----. 1 root root   4,  0 2010-06-14 07:25 /dev/tty0

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. Listing 2 shows the partitions on the primary hard drives of two of my systems.


Listing 2. Listing partitions with fdisk
                    
[root@attic4 ~]# fdisk -l /dev/sda

Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00064a1a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         127     1020096   83  Linux
/dev/sda2             128        1402    10241437+  82  Linux swap / Solaris
/dev/sda3   *       46340       56538    81920000   83  Linux
/dev/sda4            1403       46339   360956422    5  Extended
/dev/sda5            1403       10420    72437053+  83  Linux


.... .... 

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 Listing 3.


Listing 3. Starting interactive fdisk
                    
knoppix@Microknoppix:~$ su -
root@Microknoppix:~# fdisk /dev/sda

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): 

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


Listing 4. Help in fdisk
&n
                    
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   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   extra functionality (experts only)

Command (m for help):

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


Listing 5. Displaying the existing partition table
                    
Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9634        9730      779152+  83  Linux
/dev/sda3            9731      116679   859067842+   5  Extended
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux

Command (m for help): 

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 Listing 6.

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (9112-121601, default 9112): 
Using default value 9112
Last cylinder, +cylinders or +size{K,M,G} (9112-9633, default 9633): +521

Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9634        9730      779152+  83  Linux
/dev/sda3            9731      116679   859067842+   5  Extended
/dev/sda4            9112        9633     4192965   83  Linux
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux

Partition table entries are not in disk order

Command (m for help): 

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 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 Listing 7.


Listing 7. Creating our data partitions
                    
Command (m for help): n
First cylinder (53906-116679, default 53906): 
Using default value 53906
Last cylinder, +cylinders or +size{K,M,G} (53906-116679, default 116679): +40G

Command (m for help): n
First cylinder (59129-116679, default 59129): 
Using default value 59129
Last cylinder, +cylinders or +size{K,M,G} (59129-116679, default 116679): +2000M

Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9634        9730      779152+  83  Linux
/dev/sda3            9731      116679   859067842+   5  Extended
/dev/sda4            9112        9633     4192965   83  Linux
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux
/dev/sda8           53906       59128    41953716   83  Linux
/dev/sda9           59129       59384     2056288+  83  Linux

Partition table entries are not in disk order

Command (m for help): 

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 Listing 8.


Listing 8. Changing partition types
                    
Command (m for help): t
Partition number (1-9): 4
Hex code (type L to list codes): 82
Changed system type of partition 4 to 82 (Linux swap / Solaris)

Command (m for help): t
Partition number (1-9): 9
Hex code (type L to list codes): b
Changed system type of partition 9 to b (W95 FAT32)

Command (m for help): 

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 Listing 9. 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.


Listing 9. Saving the partition table
                    
Command (m for help): v
999521580 unallocated 512-byte sectors

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
root@Microknoppix:~# fdisk -l /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9634        9730      779152+  83  Linux
/dev/sda3            9731      116679   859067842+   5  Extended
/dev/sda4            9112        9633     4192965   82  Linux swap / Solaris
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux
/dev/sda8           53906       59128    41953716   83  Linux
/dev/sda9           59129       59384     2056288+   b  W95 FAT32

Partition table entries are not in disk order

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 Listing 10. 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.


Listing 10. Fixing the partition table order.
Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9634        9730      779152+  83  Linux
/dev/sda3            9731      116679   859067842+   5  Extended
/dev/sda4            9112        9633     4192965   82  Linux swap / Solaris
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux
/dev/sda8           53906       59128    41953716   83  Linux
/dev/sda9           59129       59384     2056288+   b  W95 FAT32

Partition table entries are not in disk order

Command (m for help): x

Expert command (m for help): f
Done.

Expert command (m for help): r

Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9111    73184076    7  HPFS/NTFS
/dev/sda2            9112        9633     4192965   82  Linux swap / Solaris
/dev/sda3            9634        9730      779152+  83  Linux
/dev/sda4            9731      116679   859067842+   5  Extended
/dev/sda5            9731       20917    89859546   83  Linux
/dev/sda6           20918       39644   150424596   83  Linux
/dev/sda7           39645       53905   114551451   83  Linux
/dev/sda8           53906       59128    41953716   83  Linux
/dev/sda9           59129       59384     2056288+   b  W95 FAT32

Command (m for help): 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.

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 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 is used as the default filesystem on a number of distributions. 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 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 Listing 11.


Listing 11. Filesystem creation commands
                    
[ian@echidna ~]$ ls /sbin/mk*
/sbin/mkdosfs      /sbin/mkfs.ext2     /sbin/mkfs.ntfs
/sbin/mke2fs       /sbin/mkfs.ext3     /sbin/mkfs.vfat
/sbin/mkfs         /sbin/mkfs.ext4     /sbin/mkfs.xfs
/sbin/mkfs.btrfs   /sbin/mkfs.ext4dev  /sbin/mkhomedir_helper
/sbin/mkfs.cramfs  /sbin/mkfs.msdos    /sbin/mkswap

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 use multiple identical files with different names. Filesystems that cannot be used for the / filesystem in Linux, such as vfat or msdos, may use symbolic links instead.

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 Listing 12.


Listing 12. Creating an ext3 filesystem
[root@echidna ~]# mkfs -t ext3 /dev/sda8
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2624496 inodes, 10488429 blocks
524421 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
321 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

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 and ext3 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 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 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
                    
[ian@echidna ~]$ blkid /dev/sda8
/dev/sda8: UUID="87040def-920e-4525-9c81-c585ddc46384" SEC_TYPE="ext2" TYPE="ext3"

... ... ...

Creating a vfat filesystem

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


Listing 15. Creating a vfat filesystem
[root@echidna ~]# mkfs -t vfat /dev/sda9
mkfs.vfat 3.0.9 (31 Jan 2010)
[root@echidna ~]# blkid /dev/sda9
/dev/sda9: LABEL="" UUID="CF72-99A8" TYPE="vfat"

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 Listing 16.


Listing 16. Creating swap space
[root@echidna ~]# mkswap /dev/sda4
Setting up swapspace version 1, size = 4192960 KiB
no label, UUID=8f5a3a05-73ef-4c78-bc56-0e9b1bcc7fdb

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.

Partitionining of x86, AMD64, and Intel® 64 systems

Generally you do not need separate partitions for /opt and usr, they can happily co-exist with root partition. The only reason to create /usr partition is to make it read-only.
Red Hat

Unless you have a reason for doing otherwise, we recommend that you create the following partitions for x86, AMD64, and Intel® 64 systems:

[Nov 14, 2008] Cool Solutions Manually Partitioning Your Hard Drive with fdisk

20 Jul 2007 | Novell.com

Creating partitions via the command line interface is simple and quick, also having the kernel acknowledge the partition table has been modified and having the partition scheme take effect without having to reboot your workstation/server and without having to use the parted utility.

The first step to this guide is to see what hard drives are available and what hard drive you would like to partition. If you have multiple hard drives in your machine, fdisk will report them to you as shown in Figure 1. There are two hard drives shown in Figure 1 "sda" and "sdb".

The fdisk command with the -l qualifier ("fdisk -l") will display the current partition tables along with the hard drives that are attached to your workstation/server as shown in Figure 1.

linux-1reo:~ # fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes 
255 heads, 63 sectors/track, 9729 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sda1   *           1        1402    11261533+   7  HPFS/NTFS 
/dev/sda2            1403        1415      104422+  83  Linux 
/dev/sda3            1416        1546     1052257+  82  Linux swap / Solaris 
/dev/sda4            1547        9729    65729947+   5  Extended 
/dev/sda5            1547        7920    51199123+  8e  Linux LVM 

Disk /dev/sdb: 80.0 GB, 80026361856 bytes 
255 heads, 63 sectors/track, 9729 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1   *           1        9729    78148161   8e  Linux LVM 

Disk /dev/sdc: 500.1 GB, 500107862016 bytes 
255 heads, 63 sectors/track, 60801 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Figure 1: fdisk -l output.

Once you have determined which hard drive you want to partition you can issue the fdisk command followed by the hard drive ("fdisk /dev/sda"), in this article we will use the first hard drive (sda).

linux-1reo:~ # fdisk /dev/sda
The number of cylinders for this disk is set to 9729. 
There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
   (e.g., DOS FDISK, OS/2 FDISK) 

Command (m for help): 
Figure 2: Partitioning the first hard drive (sda).

Once fdisk has been executed your command prompt will change to "Command (m for help):" and you are ready to examine and partition your hard drive. The commands that are supported by fdisk can be displayed by pressing the "m" character followed by the return key. The commands that we will be using are "p" for printing the partition table, "n" for creating a new partition and "w" for saving the changes and exiting.

Displaying the current partition table

The first step before we start to partition our hard drive is to get a sense of what disk space we have available and what the current partition table looks like. The command we will use from fdisk is the "p" character which will print the current partition table as show in Figure 3.

Command (m for help): p 

Disk /dev/sda: 80.0 GB, 80026361856 bytes 
255 heads, 63 sectors/track, 9729 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks      Id  System 
/dev/sda1   *           1          1402    11261533+   7  HPFS/NTFS 
/dev/sda2            1403        1415      104422+  83   Linux 
/dev/sda3            1416        1546     1052257+  82  Linux swap / Solaris 
/dev/sda4            1547        9729    65729947+   5  Extended 
/dev/sda5            1547        7920    51199123+  8e Linux LVM
Figure 3: Current partition table.

The output shown in Figure 3 shows that we have 1809 cylinders available (9729 ? 7920 = 1809) and with this we can use the calculation (1809 * 16065 * 512 = 14879531520 Bytes) which is roughly about 14 gigabytes. (The 16065 and 512 were taken from the "Units =" statement and may differ on you're system, so you may be require to substitute them if necessary).

Creating a new partition

The next step is to create our new partition. For our example, we will create a partition of type "Linux" with the partition size of one gigabyte. The command that we will use to create our new partition is the "n" character, we will then be asked to select what cylinder to start from (I recommend sticking with the default) and the size of the partition as shown in Figure 4.

Command (m for help): n 
First cylinder (7921-9729, default 7921): 
Using default value 7921 
Last cylinder or +size or +sizeM or +sizeK (7921-9729, default 9729): +1024M
Figure 4: Creating a new partition with the size of one gigabyte.

Once the partition has been created, using the "p" character we can display our new partition table which will show the newly created partition, as shown in Figure 5.

Command (m for help): p 

Disk /dev/sda: 80.0 GB, 80026361856 bytes 
255 heads, 63 sectors/track, 9729 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sda1   *           1        1402    11261533+   7  HPFS/NTFS 
/dev/sda2            1403        1415      104422+  83  Linux 
/dev/sda3            1416        1546     1052257+  82  Linux swap / Solaris 
/dev/sda4            1547        9729    65729947+   5  Extended 
/dev/sda5            1547        7920    51199123+  8e  Linux LVM 
/dev/sda6            7921        8045     1004031   83  Linux 
Figure 5: Newly created partition (sda6).

Writing the new partitions to disk

Now that the partition has been successfully created you can save the changes by issuing the "w" character which will write the new partition table to the hard disk as shown in Figure 6.

Command (m for help): w 
The partition table has been altered! 

Calling ioctl() to re-read partition table. 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 
The kernel still uses the old table. 
The new table will be used at the next reboot. 
Syncing disks. 
Figure 6: Writing the new partition table to disk.

Activating the newly created partition

Once the new partition table has been written to the hard disk it is possible to have the kernel read the new partition table without the need of rebooting. The first step is to create a mount point for the new partition, in our example we will use "/media/newpart" and also use the command "partprobe" to have the kernel re-read the partition table, as shown in Figure 7.
linux-1reo:~ # mkdir /media/newpart 
linux-1reo:~ # partprobe
Figure 7: Creation of a new mount point and a re-read of the partition table.

Now that a new mount point has been created and the partition table has been re-read by the kernel you can now format the partition and place a file system of your choice on it. (ext2, ext3, ResierFS etc) In our example we have chosen the ResierFS file system as shown in Figure 8.

linux-1reo:~ # mkfs.reiserfs /dev/sda6
mkfs.reiserfs 3.6.19 (2003 www.namesys.com)

A pair of credits:
The  Defense  Advanced  Research  Projects Agency (DARPA, www.darpa.mil) is the
primary sponsor of Reiser4.  DARPA  does  not  endorse  this project; it merely
sponsors it.

Alexander  Lyamin  keeps our hardware  running,  and was very  generous  to our
project in many little ways.


Guessing about desired format.. Kernel 2.6.16.21-0.8-default is running.
Format 3.6 with standard journal
Count of blocks on the device: 126496
Number of blocks consumed by mkreiserfs formatting process: 8215
Blocksize: 4096
Hash function used to sort names: "r5"
Journal Size 8193 blocks (first block 18)
Journal Max transaction length 1024
inode generation number: 0
UUID: e20e2dc1-7277-4ab1-930c-038e54548540
ATTENTION: YOU SHOULD REBOOT AFTER FDISK!
        ALL DATA WILL BE LOST ON '/dev/sda3'!
Continue (y/n):y
Initializing journal - 0%....20%....40%....60%....80%....100%
Syncing..ok
ReiserFS is successfully created on /dev/sda3.
linux-1reo:~ #
Figure 8: Formatting the newly created partition.

Once the partition has been formatted with the file system of your choice you can mount and use you're newly created partition, Figure 9 shows the newly created partition being mounted.

linux-1reo:~ # mount /dev/sda6 /media/partnew
Figure 9: Mounting the newly created partition.

Final thoughts

Once you have mounted your newly created and formatted partition you can store your files on the partition without having any problems, you may also add your new partition to the "/etc/fstab" file so that the partition will be mounted after every reboot.

Tested on:

SUSE Linux Enterprise Desktop 10
SUSE Linux Enterprise Server 10

/dev/dm-0 - LinuxQuestions.org

fdisk -l output in case you are using LVM contains many messages like

Disk /dev/dm-0 doesn't contain a valid partition table

This has been very helpful to me. I found this thread by Goggle on dm-0 because I also got the no partition table error message.

Here is what I think:

When the programs fdisk and sfdisk are run with the option -l and no argument, e.g.
# /sbin/fdisk -l

they look for all devices that can have cylinders, heads, sectors, etc.
If they find such a device, they output that information to standard output and they output the partition table to standard output. If there is no partition table, they have an error message (also standard output).
One can see this by piping to 'less', e.g.
# /sbin/fdisk -l | less

/dev/dm-0 ... /dev/dm3 on my fedora C5 system seem to be device mappers
associated with LVM.

RAID might also require device mappers.

Partitioning question - LinuxQuestions.org

If you run suse 10.3 yast > system > partitioner show you with part is used by suse ,and with part is still unused.

I know if you startup the partitioner it gives you a warning but as long as do not change any think every is oke
If according to the partitioner sdb is unused then you can do every think with it for instance to create a second primary partition for a second OS If you put GRUB of the second OS in the second primary partition Suse is still there and must it be possible to change suse boot loader in that way that she also load the second OS

But there are more ways to do what you like to do

all the best

[Aug 17, 1999] Linux.com - Featured Articles

Dave's Diary, Entry 3: Disk Partitions and Limitations - June 23rd, 1999
by David Apfelbaum

I have heard of folks playing games to get Linux to boot off a FAT filesystem. But you really don't want to start off playing with that. So, you are going to need at least one partition. Probably two. Possibly more.

The partitioning of your drive can and should be done during the installation of Linux. However, if you don't currently have any unpartitioned disk space, or if you don't have any disk partitions that you want to wipe out and dedicate to linux, then you have a problem.

There are tools that will allow you to shrink your current (most likely Windows) partitions. I've never used them. If you do use them, be sure to back up your system thoroughly first. (And double-check [test] your backups before you begin!)

Alternatively, you can add another IDE hard drive for $125-$300. If you add another harddrive, be careful. In Windows, if you add a new Windows partition after running your system for a while, you tend to get hosed badly. Your drive letters get renumbered. Your registry no longer contains accurate data. In plain and simple terms: You can find yourself up mister creek without mister paddle.

Linux, in contrast, won't really give a damn. In part because Linux, like other flavors of Unix, doesn't have drive letters. Instead there is one master partition--the root partition which is known as "/". Additional partitions can be mounted as subdirectories inside the root partition. So /tmp, /home, and/or /usr could be separate partitions in Linux--the equivalent of D:, E:, or F: in Windows. But there is no requirement that you have more than that one master root partition (plus swap--we'll get to swap in a minute). And with this arrangement, it's quite trivial to add new partitions to a Linux system later on as your needs change.

If I may digress here for a moment: A few months ago I added a new hard drive to my dual-boot (Win95/Linux) home box. Under Linux I partitioned the drive (/sbin/fdisk), formatted the partitions (/sbin/mke2fs), added them to the /etc/fstab file so they'd automount the next time I rebooted, mounted the partitions (/bin/mount), and I was done. Windows, on the other hand, decided that there had to be a Windows partition somewhere in my newly created extended partition. And Windows tried, desperately, to find that nonexistent Windows partition. Eventually it would time out and conclude that there was a zero-length windows partition (drive) on my new extended partition. But that wouldn't stop it from trying to find that nonexistent partition again a few seconds later. It rendered Windows unusable until I figured it out and created a DOS FAT partition inside my new extended partition. A classic example of plug-and-pray!

So even though you may not be adding Windows partitions, Windows can still get upset with you. Microsoft just does not play nicely with the other children.

Anyway, back to partitions. Red Hat gives all sorts of interesting advice regarding partitions in their manual. See the Red Hat Linux 5.2 installation guide.

My two cents on this is that, if you are playing around in a non-professional environment on a PC-based (Intel/i386) system, allocate a single 1-gig partition and put everything (excluding swap) on it. Even if you are working in a professional environment, you may still want to consider doing something similar depending upon your circumstances.

The only advantage to splitting up your directory structure across multiple partitions is that, if one partition gets filled up, the rest of the system can keep going. (Specifically, log files and such can still be written to the unfilled partitions.)

Now, if you've got users who are really obnoxious. Let's say they fill up /tmp or /usr/tmp with large files, or they like to fill up their home directories in the same fashion. Then using multiple partitions can become really useful. But with Linux, it's easy enough to add more partitions later, so why make things more difficult when you're first starting out?

In a related vein: don't feel obliged to use up all your disk space at once. Who knows, next week you might decide that you'd really rather not share a partition with Joe Sixchip who, for some strange reason, seems to have a rather large collection of gifs of questionable morality.

Or you might decide that you'd like a second Linux installation containing older (or newer) software that's independent of your work system. Perhaps you will join the experimental ranks. Or perhaps you have some legacy code that wants an older version of libc.

On the other hand, consider that repartitioning a drive is a hazardous operation. So be sure to back it up before repartitioning. Alternatively, I commonly partition my drive up in 1 or 2 gig chunks. But I don't use those partitions until I need them. Which gives me some space to play around with.

Also, try not to create partitions that are substantially larger than your backup media. It can be done. And there are a lot of people doing it. But doing so just tends to make life that much more unpleasant when you're first starting out. (You would eventually need to spread your backups across multiple tapes.)

Partition Constraints: I have only used IDE, because they're cheap. SCSI is also supported. Linux won't care if your partitions are primary partitions or inside an extended partition (AKA: logical drives).

However, if you are using LILO, the /boot directory needs to be located on the first 2 IDE drives (if you have only IDE), on the first 2 SCSI drives (ID-0 / ID-1) (if you have only SCSI), or on the first IDE or first SCSI (ID-0) (if you have IDE & SCSI). See the Red Hat manual for further reference.

Also, if you are using LILO, /boot must be located below cylinder 1023 of your hard disk. If you have only one partition, that entire partition should be located below cylinder 1023. One common trick to overcome this limitation is to create a separate /boot partition. If you do this, make it at least a couple of megs. (You want to leave a little extra room in /boot so you can recompile the kernel and still keep an old kernel or two lying around.)

LILO, for those who are unfamiliar with it, is the LInux LOader. It lives outside the operating system. And it is commonly used as a means of starting Linux at boot time. (It can also be used to start Windows, which is convenient for dual-boot systems.)

Swap: it is possible, except on very small systems, to use a swap file. I do not recommend swap files. Swap files tend to have slower access times than swap partitions.

You can have more than one swap partition. Red Hat 5.2 uses the older, 2.0.36 kernel. As such, space in swap partitions above 128 megabytes will not be used. Thus leading folks to utilize multiple swap partitions. I believe that this limitation has been removed in the newer 2.2.x kernels that Red Hat 6.x uses.

How much swap? I usually figure about twice my RAM. My reasoning is that if I use more than twice my RAM in swap, my Linux box will be thrashing (spending most of its time swapping) far too hard to make it worth my while. Of course, if you're running legacy code that has a core leak (i.e., that leaks memory), extra swap may buy you some more running time.

On the other hand, if I'm working with a really tiny bit of RAM (less than 16 MB), I'll generally figure 32 Megabytes as a minimum amount of swap.



Recommended Links

Please visit nixCraft site. It has material well worth your visit.

Dr. Nikolai Bezroukov

Reference



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: May 06, 2020