High level overview
The high level steps are as follows
- VMWare – extend filesystem
- fdisk -l – check sizes before rescans
- To scan an existing device:
a. echo 1 > /sys/block/{device}/device/rescan - To scan for a new device
a. echo "- - -" > /sys/class/scsi_host/host0/scan
(different SCSI device might need to be used – check dmesg etc for further info as to which hostX device is in use) - fdisk -l (check again)
- fdisk /dev/{device}
a. p # --> Print partitions
b. d # --> Delete partition (as we are re-writing the boundary, we need to delete the original entry first)
c. n # --> New partition (write the new end boundary)
d. p # --> Choose primary partition (and specify the new boundaries - ensure the start is identical to before, the end is a larger value than before)
e. t # --> Specify the partition type (8e = Linux LVM)
f. p # --> Print partitions (compare to before, ensure the correct increase has been applied)
g. w # Write the new partition table to disk - partprobe -s
a. You may need to reboot at this stage, if an error says this can't be performed whilst the device is busy (or you can unmount filesystems, etc) - pvdisplay /dev/sda3
- pvresize /dev/{device} # --> This will automatically pick up the new capacity added to the partition
- pvdisplay /dev/sda3 # --> Check the new PV capacity
- lvextend -l +{number_PEs} /dev/{vg_name} # --> Add the new capacity to the LV which needs to be extended
- xfs_growfs /{filesystem}
Example
In this example we are adding capacity to the /dev/sda PV, so that the root filesystem can be extended. A reboot was required because the device was in use and the partition table couldn't be dynamically overwritten.
[robbie@linuxserver1 ~]$ sudo su -
Last login: Wed Dec 16 15:14:40 AEDT 2015 on pts/1
[root@linuxserver1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgos-root.fs 11G 3.6G 7.5G 32% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 289M 7.5G 4% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 997M 65M 932M 7% /boot
[root@linuxserver1 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: dos
Disk identifier: 0x0005b450
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 18827263 8388608 8e Linux LVM
/dev/sda3 18827264 41943039 11557888 8e Linux LVM
Disk /dev/mapper/vgos-root.fs: 11.8 GB, 11811160064 bytes, 23068672 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/mapper/vgswap-swap.fs: 8564 MB, 8564768768 bytes, 16728064 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/mapper/vgos-app1--poolmeta: 12 MB, 12582912 bytes, 24576 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/mapper/vgos-app1--pool: 4 MB, 4194304 bytes, 8192 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/mapper/app1-253:0-17011861-pool: 107.4 GB, 107374182400 bytes, 20971 5200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes
[root@linuxserver1 ~]# ll /sys/block/sda/device/rescan
--w-------. 1 root root 4096 Dec 17 09:11 /sys/block/sda/device/rescan
[root@linuxserver1 ~]# echo 1 > /sys/block/sda/device/rescan
[root@linuxserver1 ~]# fdisk -l | head -2
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
root@linuxserver1 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
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
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: dos
Disk identifier: 0x0005b450
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 18827263 8388608 8e Linux LVM
/dev/sda3 18827264 41943039 11557888 8e Linux LVM
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (18827264-62914559, default 18827264):
Using default value 18827264
Last sector, +sectors or +size{K,M,G} (18827264-62914559, default 62914559):
Using default value 62914559
Partition 3 of type Linux and of size 21 GiB is set
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: dos
Disk identifier: 0x0005b450
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 18827263 8388608 8e Linux LVM
/dev/sda3 18827264 62914559 22043648 83 Linux
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: dos
Disk identifier: 0x0005b450
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 18827263 8388608 8e Linux LVM
/dev/sda3 18827264 62914559 22043648 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@linuxserver1 ~]# partprobe -s
Error: Partition(s) 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
[root@linuxserver1 ~]# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@linuxserver1 ~]# reboot
login as: robbie
robbie@linuxserver1's password:
Last login: Thu Dec 17 08:51:59 2015 from 192.168.4.22
[robbie@linuxserver1 ~]$ sudo su -
Last login: Thu Dec 17 08:52:02 AEDT 2015 on pts/2
[root@linuxserver1 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vgswap
PV Size 8.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2047
Free PE 5
Allocated PE 2042
PV UUID FnpPHQ-Wh60-2enM-omUL-G63x-rkPB-hI8YHJ
--- Physical volume ---
PV Name /dev/sda3
VG Name vgos
PV Size 11.02 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2821
Free PE 1
Allocated PE 2820
PV UUID ME9lX0-PDYD-l2yg-ApJO-V6S4-8Zop-Crvwjy
[root@linuxserver1 ~]# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
[root@linuxserver1 ~]# pvdisplay /dev/sda3
--- Physical volume ---
PV Name /dev/sda3
VG Name vgos
PV Size 21.02 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5381
Free PE 2561
Allocated PE 2820
PV UUID ME9lX0-PDYD-l2yg-ApJO-V6S4-8Zop-Crvwjy
[root@linuxserver1 ~]# vgdisplay /dev/vgos
--- Volume group ---
VG Name vgos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 21.02 GiB
PE Size 4.00 MiB
Total PE 5381
Alloc PE / Size 2820 / 11.02 GiB
Free PE / Size 2561 / 10.00 GiB
VG UUID iM6US3-IIad-vWew-d75n-Fjma-ebGh-0MZBqp
[root@linuxserver1 ~]# lvextend -l +2560 /dev/vgos/root.fs
Size of logical volume vgos/root.fs changed from 11.00 GiB (2816 extents) to 21.00 GiB (5376 extents).
Logical volume root.fs successfully resized
[root@linuxserver1 ~]# xfs_growfs /
meta-data=/dev/mapper/vgos-root.fs isize=256 agcount=4, agsize=720896 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2883584, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2883584 to 5505024
[root@linuxserver1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgos-root.fs 21G 3.6G 18G 17% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.4M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 997M 65M 932M 7% /boot