Author Topic: Combine second partition to the root  (Read 7867 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Combine second partition to the root
« on: March 14, 2018, 11:44:51 AM »
 I have expanded storage in my provider, and I do not know how to add that partition to centos web panel that does not recognize me

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M   65M  331M  17% /run
/dev/vda         46G   16G   28G  37% /
tmpfs           2.0G  8.0K  2.0G   1% /dev/shm
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           395M     0  395M   0% /run/user/1006

 fdisk -l

Disk /dev/vda: 50.0 GB, 50000000000 bytes, 97656250 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 /dev/vdb: 50.0 GB, 50000000000 bytes, 97656250 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

Offline
*
Re: Combine second partition to the root
« Reply #1 on: March 15, 2018, 06:58:09 PM »
I am already moving something ... I have managed to mount the unit and already centos web panel recognizes the unit. Now I would like to be able to add that extension to the / home folder to have more space in existing accounts.
I have added / dev / vdb / home / vxd ext4 defaults 0 2 in / etc / fstab to mount the partition automatically.
« Last Edit: March 15, 2018, 06:59:49 PM by vxdas »

Offline
*
Re: Combine second partition to the root
« Reply #2 on: March 21, 2018, 01:53:16 PM »
Partitioning the new disk

Now we need to partition the new disk / dev / sdv so that it can be used, this is done by using fdisk.

fdisk / dev / vdb

Once the command has been executed, we will select the option 'n' to add a new partition:

root @ cloud: ~ # fdisk / dev / vdb
Command (m for help): n
Later we will select the option 'p' to make the primary partition:

Command action
   e extended
   p primary partition (1-4)
p
 

As it is a new album, we still do not have any particiin, then we will select 1

Partition number (1-4): 1
 
Next, we press 'Enter' twice, since, by default, the first and the last cylinder of the unallocated space must be correct.


First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-2610, default 2610): "enter"
Using default value 2610
 

't' is selected to change to a partition system ID, in this case we change to '1' automatically since it is our only partition.
Command (m for help): t
Selected partition 1
 
He entered the hexadecimal code '8e', since this is the code for a Linux LVM, since we will join it with the original Linux LVM that currently uses / dev / sda5.
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
 
'w' is used to write the table on the disk and exit, all changes that have been made will be saved and then it will leave fdisk.
Command (m for help): w
The partition table has been altered!

Calling ioctl () to re-read partition table.
Syncing disks.
 
By using "fdisk -l" you can now see that / dev / sdv1 appears in the list, this is the new partition created on our disk in / dev / sdb just added and is currently using the 20 gb of space.
fdisk after partition created
 
Step 4. Increasing the logical volume

Next, we will use the pvcreate command to create a physical volume for later use by LVM. In this case, the physical volume will be our new partition / dev / sdb1
root @ cloud: ~ # pvcreate / dev / vdb1
  Physical volume "/ dev / vdb1" successfully created

Now we need to confirm the name of the current volume group using the vgdisplay command. The name will vary according to your configuration, for me it will be the name of my test server. vgdisplay provides a lot of information about the volume group, I will only show the current name and size for this example.
root @ cloud: ~ # vgdisplay
  --- Volume group ---
  VG Name cloud
  VG Size 19.76 GiB
 
Now, using the vgextend command, we expand the 'cloud' volume group by adding the physical volume / dev / vdb1 that we created using the pvcreate command just before.
root @ cloud: ~ # vgextend cloud / dev / vdb1
  Volume group "cloud" successfully extended
 
Using the pvscan command we scan all disks for physical volumes, this should confirm the original / dev / sda5 partition and the newly created / dev / vdb1 physical volume
root @ cloud: ~ # pvscan
  PV / dev / sda5 VG cloud lvm2 [19.76 GiB / 0 free]
  PV / dev / sdb1 VG cloud lvm2 [19.99 GiB / 19.99 GiB free]
  Total: 2 [39.75 GiB] / in use: 2 [39.75 GiB] / in no VG: 0

 
Next, we need to increase the logical volume with the lvextend command (instead of the physical volume that we have already done). This means that we will take our original logical volume and expand it on our new disk / partition / physical volume of / dev / vdb1
First confirm the name of the logical volume using lvdisplay. The name will vary according to your configuration.
root @ cloud: ~ # lvdisplay
  --- Logical volume ---
  LV Name / dev / cloud / root
  LV Size 18.91 GiB
 
The / dev / cloud / root logical volume will be extended using the lvextend command with the newest / dev / vdb1 partition space
root @ cloud: ~ # lvextend / dev / cloud / root / dev / vdb1
  Extending logical volume root to 38.90 GiB
  Logical volume root successfully resized
 
If you wish, you can run vgdisplay and lvdisplay again to confirm the size of the volume group and the logical volume, respectively:
  LV Size 38.90 GiB
  VG Size 39.75 GiB
 
If you run a "df" command to see the space available on the disk, it will not have changed yet, since there is a last step, we have to resize the file system using the resize2fs command to make use of this space.
root @ cloud: ~ # resize2fs / dev / cloud / root
resize2fs 1.41.12 (May 17, 2010)
Filesystem at / dev / cloud / root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of / dev / cloud / root to 10196992 (4k) blocks.
The filesystem on / dev / cloud / root is now 10196992 blocks long.
 
VERY IMPORTANT:

Alternatively, if you are running the XFS file system (by default from RedHat / CentOS 7) you can grow the file system with "xfs_growfs / dev / cloud / root".

Offline
*
Re: Combine second partition to the root
« Reply #3 on: March 21, 2018, 01:54:59 PM »
I still have not confirmed if you can lose data from the folder / home ;D