{"id":1214,"date":"2018-05-21T13:41:13","date_gmt":"2018-05-21T18:41:13","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1214"},"modified":"2018-05-21T13:41:13","modified_gmt":"2018-05-21T18:41:13","slug":"lvm-resize-root-volume","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/lvm-resize-root-volume\/","title":{"rendered":"LVM resize root volume"},"content":{"rendered":"
Since this is a root\/boot volume we are talking about anything on this page is VERY risky.\u00a0 Be warned this post may provide you with a strategy or hints but you are completely responsible for your system.<\/span><\/p>\n Of course the best route to extend a root volume in an unmounted state is to boot of a Live CD.\u00a0 In some cases and even more relevant a lot of cloud instances you do not have normal physical or virtualization methods to access server consoles.<\/p>\n I have been trying a couple ideas.\u00a0 First one is using dracut to resize the root volume on system bootup.\u00a0 I have had success with this method.\u00a0 The second method is using pivot_root.\u00a0 On this method it may be slightly easier on systemd servers but for my paritcular need I have an older Centos 6 flavor without systemd and so far I could not get pivot_root and resize online to work.<\/p>\n Below is notes on method 1 (dracut resize):<\/p>\n Specs: GOAL: Verify after the reboot<\/p>\n ** remove custom code from mount-root.sh<\/p>\n ################################################################# ** Howto check if lvm and resize2fs is in intramfs image<\/p>\n ################################################################# Kernel panic on boot following \"dracut Warning: LVM rootvg\/rootlv not found\": https:\/\/access.redhat.com\/solutions\/1282013 Is it possible to on-line shrink a EXT4 volume with LVM?: https:\/\/serverfault.com\/questions\/528075\/is-it-possible-to-on-line-shrink-a-ext4-volume-with-lvm\/528076 [\/bash]<\/p>\n","protected":false},"excerpt":{"rendered":" Since this is a root\/boot volume we are talking about anything on this page is VERY risky.\u00a0 Be warned this<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1214","post","type-post","status-publish","format-standard","hentry","category-lvm"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1214"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1214\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\nVirtualBox VM CentOS6.4
\nDisk layout 15G
\n- \/boot 200M ext4
\n- \/ LV 13G ext4
\n- \/u01 LV 2G ext4<\/p>\n
\n1. Resize \/ file system smaller without boot CD only SSH access. Using dracut bootup.
\n2. Extend \/u01 with the additional space in the VG<\/p>\n\t\r\n[root@localhost ~]# df -h\r\nFilesystem Size Used Avail Use% Mounted on\r\n\/dev\/mapper\/VolGroupSys-LogVolRoot\r\n 11G 2.1G 8.7G 20% \/\r\ntmpfs 1.9G 0 1.9G 0% \/dev\/shm\r\n\/dev\/sda1 194M 29M 155M 16% \/boot\r\n\/dev\/mapper\/VolGroupSys-LogVolU01\r\n 2.1G 68M 2.0G 4% \/u01\r\n[root@localhost ~]# pvs\r\n PV VG Fmt Attr PSize PFree\r\n \/dev\/sda2 VolGroupSys lvm2 a-- 14.80g 1.70g\r\n\r\n[root@localhost ~]# vgs\r\n VG #PV #LV #SN Attr VSize VFree\r\n VolGroupSys 1 2 0 wz--n- 14.80g 1.70g\r\n\r\n[root@localhost ~]# lvs\r\n LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert\r\n LogVolRoot VolGroupSys -wi-ao--- 11.00g \r\n LogVolU01 VolGroupSys -wi-ao--- 2.11g \r\n \r\n# pwd\r\n\/usr\/share\/dracut\/modules.d\/95rootfs-block\r\n\r\n# vi mount-root.sh\r\n[..]\r\nif [ -n "$root" -a -z "${root%%block:*}" ]; then\r\n ## custom code testing lvresize on root vol\r\n lvm vgchange -ay --config " global {locking_type=1} "\r\n rm -f \/etc\/lvm\/lvm.conf\r\n e2fsck -C 0 -f \/dev\/VolGroupSys\/LogVolRoot\r\n resize2fs -p -f \/dev\/VolGroupSys\/LogVolRoot 8G\r\n lvm lvresize -f \/dev\/VolGroupSys\/LogVolRoot -L 8G\r\n resize2fs -p -f \/dev\/VolGroupSys\/LogVolRoot\r\n e2fsck -C 0 -f \/dev\/VolGroupSys\/LogVolRoot\r\n\r\n mount -t ${fstype:-auto} -o "$rflags" "${root#block:}" "$NEWROOT" \\\r\n[..]\r\n\t\r\n# dracut -f --install 'resize2fs e2fsck'\r\n\r\n# reboot\r\n<\/pre>\n
\r\n# pvs\r\n PV VG Fmt Attr PSize PFree\r\n \/dev\/sda2 VolGroupSys lvm2 a-- 14.80g 4.70g\r\n\r\n# vgs\r\n VG #PV #LV #SN Attr VSize VFree\r\n VolGroupSys 1 2 0 wz--n- 14.80g 4.70g\r\n\r\n# lvs\r\n LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert\r\n LogVolRoot VolGroupSys -wi-ao--- 8.00g \r\n LogVolU01 VolGroupSys -wi-ao--- 2.11g \r\n\r\n# df -h\r\nFilesystem Size Used Avail Use% Mounted on\r\n\/dev\/mapper\/VolGroupSys-LogVolRoot\r\n 7.9G 2.1G 5.8G 26% \/\r\ntmpfs 1.9G 0 1.9G 0% \/dev\/shm\r\n\/dev\/sda1 194M 30M 155M 16% \/boot\r\n\/dev\/mapper\/VolGroupSys-LogVolU01\r\n 2.1G 68M 2.0G 4% \/u01\r\n<\/pre>\n
\r\n# dracut -f\r\n# reboot\r\n<\/pre>\n
\n### EXTEND u01
\n#################################################################<\/p>\n\r\n# lvextend -L+2G \/dev\/VolGroupSys\/LogVolU01 \r\n Extending logical volume LogVolU01 to 4.11 GiB\r\n Logical volume LogVolU01 successfully resized\r\n\r\n# resize2fs \/dev\/VolGroupSys\/LogVolU01 \r\nresize2fs 1.41.12 (17-May-2010)\r\nFilesystem at \/dev\/VolGroupSys\/LogVolU01 is mounted on \/u01; on-line resizing required\r\nold desc_blocks = 1, new_desc_blocks = 1\r\nPerforming an on-line resize of \/dev\/VolGroupSys\/LogVolU01 to 1076224 (4k) blocks.\r\nThe filesystem on \/dev\/VolGroupSys\/LogVolU01 is now 1076224 blocks long.\r\n\r\n# vgs\r\n VG #PV #LV #SN Attr VSize VFree\r\n VolGroupSys 1 2 0 wz--n- 14.80g 2.70g\r\n\r\n# lvs\r\n LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert\r\n LogVolRoot VolGroupSys -wi-ao--- 8.00g \r\n LogVolU01 VolGroupSys -wi-ao--- 4.11g \r\n\r\n# df -h\r\nFilesystem Size Used Avail Use% Mounted on\r\n\/dev\/mapper\/VolGroupSys-LogVolRoot\r\n 7.9G 2.1G 5.8G 26% \/\r\ntmpfs 1.9G 0 1.9G 0% \/dev\/shm\r\n\/dev\/sda1 194M 29M 155M 16% \/boot\r\n\/dev\/mapper\/VolGroupSys-LogVolU01\r\n 4.1G 69M 3.8G 2% \/u01\r\n\r\n#################################################################\t\t\t\t\t \r\n### APPENDIX: \r\n#################################################################\r\n\r\n** Use \/var\/messages\/boot.log to check dracut failures on our custom code\r\n[bash]\r\n# more boot.log \r\ne2fsck 1.41.12 (17-May-2010)\r\nPass 1: Checking inodes, blocks, and sizes\r\n_CentOS-6.4-x86_: |=== - 4.8% \r\nPass 2: Checking directory structure \r\nPass 3: Checking directory connectivity \r\nPass 4: Checking reference counts\r\nPass 5: Checking group summary information\r\n_CentOS-6.4-x86_: 76680\/835584 files (0.1% non-contiguous), 578555\/3328000 blocks\r\nresize2fs 1.41.12 (17-May-2010)\r\nResizing the filesystem on \/dev\/VolGroupSys\/LogVolRoot to 2621440 (4k) blocks.\r\nBegin pass 3 (max = 102)\r\nScanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nThe filesystem on \/dev\/VolGroupSys\/LogVolRoot is now 2621440 blocks long.\r\n\r\n Read-only locking type set. Write locks are prohibited.\r\n Can't get lock for VolGroupSys\r\nresize2fs 1.41.12 (17-May-2010)\r\nResizing the filesystem on \/dev\/VolGroupSys\/LogVolRoot to 3328000 (4k) blocks.\r\nBegin pass 1 (max = 22)\r\nExtending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nThe filesystem on \/dev\/VolGroupSys\/LogVolRoot is now 3328000 blocks long.\r\n[..]\r\n<\/pre>\n
\r\n# lsinitrd \/boot\/initramfs-2.6.32-358.el6.x86_64.img | grep lvm\r\n-rw-r--r-- 1 root root 657 Feb 22 2013 etc\/udev\/rules.d\/64-lvm.rules\r\n-r--r--r-- 1 root root 1286 Feb 22 2013 etc\/udev\/rules.d\/11-dm-lvm.rules\r\ndrwxr-xr-x 2 root root 0 May 21 13:27 etc\/lvm\r\n-rw-r--r-- 1 root root 37554 May 21 13:27 etc\/lvm\/lvm.conf\r\n-rwxr-xr-x 1 root root 2243 Feb 22 2013 sbin\/lvm_scan\r\n-r-xr-xr-x 1 root root 1013336 May 21 13:27 sbin\/lvm\r\n[..]\r\n-rwxr-xr-x 1 root root 525 Feb 22 2013 cmdline\/30parse-lvm.sh\r\n\r\n# lsinitrd \/boot\/initramfs-2.6.32-358.el6.x86_64.img | grep resize2fs\r\n<\/pre>\n
\n#### Some links ...
\n#################################################################<\/p>\n
\nRename LVM Volume Group Holding Root File System Volume: https:\/\/oraganism.wordpress.com\/2013\/03\/09\/rename-lvm-vg-for-root-fs-lv\/
\nHow to debug Dracut problems: https:\/\/fedoraproject.org\/wiki\/How_to_debug_Dracut_problems
\nInject ephemeral disk into root disk: https:\/\/github.com\/eucalyptus\/eucalyptus\/wiki\/Inject-ephemeral-disk-into-root-disk
\nConvert an Existing System to Use Thin LVs: https:\/\/dustymabe.com\/2013\/09\/07\/convert-an-existing-system-to-use-thin-lvs\/
\nPartition Resize fails on LVM: https:\/\/github.com\/flegmatik\/linux-rootfs-resize\/issues\/8
\nHow to write a pre-mount startup script?: https:\/\/unix.stackexchange.com\/questions\/87814\/how-to-write-a-pre-mount-startup-script<\/p>\n
\nresize a Linux root partition while it's still mounted: http:\/\/www.ivarch.com\/blogs\/oss\/2007\/01\/resize-a-live-root-fs-a-howto.shtml
\nHow to shrink root filesystem without booting a livecd: https:\/\/unix.stackexchange.com\/questions\/226872\/how-to-shrink-root-filesystem-without-booting-a-livecd?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa<\/p>\n