This post gives the details for creating a new partition after installed the operating system, Maximum Linux can allow to create four primary partitions only, but you can have to create much number of logical partitions dividing from one of the primary partitions.
Normally creating partitions are look like,
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
Above partitions have been created three primary partitions, file systems are Linux, Linux LVM and Linux Swap. I would like to be add another two portions and the options are available can make only one primary , so create an extended partition, We can use fdisk command,
More fdisk commands : http://thelinuxfaq.com/147-how-to-create-swap-partition-in-centos-rhel-ubuntu
Note : When you create a extended ask first sector -> "Press Enter" button and Last Sector -> "Press Enter" button.
# fdisk -cu /dev/sda
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First sector (58918912-488397167, default 58918912):
Using default value 58918912
Last sector, +sectors or +size{K,M,G} (58918912-488397167, default 488397167):
Using default value 488397167
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
/dev/sda4 58918912 488397167 214739128 5 Extended
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First sector (58918912-488397167, default 58918912):
Using default value 58918912
Last sector, +sectors or +size{K,M,G} (58918912-488397167, default 488397167):
Using default value 488397167
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
/dev/sda4 58918912 488397167 214739128 5 Extended
There are four partitions has been created, including Extended partition the Extended ID is 5. I will create two partitions with 10G space from extended partition.
Note : When you create a partition ask first sector -> "Press Enter" button and Last Sector -> give your required space value (Example : +10G or +500M )
Command (m for help): n
First sector (58920960-488397167, default 58920960):
Using default value 58920960
Last sector, +sectors or +size{K,M,G} (58920960-488397167, default 488397167): +10G
Command (m for help): n
First sector (79894528-488397167, default 79894528):
Using default value 79894528
Last sector, +sectors or +size{K,M,G} (79894528-488397167, default 488397167): +10G
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
/dev/sda4 58918912 488397167 214739128 5 Extended
/dev/sda5 58920960 79892479 10485760 83 Linux
/dev/sda6 79894528 100866047 10485760 83 Linux
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
First sector (58920960-488397167, default 58920960):
Using default value 58920960
Last sector, +sectors or +size{K,M,G} (58920960-488397167, default 488397167): +10G
Command (m for help): n
First sector (79894528-488397167, default 79894528):
Using default value 79894528
Last sector, +sectors or +size{K,M,G} (79894528-488397167, default 488397167): +10G
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9b75ce8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 526335 262144 83 Linux
/dev/sda2 526336 57870335 28672000 8e Linux LVM
/dev/sda3 57870336 58918911 524288 82 Linux swap / Solaris
/dev/sda4 58918912 488397167 214739128 5 Extended
/dev/sda5 58920960 79892479 10485760 83 Linux
/dev/sda6 79894528 100866047 10485760 83 Linux
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
Once created the partitions rebooting the system.
# init 6
Have to decide create two directories in root the name of redhat and centos, mount that partition to this directories.
# mkdir /redhat
# mkdir /centos
You need to format these file system to ext4 using mkfs.ext4 command,
# mkfs.ext4 /dev/sda5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Same as
# mkfs.ext4 /dev/sda5
# Mount the device sda4 and sda5 to that directory
# mount /dev/sda5 /redhat/
# mount /dev/sda6 /centos/
Check your disk partition space,
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root
18G 7.5G 9.4G 45% /
tmpfs 1.8G 260K 1.8G 1% /dev/shm
/dev/sda1 248M 69M 167M 30% /boot
/dev/sda5 9.9G 151M 9.2G 2% /redhat
/dev/sda6 9.9G 151M 9.2G 2% /centos
The two partition set on after reboot add the line in /etc/fstab file,
/dev/sda5 /redhat ext4 defaults 0 0
/dev/sda6 /centos ext4 defaults 0 0
or Add with UUID
How to unmount the partition:
Before unmount the partition remove file system configuration line from /etc/fstab file and run below command
# umount /dev/sda5
# umount /dev/sda6
or
# umount /redhat
# umount /centos
Error :
# umount /dev/sda5
umount: /redhat: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
If you get an above error you are currently working on that directory.
Comments (0)