نحوه‌ی افزایش هارد سرور مجازی لینوکس

بر اساس نوع پارتیشن بندی سرور لینوکس شما، مراحل انجام افزایش هارد (Expand Disk) به دو صورت انجام می شود.


در نظر داشته باشید مراحل زیر بسیار خطرناک بوده و ریسک از دست رفتن اطلاعات را در صورت انجام اشتباه مراحل همراه دارند. حتما از کلیه اطلاعات خود Backup تهیه نمایید.


پارتیشن بندی LVM) در این نوع می بایست فضای آزاد موجود پارتیشن بندی از نوع LVM شده و سپس از طریق Volume Group به مسیر روت اضافه گردد. بدین منظور مجموعه دستور زیر را اجرا نمایید.


fdisk /dev/sda  
n 
p 
3 
Enter 
Enter 
t 
3 
8e 
p 
w 
shutdown -r now 

*** After Reboot *** 
vgdisplay (نام ولیوم گروپ را یادداشت کنید) 
pvscan 
pvcreate /dev/sda3                
vgextend [Volume Group Name] /dev/sda3
pvscan
df -h (یادداشت فضای آزاد پارتیشن 3 و همچنین نام کامل ولیوم گروپ)
lvextend -l +100%FREE [Path of Volume Group]
resize2fs [Path of Volume Group]
df -h #The process has finished

پارتیشن بندی غیر LVM) در سرورهای لینوکسی که LVM نیستند می بایست از متد زیر استفاده کرد.

run “swapoff -a” to turn off all swap. Then go back into parted and delete the swap partition, so if it was number 3, you’d run parted and type “rm 3”. After this, edit /etc/fstab and remove the line pointing to the swap partition so your system doesn’t try to mount it at the next boot. Once you’ve done this,  you should be able to continue with the rest of this process.
 fdisk /dev/sda p d 2 n p 2 First cylinder: Exactly same value as the previous one +[Size]G #remember to leave free space for swap p 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.

                        

سرور را ریست می کنیم تا تغییرات اعمال گردد.

resize2fs /dev/sda2

حال می بایست مجدد SWAP را بسازیم.

fdisk /dev/sda n First cylinder: default Last cylinder: default t 3 82 w reboot mkswap /dev/sda3 #Copy UUID for fstab swapon vi /etc/fstab UUID=[UUID] swap swap defaults 0 0 :wq reboot cat /proc/swaps