Lagi asyik belajar ngoprek ‘docker’ di vm…loh koq waktu ‘yum/apt-get update’ nongol pesan ‘insufficient disk space’..dan cek ke ‘df -h’, ternyata hdd root ‘/’ nya udah 99%….waduh!

Daripada harus install ulang VM, lebih baik belajar resize hdd nya aja ya?..yuk ah kita mulai :

1. anggaplah posisi awal hdd pada /dev/sda sebagai berikut :

/dev/sda1 8.0GB dan kapasitas terpakai 44%, ini partisi yang akan kita resize menjadi 33.4GB dari total hdd Disk /dev/sda: 34.4GB dan untuk swap 1.0GB

2. shutdown VM dan lakukan ‘resize disk’ dibagian ‘hardware’ nya VM :

nyalakan ulang VM dan masuk ke console nya.

3. langkah dibawah ini untuk menghapus partisi swap, karena menghalangi sector /dev/sda1 ketika di resize :

root@docker-ce:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 8053MB 8052MB primary ext4 boot
2 8054MB 8589MB 535MB extended
5 8054MB 8589MB 535MB logical linux-swap(v1)

(parted) rm 5
Warning: Partition /dev/sda5 is being used. Are you sure you want to continue?
Yes/No? Yes
Error: Partition(s) 5 on /dev/sda 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? I
(parted) rm 2
Error: Partition(s) 5 on /dev/sda 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? I

4. lanjutkan dengan resize partisi /dev/sda1 :

(parted) resizepart /dev/sda1
Error: Expecting a partition number.
(parted) resizepart 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [8053MB]? 33.4GB

partisi /dev/sda1 kita ubah menjadi 33.4GB dan menyisakan 1.0GB untuk swap.

5. langkah dibawah ini untuk melakukan create ulang swap partisi yang tadinya dihapus :

(parted) mkpart primary linux-swap 33.4GB 34.4GB

6. karena ubuntu menggunakan UUID dan kode nya tidak akan sama lagi akibat resize dan swap yang dihapus pada langkah no.3, maka sesuaikan aja isi /etc/fstab :
nano /etc/fstab

/dev/sda1 / ext4 errors=remount-ro 0 1
/dev/sda2 none swap sw 0 0

reboot vm nya agar dibaca konfigurasi fstab yang baru…

7. langkah terakhir adalah mengenalkan hdd size /dev/sda1 yang baru ke sistem :

root@docker-ce:~# resize2fs /dev/sda1

cek hasil resize pada /dev/sda1 apakah sudah bertambah kapasitas nya?

root@docker-ce:~# df -h
Filesystem Size Used Avail Use% Mounted on

/dev/sda1 31G 3.0G 27G 11% /

untuk meyakinkan hasil resize hdd bisa berjalan dengan baik…reboot vm nya…

selamat mencoba!.. D.W.Y.O.R bro!

referensi sumber :

8 Linux ‘Parted’ Commands to Create, Resize and Rescue Disk Partitions


https://linuxadmin.io/using-parted-create-new-swap-disk/
https://askubuntu.com/questions/24027/how-can-i-resize-an-ext-root-partition-at-runtime