2014-07-01 17 views
5

Làm cách nào để tăng ổ đĩa khởi động mặc định 10GB khi tôi tạo một phiên bản trên Nền tảng đám mây của Google? Tôi đã đọc qua các câu trả lời khác nhau về vấn đề này mà không có gì siêu rõ ràng. Tôi là người mới bắt đầu với nền tảng và tôi thực sự đánh giá cao nếu ai đó có thể cho tôi biết cách thực hiện điều này theo cách đơn giản.Thay đổi kích thước ổ đĩa khởi động mặc định 10GB Google Cloud Platform

+0

Điều này có thể trùng lặp với [câu hỏi này] (http://stackoverflow.com/q/24021214/3618671), vui lòng xem câu trả lời được đăng ở đó và đóng câu hỏi này nếu chúng đủ. –

Trả lời

1

Các bước thực hiện đơn giản:

  1. Tạo một đĩa mới từ một hình ảnh nguồn hiện với kích thước lớn hơn
  2. Tạo một trường hợp mới sử dụng đĩa bạn vừa tạo (select disk hiện)
  3. Sau hệ thống khởi động, sử dụng lệnh "df -h", bạn có thể thấy dung lượng lưu trữ vẫn là 9,9GB.
  4. Làm theo các bước (từ bước 4-12) trong phần "Phân hoạch lại đĩa gốc liên tục" trong https://developers.google.com/compute/docs/disks
  5. Hoàn tất !!
12

Sử dụng các bước sau để tăng kích thước khởi động bằng CentOS trên Nền tảng đám mây của Google.

 
ssh into vm instance 

[[email protected] ~]$ df -h 
Filesystem   Size Used Avail Use% Mounted on 
/dev/sda1    9.9G 898M 8.5G 10%/
tmpfs     296M  0 296M 0% /dev/shm 
[[email protected] ~]$ sudo fdisk /dev/sda 

The device presents a logical sector size that is smaller than 
the physical sector size. Aligning to a physical sector (or optimal 
I/O) size boundary is recommended, or performance may be impacted. 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to 
     switch off the mode (command 'c') and change display units to 
     sectors (command 'u'). 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
4 heads, 32 sectors/track, 819200 cylinders 
Units = cylinders of 128 * 512 = 65536 bytes 
Sector size (logical/physical): 512 bytes/4096 bytes 
I/O size (minimum/optimal): 4096 bytes/4096 bytes 
Disk identifier: 0x0004a990 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1    17  163825 10483712+ 83 Linux 

Command (m for help): c 
DOS Compatibility flag is not set 

Command (m for help): u 
Changing display/entry units to sectors 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
4 heads, 32 sectors/track, 819200 cylinders, total 104857600 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/4096 bytes 
I/O size (minimum/optimal): 4096 bytes/4096 bytes 
Disk identifier: 0x0004a990 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1   2048 20969472 10483712+ 83 Linux 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
4 heads, 32 sectors/track, 819200 cylinders, total 104857600 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/4096 bytes 
I/O size (minimum/optimal): 4096 bytes/4096 bytes 
Disk identifier: 0x0004a990 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1   2048 20969472 10483712+ 83 Linux 

Command (m for help): n 
Command action 
    e extended 
    p primary partition (1-4) 
p 
Partition number (1-4): 1 
Partition 1 is already defined. Delete it before re-adding it. 

Command (m for help): d 
Selected partition 1 

Command (m for help): n 
Command action 
    e extended 
    p primary partition (1-4) 
p 
Partition number (1-4): 1 
First sector (2048-104857599, default 2048): 
Using default value 2048 
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): 
Using default value 104857599 

Command (m for help): 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. 
[[email protected] ~]$ df -h 
Filesystem   Size Used Avail Use% Mounted on 
/dev/sda1    9.9G 898M 8.5G 10%/
tmpfs     296M  0 296M 0% /dev/shm 
[[email protected] ~]$ sudo reboot 

Broadcast message from [email protected] 
(/dev/pts/0) at 3:48 ... 

The system is going down for reboot NOW! 
[[email protected] ~]$ Connection to 23.251.144.204 closed by remote host. 
Connection to 23.251.144.204 closed. 

Robetus-Mac:~ tomassiro$ gcutil listinstances --project="project-name" 
+-------+---------------+---------+----------------+----------------+ 
| name | zone   | status | network-ip  | external-ip | 
+-------+---------------+---------+----------------+----------------+ 
| srv-1 | us-central1-a | RUNNING | 10.230.224.112 | 107.168.216.20 | 
+-------+---------------+---------+----------------+----------------+ 

ssh into vm instance 

[[email protected] ~]$ df -h 
Filesystem   Size Used Avail Use% Mounted on 
/dev/sda1    9.9G 898M 8.5G 10%/
tmpfs     296M  0 296M 0% /dev/shm 

[[email protected] ~]$ sudo resize2fs /dev/sda1 
resize2fs 1.41.12 (17-May-2010) 
Filesystem at /dev/sda1 is mounted on /; on-line resizing required 
old desc_blocks = 1, new_desc_blocks = 4 
Performing an on-line resize of /dev/sda1 to 13106944 (4k) blocks. 
The filesystem on /dev/sda1 is now 13106944 blocks long. 

[[email protected] ~]$ df -h 
Filesystem   Size Used Avail Use% Mounted on 
/dev/sda1    50G 908M 46G 2%/
tmpfs     296M  0 296M 0% /dev/shm 
[[email protected] ~]$ exit 
logout 
Connection to 23.251.144.204 closed. 
+1

Cảm ơn bạn rất nhiều vì điều này. Điều này làm việc hoàn hảo. – MikeGA

+1

Họ nên đặt điều này trên trang wiki của họ nếu bạn hỏi tôi :) – nyxz

+0

Bạn là một HERO thực sự! –

0

Một phương pháp an toàn hơn chỉnh sửa phân vùng trực tiếp và mà không yêu cầu duy trì hình ảnh của riêng bạn, là dracut của mô-đun growroot & cloud-init.

Tôi đã sử dụng tính năng này với CentOS 6 & 7 trên Google Compute, AWS & Azure.

## you'll need to be root or use sudo 
yum -y install epel-release 
yum -y install cloud-init cloud-initramfs-tools dracut-modules-growroot cloud-utils-growpart 
rpm -qa kernel | sed -e 's/^kernel-//' | xargs -I {} dracut -f /boot/initramfs-{}.img {} 
# reboot for the resize to take affect 

Phân vùng sẽ được tự động thay đổi kích cỡ trong lần khởi động tiếp theo.

Ghi chú:

  • này được xây dựng vào Ubuntu, đó là lý do bạn không thấy vấn đề đó.
  • Sự cố kích thước phân vùng được nhìn thấy với RedHat & CentOS với hầu hết các hình ảnh được tạo sẵn, không chỉ Google Cloud. Phương pháp này sẽ hoạt động ở mọi nơi.
Các vấn đề liên quan