Fdisk & Gdisk

From DikapediaV2
Revision as of 00:15, 27 August 2024 by Ardika Sulistija (talk | contribs) (Created page with "If you do not know whether the VM uses MBR or GPT partitions, log into the VM as root and enter one of the following commands. * **fdisk -l /dev/xvda** - For MBR partitions, the operating system will be shown in the Disklabel type field. # fdisk -l /dev/xvda Welcome to fdisk (util-linux 2.27.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 Disk /dev/xvd...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If you do not know whether the VM uses MBR or GPT partitions, log into the VM as root and enter one of the following commands.

  • **fdisk -l /dev/xvda** - For MBR partitions, the operating system will be shown in the Disklabel type field.
   # fdisk -l /dev/xvda

   Welcome to fdisk (util-linux 2.27.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
   Disk /dev/xvda: 9 GiB, 9663676416 bytes, 18874368 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: 0xe5c7298c


  • **gdisk -l /dev/xvda** - For GPT partitions, the GPT field in the Partition Label Scan section will display "present".
# gdisk -l /dev/xvda 
 
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

The Protective MBR protects GUID Partition Table disks from previously-released MBR disk tools such as Microsoft MS-DOS FDISK or Microsoft Windows NT Disk Administrator. These tools are not aware of GUID Partition Table and do not know how to properly access a GUID Partition Table disk.

How to create extended partition using fdisk


https://www.thegeekdiary.com/linux-unix-how-to-create-extended-partition-using-fdisk/


Use this if you just attached a /dev/xvdb disk and you want to make /dev/xvdb1 available:

$ fdisk /dev/nvme1n1p1
Disk /dev/nvme1n1p1: 205.0 GB, 204998951936 bytes, 400388578 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 label type: gpt
Disk identifier: 8ADED94B-5295-4B97-BCB4-74DB3348EB1E


#         Start          End    Size  Type            Name

Command (m for help): m
Command action
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only) 

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-400388544, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-400388544, default 400388544): +20G
Created partition 1
 

Command (m for help): n
Partition number (2-4, default 2):
First sector (41945088-400388544, default 41945088):
Last sector, +sectors or +size{K,M,G,T,P} (41945088-400388544, default 400388544): +30G
Created partition 2 


Command (m for help): w
The partition table has been altered!
  • https://www.howtogeek.com/106873/how-to-use-fdisk-to-manage-partitions-on-linux/
    • specify the last sector of the partition on the disk. If you want to use up all available space after the initial sector, just press Enter. You can also specify a specific size, such as +5G for a five gigabyte partition or +512M for a 512 megabyte partition. If you don’t specify a unit after the + sign, fdisk uses sectors as the unit. For example, +10000 results in the end of the partition being 10000 sectors after its beginning.


Creating a Boot Partition on the AWS Root Volume


https://docs.hytrust.com/DataControl/4.3/Online/Content/Books/Admin-Guide/Linux-Root-Swap-Drive-Encryption/Creating-Boot-Partition-on-AWS-Root-Volume-Admin-Guide.html


[root@ip-172-31-94-208 ec2-user]# gdisk /dev/xvda
GPT fdisk (gdisk) version 0.8.10 

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present 

Found valid GPT with protective MBR; using GPT. 

Command (? for help): x 

Expert command (? for help): e
Relocating backup data structures to the end of the disk  

Expert command (? for help): m 

Command (? for help): p
Disk /dev/xvda: 23068672 sectors, 11.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E5D51EAD-EA94-46B7-8EF5-CE2BBB0BF57C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 23068638
Partitions will be aligned on 2048-sector boundaries
Total free space is 2099166 sectors (1.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        20971486   10.0 GiB    0700   

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-23068638, default = 20971520) or {+-}size{KMGTP}: 
Last sector (20971520-23068638, default = 23068638) or {+-}size{KMGTP}: +250M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data' 

Command (? for help): c
Partition number (1-2): 2
Enter name:  
 
Command (? for help): p
Disk /dev/xvda: 23068672 sectors, 11.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E5D51EAD-EA94-46B7-8EF5-CE2BBB0BF57C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 23068638
Partitions will be aligned on 2048-sector boundaries
Total free space is 1587166 sectors (775.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        20971486   10.0 GiB    0700  
   2        20971520        21483519   250.0 MiB   0700   

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!! 

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@ip-172-31-94-208 ec2-user]# reboot 

Broadcast message from ec2-user@ip-172-31-94-208.ec2.internal
	(/dev/pts/0) at 22:42 ...

The system is going down for reboot NOW!
[root@ip-172-31-94-208 ec2-user]# Connection to 54.174.120.229 closed by remote host.
Connection to 54.174.120.229 closed.
38f9d3587610:~ ardikas$ ssh -i .ssh/ec2_nva_key.pem ec2-user@54.174.120.229
ssh: connect to host 54.174.120.229 port 22: Operation timed out
38f9d3587610:~ ardikas$ ssh -i .ssh/ec2_nva_key.pem ec2-user@54.174.120.229
Last login: Wed Jul 13 22:38:39 2022 from 72-21-198-65.amazon.com
[ec2-user@ip-172-31-94-208 ~]$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   11G  0 disk 
├─xvda1 202:1    0   10G  0 part /
└─xvda2 202:2    0  250M  0 part