Lets Assume the Attached Disk of size 500GB for e.g. is shown as /dev/sdc. Below is the procedure to create 2 or more custom partitions from attached disk
1) List the size of the attached disk
fdisk -l /dev/sdc
Disk /dev/sdc: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0xf24ccf4c
2) Run fdisk command to create the 2 or more partitions as follows. In this example we are creating 3 partitions, partition 1 of 375G size, partition 2 of 100G size and partition 3 of 25GB size.
fdisk into the attached disk.
#fdisk /dev/sdc
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p >>>> Enter p here to print
Disk /dev/sdc: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0xf24ccf4c
In above output we see 500GB size.
Command (m for help): n >>>> Enter n to create new partition
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p >>>>> select p here for default partition.
Partition number (1-4, default 1): >>>>> go with default, or enter the partition number here. In this case we are going with default of 1 for 1st partition
First sector (2048-1048575999, default 2048): >>>> hit enter.
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): +375G >>>>> here enter +375G which means that you want 375GB size for 1st partition.
Created a new partition 1 of type 'Linux' and of size 375 GiB.
As seen above we have now created 1st partition.
Command (m for help): n >>>> Enter n here to create second partition.
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p >>>> select p for primary partition
Partition number (2-4, default 2): >>>> go with default or enter partition number. Default is 2 as it is second partition.
First sector (786434048-1048575999, default 786434048): >>>> Hit enter.
Last sector, +sectors or +size{K,M,G,T,P} (786434048-1048575999, default 1048575999): +100G >>>>>> here enter +100G for entering the size of 100GB for second partition.
Created a new partition 2 of type 'Linux' and of size 100 GiB.
As seen above 2nd partition is created above.
Now lets create the final third partition. If you want to create more than 3 partitions you have to specific the custom size here for Last section when prompted instead of going with default option of hitting enter which will take whatever the free attached space is.
Command (m for help): n >>>>>>> Enter n for creating third new partition
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p >>>> Enter p for primary partition.
Partition number (3,4, default 3): >>>>> go with default by hitting enter which will be 3rd partition, if not provide the partition number.
First sector (996149248-1048575999, default 996149248): >>>> go with default
Last sector, +sectors or +size{K,M,G,T,P} (996149248-1048575999, default 1048575999): >>>> go with default it will take all the rest of the disk space.
Created a new partition 3 of type 'Linux' and of size 25 GiB.
As you can see above the 3rd partition is created with 25GB size.
Command (m for help):
Command (m for help): p >>>> print the partitions. As you can see we have 2 partitions /dev/sdc1, /dev/sdc2 and /dev/sdc3
Disk /dev/sdc: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0xf24ccf4c
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 786434047 786432000 375G 83 Linux
/dev/sdc2 786434048 996149247 209715200 100G 83 Linux
/dev/sdc3 996149248 1048575999 52426752 25G 83 Linux
Command (m for help):
Command (m for help): w >>>>> write and save the changes.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
3) List the partitions for the attached disk to verify that the created partitoins are seen.
[root@ops var]#
[root@ops var]# fdisk -l /dev/sdc
Disk /dev/sdc: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0xf24ccf4c
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 786434047 786432000 375G 83 Linux
/dev/sdc2 786434048 996149247 209715200 100G 83 Linux
/dev/sdc3 996149248 1048575999 52426752 25G 83 Linux
[root@ops var]#
4) Format all the newly created partitions using below commands.
sudo mkfs.xfs -f /dev/sdc1
sudo mkfs.xfs -f /dev/sdc2
sudo mkfs.xfs -f /dev/sdc3
Below are sample outputs.
[root@ops var]# sudo mkfs.xfs -f /dev/sdc1
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=24576000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=98304000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=48000, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ops var]# sudo mkfs.xfs -f /dev/sdc2
meta-data=/dev/sdc2 isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ops var]# sudo mkfs.xfs -f /dev/sdc3
meta-data=/dev/sdc3 isize=512 agcount=4, agsize=1638336 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=6553344, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=3199, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
5) Print the size of the partitions using parted command.
parted /dev/sdc print
Below is sample output.
[root@ops ~]# parted /dev/sdc print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdc: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 403GB 403GB primary xfs
2 403GB 510GB 107GB primary xfs
3 510GB 537GB 26.8GB primary xfs
6) Mount the filesystems using the new partitions.
For e.g. if you want to mount /apps1, /apps2 and /apps3 for partitions sdc1, sdc2 & sdc3 you will need to have below entries in /etc/fstab file.
/dev/sdc2 /apps1 xfs defaults 0 0
/dev/sdc3 /apps2 xfs defaults 0 0
/dev/sdc1 /apps3 xfs defaults 0 0
Alternatively you can mount filesystem using below commands.
sudo mount -t xfs /dev/sdc1 /apps1
sudo mount -t xfs /dev/sdc2 /apps2
sudo mount -t xfs /dev/sdc3 /apps3
Keywords:
Disk disks filesystem filesystems system systems files volume volumes attached attaching size increase expand reduce expanding reducing multiple partitions partition mount mounts points fdisk erase format formatting
No comments:
Post a Comment