Tuesday, December 24, 2019

Tăng/mở rộng ổ cứng Ubuntu

Cách 1: Tắt máy chủ, khởi động lại server
You do not need a live CD for this to work. I’m basically summarizing the other answers given here:
  1. From Ubuntu (in VM) install gparted by executing sudo apt-get install gpartedin terminal
  2. Open sudo gpartedfrom terminal
  3. Rightclick on the swap partition, click “swapoff”
  4. Delete swap partition
  5. Extend your data partition, but leave enough space to create a new swap partition
  6. Recreate swap partition with about the same size as before, select linux-swap as file system
  7. Click that green tick in gparted to apply all operations. Then select “swapon” to enable swap again
Cách 2: Tóm lược
Sử dụng command line, không cần phải reboot lại server.
You should first delete all partitions between your partition and free space. You can do it using parted command.
1/ Turn off swap. we gonna remove it’s partition!
sudo swapoff -a
2/  run sudo parted.
3/ get partitions list with print all:
  • (parted) print all
  • Model: Virtio Block Device (virtblk)
  • Disk /dev/vda: 752GB
  • Sector size (logical/physical): 512B/512B
  • Partition Table: msdos
  • Disk Flags:
  • Number  Start   End    Size    Type      File system     Flags
  • 1      1049kB  528GB  528GB   primary   ext4            boot
  • 2      528GB   537GB  8588MB  extended
  • 5      528GB   537GB  8588MB  logical   linux-swap(v1)
4/ remove none root partitions with rm (part-index):
  • (parted) rm 5
  • Warning: Partition /dev/vda5 is being used. Are you sure you want to continue?
  • Yes/No? yes
  • Error: Partition(s) 5 on /dev/vda have been written, but we have been unable to
  • inform the kernel of the change, probably because it/they are in use.  As a
  • result, the old partition(s) will remain in use.  You should reboot now before
  • making further changes.
  • Ignore/Cancel? C
  • (parted) print all
  • Model: Virtio Block Device (virtblk)
  • Disk /dev/vda: 752GB
  • Sector size (logical/physical): 512B/512B
  • Partition Table: msdos
  • Disk Flags:
  • Number  Start   End    Size    Type      File system  Flags
  •  1      1049kB  528GB  528GB   primary   ext4         boot
  •  2      528GB   537GB  8588MB  extended
  • (parted) rm 2
  • Error: Partition(s) 5 on /dev/vda have been written, but we have been unable to
  • inform the kernel of the change, probably because it/they are in use.  As a
  • result, the old partition(s) will remain in use.  You should reboot now before
  • making further changes.
  • Ignore/Cancel? C
  • (parted) print all
  • Model: Virtio Block Device (virtblk)
  • Disk /dev/vda: 752GB
  • Sector size (logical/physical): 512B/512B
  • Partition Table: msdos
  • Disk Flags:
  • Number  Start   End    Size   Type     File system  Flags
  •  1      1049kB  528GB  528GB  primary  ext4         boot
The commands works on ubuntu 16.04 (NONE LVM) and machine is running a kvm:
  • sudo growpart /dev/vda 1
  • sudo resize2fs /dev/vda1  
growpart and resize2fs are e.g. available via sudo apt-get install cloud-guest-utils
=====================================
Chi tiết:
1/ Kiểm tra dung lượng ổ địa hiện tại
Sử dụng lệnh df -hT:

Dùng lệnh fdisk -l: dung lượng ổ /dev/sda: 200 GiB

2/ Tăng thêm 100GB qua Vcenter:

3/ Quét lại ổ đĩa:
– Kiểm tra các ổ địa hiện tại bằng lệnh ls /sys/class/scsi_device/

– Scan lại các ổ bằng lệnh:
echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/32\:0\:0\:0/device/rescan
4/ Kiểm tra xem hệ thống đã nhận thêm 100GB nữa chưa bằng lệnh fdisk -l:

Giờ đây /dev/sda: 300 GiB
5/ Sử dụng 2 lệnh dưới đây để mở rộng ổ /dev/sda2
growpart /dev/sda 2
resize2fs /dev/sda2  

6/ Kiểm tra lại
– Sử dụng fdisk -l:

– và df -hT:


No comments:

Post a Comment