GNU/Linux >> Belajar Linux >  >> Cent OS

Cara Mengubah Ukuran / Memperluas Volume / Sistem File Btrfs

Ini adalah tugas umum untuk mengubah ukuran/memperluas sistem file btrfs karena btrfs banyak digunakan di CentOS/RHEL 7 dan juga sebagai driver penyimpanan backend Docker. Posting ini menggambarkan 2 prosedur umum untuk memperluas volume root btrfs:

  1. Perluas untuk menggunakan ruang yang tersedia di disk asli
  2. Tambahkan disk baru ke dalam volume btrfs yang sama
Catatan :Prosedur ini berisiko karena kemungkinan kesalahan yang dibuat dalam mengubah partisi yang ada atau pemadaman listrik yang tidak terduga selama operasi keseimbangan btrfs, pastikan data/sistem Anda memiliki CADANGAN terbaru yang dapat digunakan.

1. Mengubah ukuran partisi untuk menggunakan ruang yang tersedia pada disk asli

1. Verifikasi ruang disk Anda dan ukuran partisi saat ini dengan fdisk atau parted jika disk Anda lebih besar dari 2 terabyes:

# fdisk -l /dev/xvda

Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x00087895

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1030143 514048 83 Linux
/dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris
/dev/xvda3 9418752 31457279 11019264 83 Linux
[root@host0 ~]# lsblk -f /dev/xvda
NAME FSTYPE LABEL UUID MOUNTPOINT
xvda
├─xvda1 xfs /boot 049e257e-25b1-4f46-80aa-ffaa27a21022 /boot
├─xvda2 swap SWAP-VM 0406d7df-68b6-47cb-8ea9-195ac7ef7497 [SWAP]
└─xvda3 btrfs btr_pool 1e72a30b-d59d-458f-b04f-59bf8bdec35d /

2. fdisk tidak mendukung resize partisi, jadi Anda perlu menghapus partisi lama yang ingin Anda ubah dan membuat yang baru.

# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x00087895

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1030143 514048 83 Linux
/dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris
/dev/xvda3 9418752 31457279 11019264 83 Linux

Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted

3. Sekarang mari kita buat partisi baru.

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (9418752-104857599, default 9418752):
Using default value 9418752
Last sector, +sectors or +size{K,M,G} (9418752-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 45.5 GiB is set

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.

4. Verifikasi partisi yang baru dibuat menggunakan “fdisk -l”.

# fdisk -l /dev/xvda

Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x00087895

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1030143 514048 83 Linux
/dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris
/dev/xvda3 9418752 104857599 47719424 83 Linux

5. Anda perlu memberi tahu kernel Linux tentang perubahan yang Anda buat pada /dev/xvda menggunakan perintah “partprobe”:

# partprobe
Error: Partition(s) 3 on /dev/xvda 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.

6. Karena sistem file root yang digunakan, Anda harus me-reboot OS agar kernel melihat perubahannya. Jika ini bukan sistem file root, Anda dapat melewati langkah ini.

# shutdown -r now

Memperluas Sistem File btfrs

1. Sekarang Anda dapat memperluas sistem file root btrfs.

# btrfs filesystem resize +10g /
Resize '/' of '+10g'

2. Verifikasi ukuran sistem file baru di output perintah “df -h”.

# df -h /
Filesystem    Size    Used     Avail    Use%     Mounted on
/dev/xvda3    21G     2.5G     17G      14%      /

Anda juga dapat menggunakan semua ruang pada disk jika Anda mau. Gunakan opsi “max” dengan perintah “btrfs filesystem resize”.

# btrfs filesystem resize max /
Resize '/' of 'max'
# df -h /
Filesystem    Size    Used     Avail    Use%     Mounted on
/dev/xvda3    46G     2.5G     42G      6%      /

2. Tambahkan disk baru ke volume btrfs

1. Anda dapat menambahkan disk baru ke sistem dengan menghadirkan LUN baru atau melampirkan disk virtual baru jika Anda menjalankan mesin virtual. Anda mungkin perlu menjalankan skrip di bawah ini untuk memindai LUN/disk baru.

# rescan-scsi-bus.sh -a

atau reboot sistem untuk membuat disk baru terlihat oleh OS,

2. Pastikan disk baru dapat dilihat oleh sistem operasi dengan menggunakan perintah “sblk -f” atau “fdisk -l”. Misalnya /dev/xvdb adalah disk baru untuk contoh di postingan ini.

# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
xvda
├─xvda1 xfs /boot 049e257e-25b1-4f46-80aa-ffaa27a21022 /boot
├─xvda2 swap SWAP-VM 0406d7df-68b6-47cb-8ea9-195ac7ef7497 [SWAP]
└─xvda3 btrfs btr_pool 1e72a30b-d59d-458f-b04f-59bf8bdec35d /
xvdb
# fdisk -l /dev/xvdb

Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 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

3. Tambahkan disk baru /dev/xvdb ke volume root

# btrfs device add /dev/xvdb /

4. Distribusikan data meta dari disk pertama /dev/xvda ke disk kedua /dev/xvdb.

# btrfs filesystem balance /
WARNING:

Full balance without filters requested. This operation is very
intense and takes potentially very long. It is recommended to
use the balance filters to narrow down the balanced data.
Use 'btrfs balance start --full-balance' option to skip this
warning. The operation will start in 10 seconds.
Use Ctrl-C to stop it.
10 9 8 7 6 5 4 3 2 1
Starting balance without any filters.
Done, had to relocate 9 out of 9 chunks

5. Verifikasi ukuran baru sistem file menggunakan “df -h”.

# df -h /
Filesystem    Size    Used    Avail    Use%    Mounted on
/dev/xvda3    56G     2.5G    52G      5%      /

Anda dapat melihat sistem file root ditingkatkan 10G lain yang merupakan ukuran /dev/xvdb.

Cara membuat dan memasang sistem file Btrfs (dijelaskan dengan contoh)


Cent OS
  1. Bagaimana Mengonversi Sistem File Ext ke Btrfs

  2. Perpanjang Ukuran /boot Partisi pada Sistem File XFS (CentOS/RHEL 7)

  3. CentOS / RHEL :Cara resize (memperpanjang) Physical Volume (PV) yang ada

  1. Cara membuat sistem file pada partisi Linux atau volume logis

  2. Cara Memeriksa Penggunaan Sistem File Btrfs dan Melakukan Penyeimbangan

  3. bagaimana melakukan pengujian sistem file?

  1. Bagaimana Mengubah Ukuran Partisi Dan Sistem File Pada Mereka?

  2. Cara menggunakan perintah "btrfs device" untuk menambah/menghapus perangkat ke/dari sistem file btrfs

  3. Fitur Sistem File "Btrfs"