DEV Community

Doğukan Eren for Açıklab

Posted on • Edited on

3

Linux Sistemlerde Chroot kullanarak İmaj Dosyalarına Bağlanma

Ilk önce örnek imaj dosyamızı indiriyoruz.

 wget http://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img
Enter fullscreen mode Exit fullscreen mode

Sonrasında bu imajı sistemimize mount edip chroot ile bağlanmamız gerekecek.

Öncelikle mount edebilmemiz için bir dosya yolu belirlelim.

Bunun için mnt altında bir dosya oluşturuyorum.

mkdir /mnt/ubuntu
Enter fullscreen mode Exit fullscreen mode

Sonrasında aşağıdaki komutu kullanarak img dosyamızı kontrol edebiliriz.

sudo file ubuntu-22.04-server-cloudimg-amd64.img
Enter fullscreen mode Exit fullscreen mode
ubuntu-22.04-server-cloudimg-amd64.img: QEMU QCOW2 Image (v2), 2361393152 bytes
Enter fullscreen mode Exit fullscreen mode

Bu çıktıdan imajımızın qcow formatında olduğunu çıkarabilriz.

Aşağıdaki komutlarla işlemimize devam edelim.

sudo modprobe nbd
Enter fullscreen mode Exit fullscreen mode
sudo qemu-nbd --connect=/dev/nbd0 ubuntu-22.04-server-cloudimg-amd64.img
Enter fullscreen mode Exit fullscreen mode

Ve mount edelim

sudo mount /dev/nbd0p1 /mnt/ubuntu/
Enter fullscreen mode Exit fullscreen mode

Şimdi mount pointimiin içine girip aşağıdaki

cd /mnt/ubuntu
sudo mount --bind /proc proc/
sudo mount --bind /sys sys/
sudo mount --bind /dev dev/
Enter fullscreen mode Exit fullscreen mode

chroot ile giriş yapalım

sudo chroot .
Enter fullscreen mode Exit fullscreen mode

pwd komutu ile kontrol ettiğimizde artık /mnt/ubuntu dizininde chroot dediğimizde imaj makinansının kök dizininde olduğumuzu görebiliriz. Ayrıca ls komutu ile de makinanın dosyalarını görebilir. paket kurabilir veya silebiliriz :)

pwd
Enter fullscreen mode Exit fullscreen mode
/
Enter fullscreen mode Exit fullscreen mode
ls
Enter fullscreen mode Exit fullscreen mode
root@OpenStack:/# ls
bin  boot  dev  etc  home  lib  lib32  lib64  libx32  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var
Enter fullscreen mode Exit fullscreen mode

Check out the CodeNewbie Podcast!

Check out the show on Spotify or wherever you get your podcasts.

This episode is all about Learning AI

Meet Matt Eland, AI Specialist at Leading EDJE. Matt shares what sparked his passion for AI years ago, why he’s made the decision to go back to school for his master's degree and how he aims to continue spreading his expertise with the community.

Top comments (1)

Collapse
 
zeki profile image
Zeki Ahmet Bayar

İmajı kapatıp tekrardan paketlemek için

sudo umount /mnt/ubuntu/
sudo qemu-nbd -d /dev/nbd0
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay