Skip to content

Instantly share code, notes, and snippets.

@itzg
Last active September 6, 2023 22:22
Show Gist options
  • Select an option

  • Save itzg/0ab1fd188a7c19416e3b to your computer and use it in GitHub Desktop.

Select an option

Save itzg/0ab1fd188a7c19416e3b to your computer and use it in GitHub Desktop.

Revisions

  1. itzg revised this gist Mar 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Add more physical space to an LVM volume.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Find and create a partition with free space:

    root@nuc:/home/geoff# parted
    # parted
    GNU Parted 2.3
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
  2. itzg created this gist Mar 13, 2015.
    102 changes: 102 additions & 0 deletions Add more physical space to an LVM volume.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,102 @@
    Find and create a partition with free space:

    root@nuc:/home/geoff# parted
    GNU Parted 2.3
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print free
    Model: ATA Crucial_CT240M50 (scsi)
    Disk /dev/sda: 240GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt

    Number Start End Size File system Name Flags
    17.4kB 1049kB 1031kB Free Space
    1 1049kB 512MB 511MB fat32 EFI System Partition boot
    2 512MB 768MB 256MB ext2 msftdata
    3 768MB 18.8GB 18.0GB swap_1 lvm
    4 18.8GB 68.8GB 50.0GB lvm
    5 68.8GB 83.8GB 15.0GB es
    6 83.8GB 100GB 16.2GB docker
    100GB 240GB 140GB Free Space

    We'll carve out a new 20GB partition:

    (parted) mkpart
    Partition name? []? docker-2
    File system type? [ext2]?
    Start? 100GB
    End? 120GB
    (parted) print
    Model: ATA Crucial_CT240M50 (scsi)
    Disk /dev/sda: 240GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt

    Number Start End Size File system Name Flags
    1 1049kB 512MB 511MB fat32 EFI System Partition boot
    2 512MB 768MB 256MB ext2 msftdata
    3 768MB 18.8GB 18.0GB swap_1 lvm
    4 18.8GB 68.8GB 50.0GB lvm
    5 68.8GB 83.8GB 15.0GB es
    6 83.8GB 100GB 16.2GB docker
    7 100GB 120GB 20.0GB docker-2

    (parted) quit

    So `/dev/sda7` is our new physical allocation, but we need to bless it:

    # pvcreate /dev/sda7
    Physical volume "/dev/sda7" successfully created

    Let's see the name of the volume group and logical volume we need to target:

    # lvs
    LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
    docker_lib vg_docker -wi-ao--- 15.09g
    es vg_es -wi-ao--- 14.00g
    root vg_nuc -wi-ao--- 46.56g
    swap vg_swap -wi-ao--- 16.76g

    The volume is `docker_lib` but first we need to adjust its volume group, `vg_docker`:

    # vgextend vg_docker /dev/sda7
    Volume group "vg_docker" successfully extended

    And to cross check that:

    # vgs
    VG #PV #LV #SN Attr VSize VFree
    vg_docker 2 1 0 wz--n- 33.71g 18.62g
    vg_es 1 1 0 wz--n- 14.00g 0
    vg_nuc 1 1 0 wz--n- 46.56g 0
    vg_swap 1 1 0 wz--n- 16.76g 0

    Resize the logical volume (and its filesystem):

    # lvresize --extents +100%FREE -r vg_docker/docker_lib
    Extending logical volume docker_lib to 33.71 GiB
    Logical volume docker_lib successfully resized
    resize2fs 1.42.9 (4-Feb-2014)
    Filesystem at /dev/mapper/vg_docker-docker_lib is mounted on /var/lib/docker; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 3
    The filesystem on /dev/mapper/vg_docker-docker_lib is now 8837120 blocks long.

    Awesome, it resized while online/in-use. Let's check:

    # df -H
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/vg_nuc-root 50G 20G 28G 42% /
    none 4.1k 0 4.1k 0% /sys/fs/cgroup
    udev 8.4G 13k 8.4G 1% /dev
    tmpfs 1.7G 1.3M 1.7G 1% /run
    none 5.3M 0 5.3M 0% /run/lock
    none 8.4G 1.8M 8.4G 1% /run/shm
    none 105M 0 105M 0% /run/user
    /dev/sda2 248M 151M 85M 65% /boot
    /dev/sda1 510M 7.0M 503M 2% /boot/efi
    /dev/mapper/vg_es-es 15G 3.2G 11G 23% /var/lib/elasticsearch
    /dev/mapper/vg_docker-docker_lib 36G 14G 20G 41% /var/lib/docker


    > Written with [StackEdit](https://stackedit.io/).