Showing posts with label hardisk. Show all posts
Showing posts with label hardisk. Show all posts

Monday, November 14, 2022

Creating Partition Using cfdisk

Manipulating and partitioning hardisk can be a daunting task, especially for new sysadmin and if the disk has already contain data. Luckily, there is a tool that make this task easier, and that tool is called cfdisk.


First, we need to identify our disk name. This can be achieved by running lsblk
$ lsblk











Above is a sample output of lsblk. We can see that our disk name is sda (append /dev/ to the name for full path), and it has 130GB size. We can also see that only around 30GB has been used. We should have 100GB worth of free space for our new partition.

To start using cfdisk, just run it against the path of our disk, in this case /dev/sda
$ sudo cfdisk /dev/sda

We should be able to see this interface




















Move the cursor using the down arrow key on our keyboard, so that the cursor lies on the 107374.19MB line




















Make sure your cursor is at "New" button, and press Enter.

Choose "Primary" and press Enter.





















We want to use the whole free space, so just leave the size as it is, and press Enter.




















We now have a partition ready. To actually write the partition to the partition table, move your cursor using the right arrow key on the keyboard until it reached the "Write" button, and press Enter.




We will get  a warning message. Type "yes" and press Enter to confirm this action.



We will get this message once the partitioning is complete.



Quit cfdisk by choosing "Quit" and press Enter





















Eventhough we have created the partition, but sometimes the partition table is not automatically updated. Run "partprobe" to inform the OS of the partition table change.
$ sudo partprobe


Use "lsblk" to see that the new partition has been created
$ lsblk







Tuesday, August 14, 2018

Adding new virtual hard disk to existing RHV virtual machine

Login to your RHV/RHEV/ovirt console




Enter your administrator username and password



Once inside, search for your VM name



Scroll down, and choose Disk tab



Add details of your new virtual hard disk and click OK once done.



Make sure that your newly created disk is listed in the Disk tab



Login to your vm, and run lsblk to check your newly created disk
# lsblk 
NAME              MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
vdc               252:32   0   200G  0 disk 



Create partition on the new disk
# cfdisk /dev/vdc
Choose New --> Primary --> Set size --> Write --> answer 'yes' --> Quit



Run lsblk again to check if your partition is successfully created 
# lsblk 
NAME              MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
vdc               252:32   0   200G  0 disk 
└─vdc1            252:33   0   200G  0 part 



Make filesystem for your partition, in this case I want an ext4 partition
# mkfs.ext4 /dev/vdc1 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
...
Writing superblocks and filesystem accounting information: done   



Once done, you can mount your partition wherever you want
# mount /dev/vdc1 /mnt
# df -Th /mnt/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vdc1      ext4  197G   61M  187G   1% /mnt



Score!!

Wednesday, March 21, 2018

Creating large gpt partition using gdisk

Check the current partition

# parted /dev/sda print
Model: Cisco (scsi)
Disk /dev/sda: 78124994560s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start    End                Size                Type       File system  Name                             Flags
 1            2048s  4095s             2048s             primary                       Linux Filesystem
 2            4096s  4294967295s 4294963200s primary   xfs               Linux Filesystem           boot

Run gdisk on the disk
# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************
Command (? for help):

Press 'p' to print current partition, and to see how much free space is available
Command (? for help): p
Disk /dev/sda: 78124994560 sectors, 36.4 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): F0A6B5A3-3C91-47CE-BD70-FAD8A88DD132
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 78124994526
Partitions will be aligned on 2048-sector boundaries
Total free space is 73830029245 sectors (34.4 TiB)
Number  Start (sector)    End (sector)  Size              Code  Name
   1            2048               4095              1024.0 KiB  8300  Linux filesystem
   2            4096               4294967295  2.0 TiB         8300  Linux filesystem

Press 'n' to create new partition, and choose the default partition type, which is Linux filesystem
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-78124994526, default = 4294967296) or {+-}size{KMGTP}:
Last sector (4294967296-78124994526, default = 78124994526) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'

Press 't', and type 'ef02' to change the first partition type, to bios boot partition. This to make sure that that this partition will be used for grub reinstallation later
Command (? for help): t
Partition number (1-3): 1
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved
8e00 Linux LVM             a500 FreeBSD disklabel     a501 FreeBSD boot
a502 FreeBSD swap          a503 FreeBSD UFS           a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID    a580 Midnight BSD data     a581 Midnight BSD boot
a582 Midnight BSD swap     a583 Midnight BSD UFS      a584 Midnight BSD ZFS          a585 Midnight BSD Vinum    a800 Apple UFS             a901 NetBSD swap
a902 NetBSD FFS            a903 NetBSD LFS            a904 NetBSD concatenated
a905 NetBSD encrypted      a906 NetBSD RAID           ab00 Apple boot
af00 Apple HFS/HFS+        af01 Apple RAID            af02 Apple RAID offline
af03 Apple label           af04 AppleTV recovery      af05 Apple Core Storage
be00 Solaris boot          bf00 Solaris root          bf01 Solaris /usr & Mac Z
bf02 Solaris swap          bf03 Solaris backup        bf04 Solaris /var
bf05 Solaris /home         bf06 Solaris alternate se  bf07 Solaris Reserved 1
bf08 Solaris Reserved 2    bf09 Solaris Reserved 3    bf0a Solaris Reserved 4
bf0b Solaris Reserved 5    c001 HP-UX data            c002 HP-UX service
ed00 Sony system partitio  ef00 EFI System            ef01 MBR partition scheme
ef02 BIOS boot partition   fb00 VMWare VMFS           fb01 VMWare reserved
fc00 VMWare kcore crash p  fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): ef02
Changed type of partition to 'BIOS boot partition'

Press 'p' to check the changes that you have made
Command (? for help): p
Disk /dev/sda: 78124994560 sectors, 36.4 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): F0A6B5A3-3C91-47CE-BD70-FAD8A88DD132
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 78124994526
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02  BIOS boot partition
   2            4096      4294967295   2.0 TiB     8300  Linux filesystem
   3      4294967296     78124994526   34.4 TiB    8300  Linux filesystem

Press 'w' to write the changes to disk, and answer 'Y' for confirmation
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/sda.
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.

Reinstall grub, so that it will be located in the first partition of the hardisk
# grub2-install /dev/sdaInstalling for i386-pc platform.
Installation finished. No error reported.

Reboot the machine, for the new partition table to be activated
# reboot

Once booted, check whether the new partition has been successfully created, with GPT partition table 
# parted /dev/sda printModel: Cisco (scsi)
Disk /dev/sda: 40.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start       End        Size         File system  Name                        Flags
 1            1049kB  2097kB  1049kB                       BIOS boot partition  bios_grub
 2            2097kB  2199GB 2199GB  xfs               Linux filesystem
 3            2199GB 40.0TB   37.8TB                       Linux filesystem