Friday, October 26, 2012

Running out of disk space on a small VM at work used for the Cisco Call manger backups the other day I whacked up these notes below so I dont need to comb the internet again.....

Let me know if they are helpful or even if they crash your system!

Expanding LVM based disk size on the fly (Fedora 16+)

Used on Fedora 16 GPT partition table

This disk is sitting on  a VMware virtual machine - the VM GUI was used to add 40 GB to the existing 20 GB virtual disk, I then rebooted to pick up the change. Once rebooted I use fdisk to verify the 'physical' device, gdisk to modify the partition and resize it to the full extent as indicated by vmware. Once this is done the physical volume needs expanding (pvresize) and the logical volume needs extending (lvextend). A final filesystem resize (resize2fs) will allow the fs to be available for use. Again a final reboot checks everything. Reboots are not necessary as this can all be done on the fly.


STEP 1

# fdisk is no good on GPT tables but I used it to find the physical device name:


[root@HQ-SV-COMS-ARGUS ~]# fdisk -l

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 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 identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1   125829119    62914559+  ee  GPT

Disk /dev/mapper/vg_hqsvcomsargus-lv_swap: 4227 MB, 4227858432 bytes
255 heads, 63 sectors/track, 514 cylinders, total 8257536 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 identifier: 0x00000000

Disk /dev/mapper/vg_hqsvcomsargus-lv_swap doesn't contain a valid partition table

Disk /dev/mapper/vg_hqsvcomsargus-lv_root: 16.7 GB, 16710107136 bytes
255 heads, 63 sectors/track, 2031 cylinders, total 32636928 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 identifier: 0x00000000

Disk /dev/mapper/vg_hqsvcomsargus-lv_root doesn't contain a valid partition table

STEP 2

# fedora 16 doesnt have gdisk so I installed it:

yum install gdisk -y

# run gdisk on that device
gdisk /dev/sda

# print current status

Command (? for help): p
Disk /dev/sda: 125829120 sectors, 60.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C752E34E-343B-4021-A836-3515BB8240DC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 125829086
Partitions will be aligned on 2048-sector boundaries
Total free space is 83890109 sectors (40.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
  1            2048            4095   1024.0 KiB  EF02  
  2            4096         1028095   500.0 MiB   EF00  ext4
  3         1028096        41940991   19.5 GiB    8E00  

Command (? for help): d
Partition number (1-3): 3

Command (? for help): p
Disk /dev/sda: 125829120 sectors, 60.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C752E34E-343B-4021-A836-3515BB8240DC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 125829086
Partitions will be aligned on 2048-sector boundaries
Total free space is 124803005 sectors (59.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
  1            2048            4095   1024.0 KiB  EF02  
  2            4096         1028095   500.0 MiB   EF00  ext4

Command (? for help): n
Partition number (3-128, default 3):
First sector (34-125829086, default = 1028096) or {+-}size{KMGTP}:
Last sector (1028096-125829086, default = 125829086) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/sda: 125829120 sectors, 60.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C752E34E-343B-4021-A836-3515BB8240DC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 125829086
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  
  2            4096         1028095   500.0 MiB   EF00  ext4
  3         1028096       125829086   59.5 GiB    8E00  Linux LVM

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.
[root@HQ-SV-COMS-ARGUS ~]# reboot

STEP 3

hq-lt-icts-dag:~ root# ssh 10.180.12.96
root@10.180.12.96's password:
Last login: Fri Oct 26 10:21:58 2012 from 10.180.2.134
[root@HQ-SV-COMS-ARGUS ~]# pvdisplay
 --- Physical volume ---
 PV Name               /dev/sda3
 VG Name               vg_hqsvcomsargus
 PV Size               19.51 GiB / not usable 9.00 MiB
 Allocatable           yes (but full)
 PE Size               32.00 MiB
 Total PE              624
 Free PE               0
 Allocated PE          624
 PV UUID               BoP2za-jBDl-eajm-vqaM-abZ3-KorZ-P3Mm5b
  
[root@HQ-SV-COMS-ARGUS ~]# pvresize /dev/sda3
 Physical volume "/dev/sda3" changed
 1 physical volume(s) resized / 0 physical volume(s) not resized
[root@HQ-SV-COMS-ARGUS ~]# pvdisplay
 --- Physical volume ---
 PV Name               /dev/sda3
 VG Name               vg_hqsvcomsargus
 PV Size               59.51 GiB / not usable 8.98 MiB
 Allocatable           yes
 PE Size               32.00 MiB
 Total PE              1904
 Free PE               1280
 Allocated PE          624
 PV UUID               BoP2za-jBDl-eajm-vqaM-abZ3-KorZ-P3Mm5b
  
[root@HQ-SV-COMS-ARGUS ~]# df -h
Filesystem                            Size  Used Avail Use% Mounted on
rootfs                                 16G   12G  2.6G  83% /
devtmpfs                              992M     0  992M   0% /dev
tmpfs                                1002M     0 1002M   0% /dev/shm
tmpfs                                1002M  492K 1002M   1% /run
/dev/mapper/vg_hqsvcomsargus-lv_root   16G   12G  2.6G  83% /
tmpfs                                1002M     0 1002M   0% /sys/fs/cgroup
tmpfs                                1002M     0 1002M   0% /media
/dev/sda2                             485M   83M  377M  19% /boot
[root@HQ-SV-COMS-ARGUS ~]# pvscan
 PV /dev/sda3   VG vg_hqsvcomsargus   lvm2 [59.50 GiB / 40.00 GiB free]
 Total: 1 [59.50 GiB] / in use: 1 [59.50 GiB] / in no VG: 0 [0   ]

STEP 4

[root@HQ-SV-COMS-ARGUS ~]# lvextend -L +40G /dev/mapper/vg_hqsvcomsargus-lv_root
 Extending logical volume lv_root to 55.56 GiB
 Logical volume lv_root successfully resized
[root@HQ-SV-COMS-ARGUS ~]# df -h
Filesystem                            Size  Used Avail Use% Mounted on
rootfs                                 16G   12G  2.6G  83% /
devtmpfs                              992M     0  992M   0% /dev
tmpfs                                1002M     0 1002M   0% /dev/shm
tmpfs                                1002M  496K 1002M   1% /run
/dev/mapper/vg_hqsvcomsargus-lv_root   16G   12G  2.6G  83% /
tmpfs                                1002M     0 1002M   0% /sys/fs/cgroup
tmpfs                                1002M     0 1002M   0% /media
/dev/sda2                             485M   83M  377M  19% /boot
[root@HQ-SV-COMS-ARGUS ~]# resize2fs /dev/mapper/vg_hqsvcomsargus-lv_root
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/mapper/vg_hqsvcomsargus-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg_hqsvcomsargus-lv_root to 14565376 (4k) blocks.
The filesystem on /dev/mapper/vg_hqsvcomsargus-lv_root is now 14565376 blocks long.

[root@HQ-SV-COMS-ARGUS ~]# df -h
Filesystem                            Size  Used Avail Use% Mounted on
rootfs                                 55G   12G   41G  23% /
devtmpfs                              992M     0  992M   0% /dev
tmpfs                                1002M     0 1002M   0% /dev/shm
tmpfs                                1002M  496K 1002M   1% /run
/dev/mapper/vg_hqsvcomsargus-lv_root   55G   12G   41G  23% /
tmpfs                                1002M     0 1002M   0% /sys/fs/cgroup
tmpfs                                1002M     0 1002M   0% /media
/dev/sda2                             485M   83M  377M  19% /boot