Create Linux partitions and filesystems

we will be creating a new partition on the /dev/sdb disk

check the space avaliable in sdb, out of 40 GB only 10GB is being used so we have 30 GB remaining

[root@linux ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 56.3M 0 rom
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 256M 0 part /boot
├─sda2 8:2 0 10G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 67.8G 0 part
├─appvg-homelv (dm-2) 253:2 0 4G 0 lvm /home
├─appvg-varlv (dm-3) 253:3 0 4G 0 lvm /var
├─appvg-optlv (dm-4) 253:4 0 4G 0 lvm /opt
├─appvg-usrlocallv (dm-5) 253:5 0 4G 0 lvm /usr/local
├─appvg-usrlv (dm-6) 253:6 0 6G 0 lvm /usr
└─appvg-tmplv (dm-7) 253:7 0 4G 0 lvm /tmp
sdb 8:16 0 40G 0 disk
├─sdb1 8:17 0 5G 0 part
│ ├─datavg-harilv (dm-0) 253:0 0 3G 0 lvm /haridai
│ └─datavg-srisirlv (dm-1) 253:1 0 5G 0 lvm /srisir
└─sdb2 8:18 0 5G 0 part
└─datavg-srisirlv (dm-1) 253:1 0 5G 0 lvm /srisir

So we will be creating one more partition

[root@linux ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xccf9dd0d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         654     5253223+  8e  Linux LVM
/dev/sdb2             655        1308     5253255   8e  Linux LVM

 

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1309-5221, default 1309):
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-5221, default 5221): +2G

Command (m for help): p

Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xccf9dd0d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         654     5253223+  8e  Linux LVM
/dev/sdb2             655        1308     5253255   8e  Linux LVM
/dev/sdb3            1309        1570     2104515   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.

after creating partition , to able to see the device without rebooting we can use partprobe

[root@linux ~]# partprobe /dev/sdb3
Error: Could not stat device /dev/sdb3 - No such file or directory.

if partprobe does not work then we can use partx

[root@linux ~]# partx -v -a /dev/sdb
device /dev/sdb: start 0 size 83886080
gpt: 0 slices
dos: 4 slices
# 1:        63- 10506509 ( 10506447 sectors,   5379 MB)
# 2:  10506510- 21013019 ( 10506510 sectors,   5379 MB)
# 3:  21013020- 25222049 (  4209030 sectors,   2155 MB)
# 4:         0-       -1 (        0 sectors,      0 MB)
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
added partition 3
[root@linux ~]# lsblk | grep sdb
sdb                           8:16   0   40G  0 disk
├─sdb1                        8:17   0    5G  0 part
├─sdb2                        8:18   0    5G  0 part
└─sdb3                        8:19   0    2G  0 part

Now create a directory where you want to mount

[root@linux ~]# mkdir /uday

format the partition

[root@linux ~]# mkfs.ext4 /dev/sdb3
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
131648 inodes, 526128 blocks
26306 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

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

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

Put the entry in /etc/fstab file to make mount persistant across reboot

[root@linux ~]# vi /etc/fstab
/dev/sdb3       /uday ext4      defaults 1 2

mount and check if it is mounted

[root@linux ~]# mount -a
[root@linux ~]# df -PTh | grep uday
/dev/sdb3                    ext4   2.0G  3.1M  1.9G   1% /uday

 

Leave a Reply