User Tools

Site Tools


tech:documentation:procedures:vm:vm_disk_expansion_lvm_xfs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tech:documentation:procedures:vm:vm_disk_expansion_lvm_xfs [2010/03/17 15:30] kohofertech:documentation:procedures:vm:vm_disk_expansion_lvm_xfs [2020/10/13 16:46] (current) – [VM disk Expansion LVM with XFS/EXT4] kohofer
Line 1: Line 1:
-======VM disk Expansion LVM+XFS=======+====== VM disk Expansion LVM with XFS/EXT4 =======
  
-Expand the original disk or add a second vdisk from Infrastructure client.\\ If you want to perform grow w/o reboot you have to add second disk +Expand the original disk or add a second vdisk from **Infrastructure Client**.\\ 
-**THEN TAKE A SNAPSHOT!!!**+ 
 +If you are on kernel newer or equal to 2.6.32 then you can issue the command 
 + 
 +<code>echo "1" > /sys/block/sdX/device/rescan</code> 
 + 
 +to get the new size w/o reboot
 + 
 + 
 +In case you cant see the "disk" do this: 
 + 
 +  echo "- - -" > /sys/class/scsi_host/host0/scan 
 +   
 +Do this for all host0,1,2 etc. 
 + 
 + 
 +or 
 + 
 +  echo "1" > /sys/class/scsi_device/2\:0\:0\:0/device/rescan 
 + 
 +whereby after scsi_device you need to find the correct scsi device 
 + 
 +or 
 + 
 +  apt-get install scsitools 
 +  rescan-scsi-bus 
 + 
 +At the end it should list that new device was found, note down the name/number! 
 + 
 +  echo '1' > /sys/class/scsi_disk/32\:0\:1\:0/device/rescan 
 + 
 +IMPORTANT: Be sure to replace the 32\:0\:1\:0 with the appropriate disk for your purposes.  
 + 
 + 
 +**EXPAND ORIGINAL DISK** 
 + 
 +Create an additional partition on the free space, say you increased the existing disc 
 + 
 +from 8GB to 15GB. The partition type is 8e. 
 + 
 +  cfdisk /dev/sda or cfdisk /dev/sdb 
 + 
 + 
 +**RESIZE ORIGINAL DISK** 
 + 
 +Resize the already existing partition, e.g. /dev/sda4 to the newly created free partition. 
 + 
 +  cfdisk /dev/sda or cfdisk /dev/sdb 
 + 
 +Now resize the Physical Volume to the new size 
 + 
 +  pvresize /dev/sda4 
 + 
 +extend the logical volume 
 + 
 +  lvextend -l +100%FREE  /dev/data-www-vg/lvol-datawww 
 + 
 +next resize the file system 
 + 
 +  resize2fs -p /dev/data-www-vg/lvol-datawww 
 + 
 + 
 +If you get a error: 
 + 
 +<color #ed1c24>GPT PMBR size mismatch (2362232011 != 2516582399) will be corrected by w(rite).</color> 
 + 
 +run this command: 
 + 
 +  parted -l 
 + 
 +and when asked to Fix/Cancel? type **F** 
 + 
 +# for example if the new partition is /dev/sda3 
 + 
 +# create logical disk /dev/sda3 of type 8e (Linux LVM)
  
-then from on the vm either create an additional partition on the free space. The partition type is 8e 
-<code> 
-cfdisk /dev/sda 
-## for example if the new partition is /dev/sda3 
-## create logical disk /dev/sda3 
 # make disk visible to linux # make disk visible to linux
-partprobe 
-pvcreate /dev/sda3 
-</code> 
  
-if you are running a newer kernel you can issue this command to male linux re-read the disk geometry: +  partprobe 
-<code> +  pvcreate /dev/sda3
-echo "1"/sys/class/scsi_device/<device>/device/rescan +
-</code>+
  
-or assign the whole new disk to lvm assuming it'/dev/sdb +now you have to extend the volgroup. use ''lvdisplay'' to see which is the name of the group,\\ 
-<code> +in this example it'**base** 
-apt-get install scsitools + 
-rescan-scsi-bus.sh +  lvdisplay
-cfdisk /dev/sdb +
-### for example if the new partition is /dev/sda3 +
-pvcreate /dev/sdb +
-</code>+
  
-now you have to extend the volgroup. use ''lvdisplay'' to see which is the name of the group, in this example it's base 
 <code> <code>
-lvdisplay  
   --- Logical volume ---   --- Logical volume ---
   LV Name                /dev/base/root   LV Name                /dev/base/root
Line 86: Line 143:
   Read ahead sectors     0   Read ahead sectors     0
   Block device           254:3   Block device           254:3
 +</code>
  
 +and we assume the new partition is /dev/sda3
  
-</code> and we assume the new partition is /dev/sda3 +  vgextend base /dev/sda3
- +
-<code> +
-vgextend base /dev/sda3 +
-</code>+
  
 check with ''pvscan'' if the extend was successfull check with ''pvscan'' if the extend was successfull
  
-<code> +  pvscan
-pvscan +
-</code>+
  
 Now we extend the "data" partition to 11.5 GB. See man lvextend for other options\\ Now we extend the "data" partition to 11.5 GB. See man lvextend for other options\\
 11.5 G is the NEW total size of the disk we want to extend! 11.5 G is the NEW total size of the disk we want to extend!
  
-<code> +Extend the LV to use all free space 
-lvextend -L 11.5G  /dev/base/data +  lvextend -l +100%FREE /dev/base/data
-</code>+
  
 Extend with 20G Extend with 20G
