(Resize) Expand a Hard Disk with Ubuntu LVM





root@samba:~# parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)                                                                 
(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 1074GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system  Flags
        32.3kB  1049kB  1016kB            Free Space
 1      1049kB  256MB   255MB   primary   ext2         boot
        256MB   257MB   1048kB            Free Space
 2      257MB   215GB   214GB   extended
 5      257MB   42.9GB  42.7GB  logical                lvm
 6      42.9GB  215GB   172GB   logical
 3      215GB   537GB   322GB   primary                lvm
        537GB   1074GB  537GB             Free Space <-- Free


quit

cfdisk

Pick your free space, select New, then choose a Primary or Logical partition. For a small server, it probably doesn't matter too much, but remember in x86 Linux that you can have a maximum of 4 primary + extended partitions per disk. Beyond that, you'll need to begin adding logical partitions in your extended partitions.
Select the Write command to create the partition, then (if necessary) reboot your system.

When your system comes back up, check on your new partition:

root@samba:~# fdisk -l /dev/sda
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x000e8eac

Device     Boot      Start        End    Sectors   Size Id Type
/dev/sda1  *          2048     499711     497664   243M 83 Linux
/dev/sda2           501758  419430399  418928642 199.8G  5 Extended
/dev/sda3        419430400 1048575999  629145600   300G 8e Linux LVM
/dev/sda4       1048576000 2097151999 1048576000   500G 83 Linux <-- New Partition
/dev/sda5           501760   83884031   83382272  39.8G 8e Linux LVM
/dev/sda6         83884095  419430399  335546305   160G 83 Linux
 root@samba:~# pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created
root@samba:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               samba-vg
  PV Size               39.76 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10178
  Free PE               0
  Allocated PE          10178
  PV UUID               0Zo1GS-K90O-SOh2-EHCG-yAHT-zjcx-HhbD5h
  
  --- Physical volume ---
  PV Name               /dev/sda6
  VG Name               samba-vg
  PV Size               160.00 GiB / not usable 4.97 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              40959
  Free PE               0
  Allocated PE          40959
  PV UUID               KPfysP-5dkB-Qoxo-0r4g-VEcp-8mjT-FU0EMq
  
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               samba-vg
  PV Size               300.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              76799
  Free PE               0
  Allocated PE          76799
  PV UUID               BrML5Z-MMcJ-Tqa6-8QHu-MPoe-BULq-8AJAjO
  
  "/dev/sda4" is a new physical volume of "500.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda4
  VG Name              
  PV Size               500.00 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Dc9PLA-aJW5-COwE-M9Sm-FFyA-MKaB-3Qov3W
  
root@samba:~# vgextend samba-vg /dev/sda4
  Volume group "samba-vg" successfully extended
root@samba:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/samba-vg/root
  LV Name                root
  VG Name                samba-vg
  LV UUID                ZG30J9-dkDd-fK5i-iqFO-xEGS-XJN5-bUOa42
  LV Write Access        read/write
  LV Creation host, time samba, 2015-07-23 10:45:02 +0700
  LV Status              available
  # open                 1
  LV Size                496.74 GiB
  Current LE             127166
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  
  --- Logical volume ---
  LV Path                /dev/samba-vg/swap_1
  LV Name                swap_1
  VG Name                samba-vg
  LV UUID                mSi6yB-O91P-OtFz-yblJ-Z42L-EtQ2-mQCJhc
  LV Write Access        read/write
  LV Creation host, time samba, 2015-07-23 10:45:03 +0700
  LV Status              available
  # open                 2
  LV Size                3.01 GiB
  Current LE             770
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
root@samba:~# pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created
root@samba:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               samba-vg
  PV Size               39.76 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10178
  Free PE               0
  Allocated PE          10178
  PV UUID               0Zo1GS-K90O-SOh2-EHCG-yAHT-zjcx-HhbD5h
  
  --- Physical volume ---
  PV Name               /dev/sda6
  VG Name               samba-vg
  PV Size               160.00 GiB / not usable 4.97 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              40959
  Free PE               0
  Allocated PE          40959
  PV UUID               KPfysP-5dkB-Qoxo-0r4g-VEcp-8mjT-FU0EMq
  
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               samba-vg
  PV Size               300.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              76799
  Free PE               0
  Allocated PE          76799
  PV UUID               BrML5Z-MMcJ-Tqa6-8QHu-MPoe-BULq-8AJAjO
  
  "/dev/sda4" is a new physical volume of "500.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda4
  VG Name              
  PV Size               500.00 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Dc9PLA-aJW5-COwE-M9Sm-FFyA-MKaB-3Qov3W
  
root@samba:~# vgextend samba-vg /dev/sda4
  Volume group "samba-vg" successfully extended
root@samba:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/samba-vg/root
  LV Name                root
  VG Name                samba-vg
  LV UUID                ZG30J9-dkDd-fK5i-iqFO-xEGS-XJN5-bUOa42
  LV Write Access        read/write
  LV Creation host, time samba, 2015-07-23 10:45:02 +0700
  LV Status              available
  # open                 1
  LV Size                496.74 GiB
  Current LE             127166
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  
  --- Logical volume ---
  LV Path                /dev/samba-vg/swap_1
  LV Name                swap_1
  VG Name                samba-vg
  LV UUID                mSi6yB-O91P-OtFz-yblJ-Z42L-EtQ2-mQCJhc
  LV Write Access        read/write
  LV Creation host, time samba, 2015-07-23 10:45:03 +0700
  LV Status              available
  # open                 2
  LV Size                3.01 GiB
  Current LE             770
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1


root@samba:~# lvextend -l+100%FREE /dev/samba-vg/root
  Size of logical volume samba-vg/root changed from 496.74 GiB (127166 extents) to 996.74 GiB (255165 extents).
  Logical volume root successfully resized.
 
root@samba:~# resize2fs /dev/mapper/samba--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/samba--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 32, new_desc_blocks = 63
The filesystem on /dev/mapper/samba--vg-root is now 261288960 (4k) blocks long.

root@samba:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                        2.0G     0  2.0G   0% /dev
tmpfs                       396M  6.1M  390M   2% /run
/dev/mapper/samba--vg-root  982G  447G  494G  48% /  <-- Resize OK
tmpfs                       2.0G     0  2.0G   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                       2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                   236M  148M   76M  67% /boot
cgmfs                       100K     0  100K   0% /run/cgmanager/fs
tmpfs                       396M     0  396M   0% /run/user/0



 




Komentar