Disk Management With Parted Command In Linux: ============================================= MBR partition scheme and GPT partition scheme both use different method to store partition information in disk. We cannot use both scheme in a single disk. Since in this tutorial we will create both types of partitions, we need two separate disks. We have already added two virtual disks in our system. # lsblk OR # fdisk –l Creating MBR Partition with parted command: The parted command needs the name of disk where we want to create the partition as its argument. # parted Always use parted command with argument. Without argument it will start with first available disk. # parted /dev/sdb print The print command provides important information about the hard disk. This information includes manufacturer information, disk model, disk size, Partition Table and disk flag. If this is a new disk, we will get unrecognised disk label error. Disk label is the information which is used to determine the type of disk. The parted command needs a valid disk label before it can do anything with disk. To see it practically run mkpart command. The mkpart command is used to create new partition. mkpart As above output confirmations that we are not allowed to create new partition unless it has a valid disk label. The msdos and gpt are two valid disk labels which we can use here. The msdos label is used to define the disk as MBR disk and the gpt label is used to define the disk as GPT disk. To assign the label mklabel command is used. Let’s assign the msdos label to this disk. Type mklabel and press Enter key. Type msdos and press Enter key. Verify the action with print command. # parted /dev/sdb mklabel msdos print Do not use this command if disk contains data. This command is very risky. This command will convert disk in un-partitioned blank disk silently. Now disk has label. We can create partition in it. To create partition following steps are used. Type mkpart and press Enter key. As we know in MBR partition scheme we are allowed to create maximum four primary partitions. If more partitions are required, we have to use one primary partition as extended partition. Further Extended partition can be used to create 15 logical partitions. Type the partition type and press Enter key. Type the starting point for partition and press Enter key. The parted utility supports very limited file system types. To add worse, most of them are out dated nowadays. We will make file system individually later. By now just keep the default file system type. Type the ending point for partition. We can use KB, MB or GB units to define the size of partition. We can verify the creation of partition with print command Following figure illustrates above steps mkpart primary ext2 1M 600M print Always start first partition with 1MB even only first 512 bytes are used to store the MBR data. This way we can avoid several entry point errors. Following same process create two more partitions mkpart primary ext2 601 800 mkpart primary 801 1000 print We have created three primary partitions from maximum (four) allowed. Now we can create one more primary partition or can create one extended partition. Let’s create one allowed extended partition. Since extended partition is used to create all allowed logical partitions, we should allocate the maximum disk space in this partition. We will assign all remaining disk space in this partition. mkpart extended 1001 2100 print All logical partitions will be created in extended partition. The sum (of size) of all logical partitions cannot go beyond the extended partition. In this example we created an extended partition of 1145MB, so we can create logical partitions from 1145MB. We are allowed to create up to 15 logical partitions in extended partition. We can create any number of partitions from range of one to fifteen. The only limit is that the sum of all partitions must be below the size of extended partition. Let’s create a single logical partition of all available space. mkpart logical ext2 1002 2045 print We have used all space of extended partition in one logical partition. So even we are allowed to create up to 15 logical partitions and free space is available outside the extended partition, we cannot create the another logical partition. To create another logical partition we need free space inside the extended partition not outside the partition. So far we have created all possible partitions including primary, extended and logical partitions. To exit from parted use quit command. quit The parted cannot update the in-memory kernel partition table. Kernel reads partition table when system boots. So the kernel will be updated about this change at next reboot automatically. Meanwhile if we want to update the kernel immediately, we can use partprobe command which force kernel to reread the partition table. # partprobe /dev/sdb # lsblk # fdisk -l /dev/sdb Creating GPT partition with parted command: GPT is the new partition scheme. It allows us to create up to 128 partitions. It does not divide partitions in primary, extended and logical. First part of this article explains basic concepts of GPT in detail with examples. We will create GPT partition in /dev/sdb disk. Let’s initiate parted again for /dev/sdb disk # parted /dev/sdc print mkpart mklabel gpt Now disk has a valid label. We can create partition in it. Creating partition is a six steps process. Type mkpart and press Enter key Set desired descriptive name for partition Accept default file system type Enter starting point of partition Enter ending point of partition Verify the partition with print command mkpart linux ext2 1M 600M print mkpart documents 601 1000 print quit # partprobe /dev/sdc lsblk So far we have created MBR and GPT partitions in /dev/sdb and /dev/sdc respectively. These partitions are useless unless we put a file system in them. File system is a logical container which allows us to store files and directories. How to create file system To create a file system in partition we format it with supported file system. To format a partition following command is used. # mkfs.ext3 /dev/sdb1 # mkfs.ext4 /dev/sdb2 # mkdir /srv/test1 ; mkdir /srv/test2 # mount /dev/sdb1 /srv/test1 # mount /dev/sdc1 /srv/test2 # df -hT Make entries in /etc/fstab for permanent mounting. # cd /srv/test1 # touch {1..10} # ls -l For LVM: # pvcreate /dev/sdc1 # pvs # vgcreate LinuxVG /dev/sdc1 # vgs # lvcreate -L 500M -n LinuxLV LinuxVG # lvs # mkfs.xfs /dev/LinuxLV/LinuxVG # mkdir /srv/lvm # mount /dev/LinuxLV/LinuxVG /srv/lvm # df -hT # cd /srv/lvm # touch {a..m} # ls -l How to delete MBR partitions To delete a partition rm sub-command is used. Before we delete a partition it must be un-mounted. We cannot delete a mounted partition. Let’s see it practically. # umount /srv/test* # df -hT # parted /dev/sdb print rm 1 rm 2 rm 3 rm 5 print rm 4 print quit # partprobe Delete GPT partitions Deleting a GPT partition is as same as deleting a MBR partition. Initiate parted command with GPT disk (/dev/sdb) and use print command to view the number of partition and use rm sub command to delete that partition.
@mohdsuhail3545 Жыл бұрын
Waah sir , straight forward padhaya and in simple way in simple language.salute to you from depth of my heart
@jaysonkurtyka61866 ай бұрын
Thank you very much for the time you took to create this. It helps out with learning greatly!
@josemanuelmartinellreynald57853 ай бұрын
Greetings from Cuba. Very good video.
@avcoe1233 жыл бұрын
Thanks Vikas
@SIkanderKumar-e8g Жыл бұрын
Hello Sir... can I extend / partition through Parted command.. I was tried but given error that " /dev/sda4 is being used. you must unmount it before modify.. please support
@sawantyagi26222 жыл бұрын
Sir using parted command you did not select partion type as LVM while in fdisk we creats partion as LVM first . Then we creates file system .
@NehraClasses2 жыл бұрын
That is optional
@muhammadabbashussain3 жыл бұрын
Dear Sir, Here have Questions , Creating partition its requesting for system and by default its assigning ext2 then why again we need to write file system ? can you please help me in this regard. 2nd Question === Why are giving space as sector , can we left 1st part of size like 1M and parted should auto understand to left 1M as fdisk never ask for that. and can we give only size and system will auto calculate starting and ending sector information as per our size mentioned. ?
@NehraClasses3 жыл бұрын
1. mkpart part-type [fs-type] start end Make a part-type partition with filesystem fs-type (if specified), beginning at start and ending at end (by default in megabytes). fs-type can be one of "fat16", "fat32", "ext2", "HFS", "linux-swap", "NTFS", "reiserfs", or "ufs". part-type should be one of "primary", "logical", or "extended". Here inside parted utility ext2 is used for linux filesystems, where we can further format it either ext2, 3, 4 or xfs. 2. In fdisk utility if you might have focused while creating partition it starts the partition sectors from 2048 by default.
@tameshchakraborty19943 жыл бұрын
Sir correct me if m wrong.. we use parted if we need to create partition above 2TB right ? ? Anything less than 2 TB , we can use fdisk utility right ? or do you have more clarity to this point. please correct me if m wrong
@NehraClasses3 жыл бұрын
With parted command we can create partition of any size using any partition scheme, no matter whether it is MBR or GPT. With fdisk we can only use MBR partition scheme and we are allowed to create only upto 4 Primary Partitions. MBR partition scheme doesn't support disks more than 2 TB.
@tameshchakraborty19943 жыл бұрын
@@NehraClasses Thank you for the clarity!
@AjeetKumar-gt3yk Жыл бұрын
How to convert gpt to mbr in Ubuntu without data loss
@noZ3v11 ай бұрын
That accent is difficult to understand.
@NehraClasses11 ай бұрын
Subtitles are also available. You can focus on the commands if you are facing problems with the language.