How to create partitions in Linux

In this tutorial, let us learn how to create partitions on Linux using the fdisk command. Fdisk is a command line utility that provides disk partitioning capabilities for various operating systems. It was originally developed by IBM in 1983 and has since been used on most operating systems from DOS to Windows to Unix-based operating systems.

table of Contents

  • 1) Create a new partition
  • 2) Create a file system
  • 3) Mount the new partition

1) Create a new partition

Here I try to use fdisk to create partitions on the disk (ProLiant SmartArray RAID Controller-/ dev / cciss). You can choose the option “n” to create a new partition and “p” to list the available partitions. On the output below (7253-8920, default is 8920), the average cylinder is now available from 7253 to 8920. Finally, you need to use “w” to write changes to disk. Remember that as long as you don’t use the “w” option, all changes will remain in memory and will not be written to disk.

# Fdisk / dev / cciss / c0d0

The number of cylinders of this disk is set to 8920. This is fine, but it is larger than 1024 and may cause the following problems in some settings: 1) software running at startup (eg, older versions of LILO) 2) from other operating systems (eg DOS FDISK, OS / 2 FDISK) Boot and Partition Software

Command (m for help): m command operation a switchable bootable flag b edit bsd disklabel c switch dos compatibility flag d delete partition l list known partition types m print this menu n add new partition o create new empty DOS partition Table p prints the partition table q exits without saving changes s creates a new empty Sun disklabel t changes the system ID of the partition u changes the display / entry unit v verifies the partition table w writes the table to disk and exits x additional functions (only applicable expert)

Command (m for help): n first cylinder (7253-8920, default value 7253): ==> press Enter to accept the default value use default value 7253 last cylinder or + size or + size or + sizeM Or + sizeK (7253-8920, default value 8920): + 5G

Command (m for help): p

Disk / dev / cciss / c0d0: 73.3 GB, 73372631040 bytes, 255 heads, 63 sectors / tracks, 8920 cylinder units = cylinder 16065 * 512 = 8225280 bytes

Device boot startup end block ID system / dev / cciss / c0d0p1 * 1 12 96358+ 83 Linux / dev / cciss / c0d0p2 13 2101 16779892+ 83 Linux / dev / cciss / c0d0p3 2102 4190 16779892+ 82 Linux swap / dev / cciss / c0d0p4 4191 8920 37993725 5 extended / dev / cciss / c0d0p5 4191 5234 8385898+ 83 Linux / dev / cciss / c0d0p6 5235 5756 4192933+ 83 Linux / dev / cciss / c0d0p7 5757 5881 1004031 83 Linux / dev / cciss / c0d403p1 100 83 Linux / dev / cciss / c0d0p9 6007 7252 10008463+ 83 Linux / dev / cciss / c0d0p10 7253 7861 4891761 83 Linux

Command (m for help): w partition table has changed!

Call ioctl () to re-read the partition table.

Warning: Failed to reread the partition table, Error 16: Device or resource is busy. The kernel still uses the old tables. The new table will be used at the next restart. Sync disk.

Disk

The partprobe command will notify the operating system kernel of partition table changes. Therefore, no restart is required. / * Note: Partprobe may cause a reboot (not always, just a precautionary measure)-schedule downtime for real-time systems * /

# Partprobe / dev / cciss / c0d0

To see the available disk partitions, you can check the / proc / partitions file, so the newly created partition should be in it. You can run this command before and after the disk partition.

#Cat / proc / partitions major minor #blocks name

104 0 71652960 cciss / c0d0 104 1 96358 cciss / c0d0p1 104 2 16779892 cciss / c0d0p2 104 3 16779892 cciss / c0d0p3 104 5 8385898 cciss / c0d0p5 104 6 4192933 cciss / c0d0p0 104 7 1004031 cc0 ciss / c0d0p0 cciss / c0d0p9 104 10 4891761 cciss / c0d0p10

2) Create a file system

Even if space has been allocated for the new partition and written to disk, you still need to create a file system on that new free space, so the next step is to format the partition with the required file system. In our example, we will use ext3.

# / Sbin / mkfs -t ext3 / dev / cciss / c0d0p10 mke2fs 1.35 (February 28, 2004) File system label = OS type: Linux block size = 4096 (log = 2) Fragment size = 4096 (log = 2) 611648 inode, 1222940 blocks 61147 blocks (5.00%) reserved for super users. The first data block = 0 maximum file system block = 1254096896 38 blocks per group. 32768 blocks per group. 32768 fragments per group. 16096 per group. Superblock backups stored on inode blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing the inode table: done

Create log (8192 blocks): completed writing superblock and file system accounting information: completed

The file system will be automatically checked every 33 installations or every 180 days, whichever comes first. Use tune2fs -c or -i to overwrite.

mkfs

You can use the e2label command to set a new label name for the file system.

# E2label / dev / cciss / c0d0p10 / mydatadisk

You can edit the fstab file to update the new tab (file system) information.

# Vi / etc / fstab # This file is edited by fstab-sync-see ‘man fstab-sync’ for details. LABEL = // ext3 default value 1 1 LABEL = / boot / boot ext3 default value 1 2 none / dev / pts devpts gid = 5, mode = 620 0 0 None / dev / shm tmpfs default value 0 0 LABEL = / mlextras / mlextras ext3 default value 1 2 None / proc proc default value 0 0 None / sys sysfs default value 0 0 LABEL = / var / var ext3 default value 1 2 LABEL = SW-cciss / c0d0p3 exchange default value 0 0 LABEL = / itrs / itrs ext3 default value 1 2 LABEL = / mqmsw / mqmsw ext3 default value 1 2 LABEL = / mktdata / mktdata ext3 default value 1 2 LABEL = / mydatadisk / tools ext3 default value 1 2 / dev / vx / dsk / dg_apps / apps / apps vxfs suid 1 2 / dev / hda / media / cdrecorder auto pamconsole, exec, noauto, managed 0 0

3) Mount the new partition

Now that we have created a new partition and formatted it, we need to mount it to a specific location so we can start using it. To do this, we will first create a folder to use as the mount point for the partition, and then use the mount command to actually mount the partition.

# Mkdir / tools

#Mount / dev / cciss / c0d0p10 / tools

To confirm, we can use the following command to list the mount points

#Df -h / tools used file system size available percentage already installed at / dev / cciss / c0d0p10 4.6G 42M 4.4G 1% / tools

#Mount -l | grep tool

/ dev / cciss / c0d0p10 on / tools enter ext3 (rw) [/tools]

df-h

Also read:

  • Learn about each entry in the Linux Fstab (/ etc / fstab) file
  • Find detailed NFS mount options in Linux
  • How to create, extend, delete swap partitions in Redhat / Centos LVM
Sidebar