- +  lvextend -L +20G  /dev/base/data 
-<code> +
-lvextend -L +20G  /dev/base/data  +
-</code>+
  
 now we have to grow the filesystem /data now we have to grow the filesystem /data
-<code> + 
-xfs_growfs /data +   xfs_growfs /data 
-</code>+ 
 + 
 +===== FOR EXT3/4 ===== 
 + 
 +Extend filesystem  to use all free space 
 + 
 +  vgextend base /dev/sda3 
 + 
 +  lvextend -l +100%FREE /dev/base/root 
 + 
 +Check that the filesystem is ok, **but only if the FS is unmounted** 
 + 
 +  fsck.ext4 -f /dev/base 
 + 
 +Now resize the filesystem 
 + 
 +Debian System: 
 + 
 +  resize2fs -p /dev/base/root 
 + 
 +Centos/Fedora System: 
 + 
 +  resize4fs -p /dev/base/root 
 + 
 +===== For swap ===== 
 + 
 +  swapoff /dev/base/swap 
 +  lvextend -L 3.9G /dev/base/swap 
 +  mkswap /dev/base/swap 
 +  swapon /dev/base/swap 
 +  free
  
 Check if filesystems are ok, and only then release the snapshot Check if filesystems are ok, and only then release the snapshot
 +
 +Fix issue with swap
 +
 +  * swapoff: /dev/dm-1: swapoff failed: Cannot allocate memory
 +
 +[[https://unix.stackexchange.com/questions/321675/unable-to-swapoff-but-enough-physical-memory-is-available/472012|Swapoff Cannot Allocate Memory]]
 +
 +<del>[[https://leizhilong.github.io/blog/2018-11-12-case-study-swapoff-cannot-allocate-memory/|Swapoff Cannot Allocate Memory]]</del>
 +
 +
 +======= Create LVM =======
 +
 +Find all LVM VG
 +
 +  vgscan
 +
 +Create Physical Volumes
 +
 +Der Befehl pvcreate legt den VGDA Block auf dem PV an. Er muss für jedes PV ausgeführt werden, bevor es von LVM verwendet werden kann:
 +
 +   pvcreate /dev/hda3
 +
 +Volume Groups anlegen
 +
 +Jetzt legen wir mit 'vgcreate <VolumeGroup> <Partition(en)>' unsere Volume Group an und nennen sie "vg01":
 +
 +   vgcreate vg01 /dev/hda3 /dev/hdb2
 +
 +Logische Volumes anlegen.
 +
 +Hier legen wir jetzt alle unsere logischen Volumes an. Als Namen verwenden wir, etwas fantasielos, lvol1, lvol2 und lvol3. Dabei bedienen wir uns mit dem Plattenplatz auf Volume Group vg01, der einzigen Volume Group in diesem Beispiel. Es ist offensichtlich, dass wir hier nicht mehr Plattenplatz "verteilen" können, als wir bei vgcreate in die Volume Group "hineingesteckt" haben, und zwar in Form der beiden Partitionen hda3 und hdb2. (lvcreate -L<Grösse> -n <LogicalVolumeName> <Volume Group>).
 +
 +   lvcreate -l +100%FREE -n lvol1 vg01
 +
 +oder wir könne die Größen angeben! (1500M)
 +
 +   lvcreate -L 1500M -n lvol1 vg01
 +
 +Filesysteme anlegen
 +
 +Ab jetzt können die logischen Partitionen, genau so wie gewöhnliche Partitionen, über Ihre Device Files angesprochen werden. Gewöhliche Partitionen werden mit /dev/sd[a-z]* oder /dev/hd[a-z]* bezeichnet; Logische Volumes werden mit /dev/VolumeGroupName/LogicalVolumeName angesprochen. Mit mke2fs <LogicalVolumeName> legen wir die ext2 Filesysteme an:
 +
 +  mkfs.ext4 /dev/vg01/lvol1
 +
 +fstab anpassen
 +
 +Damit die neuen Filesysteme nun bei jedem Systemstart automatisch gemountet werden, müssen wir sie in die Datei /etc/fstab eintragen (siehe 'man fstab'). In unserem Scenario sehen die zusätzlichen Einträge wie folgt aus:
 +
 +   /dev/vg01/lvol1 /usr ext4 defaults 1 2
 +
 +===== Links =====
 +
 +
 +[[http://www.thegeekstuff.com/2010/08/how-to-create-lvm/|How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands]]\\
 +[[https://unix.stackexchange.com/questions/47380/where-does-lvm-store-data|Where does LVM store data?]]\\
 +[[http://www.howtoforge.com/linux_lvm|A Beginner's Guide To LVM]]\\
 +[[http://wiki.gentoo.org/wiki/LVM#LV_.28Logical_Volume.29|LVM]] VERY GOOD SOURCE!\\
 +[[http://www.funtoo.org/LVM_Fun#Physical_volumes_creation|LVM Fun]] VERY GOOD SOURCE!\\
 +[[http://serverfault.com/questions/223361/how-to-recover-logical-volume-deleted-with-lvremove|How to recover logical volume deleted with lvremove]]\\
 +[[http://www.novell.com/support/kb/doc.php?id=3803380|LVM Volume Group Shows "unknown device"]]
 +
 +[[https://www.tutorialspoint.com/unix_commands/pvresize.htm|pvresize - Unix, Linux Command]]
 +
 +http://www.linuxhaven.de/dlhp/HOWTO-test/DE-LVM-HOWTO-2.html\\
 +http://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/
/data/www/wiki.inf.unibz.it/data/attic/tech/documentation/procedures/vm/vm_disk_expansion_lvm_xfs.1268836222.txt.gz · Last modified: 2019/01/16 10:03 (external edit)