Recover Root Password Linux Dengan SystemRescue CD

SystemRescueCD adalah sebuah distro Linux yang menyediakan Live CD untuk keperluan troubleshooting.

Misalnya saya mendadak lupa apa password akun root salah satu server Linux. Saya bisa boot servernya dengan menggunakan SystemRescueCD sebagai boot media. Lalu dari konsolnya SystemRescueCD, saya bisa lakukan langkah-langkah berikut ini :

  1. Pertama saya perlu cari cek dulu partisi apa saja yang ada dalam harddisk server ini, saya bisa gunakan perintah fdisk seperti berikut ini :
    root@sysresccd /root % fdisk -l
    
    Disk /dev/sda: 16.7 GB, 16689012736 bytes, 32595728 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 identifier: 0xbdf13b7d
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048    29362175    14680064   83  Linux
    /dev/sda2        29362176    32595727     1616776   83  Linux
    root@sysresccd /root %

    Dari situ saya tahu ada 2 partisi /dev/sda1 & /dev/sda2. Selain itu saya lihat partisi /dev/sda1 ditandai dengan flag Boot, jadi saya tebak /dev/sda1 adalah partisi root.

  2. Saya mount partisi /dev/sda1 sementara di /mnt :
    root@sysresccd /root % mount /dev/sda1 /mnt
  3. Saya perlu masuk ke environment root tadi dengan perintah chroot :
    root@sysresccd /root % chroot /mnt
    chroot: failed to run command ‘/bin/zsh’: No such file or directory
    root@sysresccd /root %

    Ternyata gagal karena SystemRescueCD menggunakan zsh sebagai default SHELL-nya. Bisa diakali dengan mengganti variabel SHELL dengan bash :

    root@sysresccd /root % export SHELL=bash
    root@sysresccd /root % chroot /mnt      
    root@sysresccd:/#
  4. Bagaimana saya tahu kalau saya sudah berada dalam chroot partisi /dev/sda1? Sederhananya saya bisa cek file hostname :
    root@sysresccd /root % chroot /mnt      
    root@sysresccd:/# cat /etc/hostname 
    debian7
    root@sysresccd:/#

    Benar ternyata hostname-nya adalah “debian7”, berarti saya sudah masuk ke chroot environment partisi /dev/sda1. Tentu ini sangat tergantung distro Linuxnya. Debian atau Ubuntu atau turunannya menaruh nama hostname di /etc/hostname. Sedikit berbeda dengan RedHat atau turunannya seperti CentOS, informasi hostname ditaruh di /etc/sysconfig/network :

    [root@sysresccd /]# cat /etc/sysconfig/network
    NETWORKING=yes
    NETWORKING_IPV6=no
    HOSTNAME=localhost.localdomain
    [root@sysresccd /]#

    Cara lain yang lebih sederhana mungkin bisa dengan memperhatikan tampilan prompt yang berubah dari

    root@sysresccd /root %

    menjadi :

    root@sysresccd:/#
  5. Dari sini saya bisa langsung mengganti password akun root dengan perintah passwd :
    root@sysresccd:/# passwd root
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    root@sysresccd:/#
  6. Setelah itu saya bisa keluar dari chroot & langsung restart servernya dengan :
    root@sysresccd:/# exit
    exit
    root@sysresccd /root % reboot

Beberapa catatan kecil dari langkah-langkah di atas :

  1. Mungkin saja partisi hardidsk-nya lebih rumit (atau mungkin ada lebih dari 2 harddisk dalam server) seperti ini :
    root@sysresccd /root % fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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 identifier: 0x00000000
    
       Device Boot      Start         End      Blocks   Id  System
    
    Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 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 identifier: 0x00027a20
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1   *          63      208844      104391   83  Linux
    /dev/sdb2          208845     6506324     3148740   83  Linux
    /dev/sdb3         6506325     8610839     1052257+  82  Linux swap / Solaris
    root@sysresccd /root %

    Tetap patokan saya adalah partisi dengan flag Boot (yang ditandai dengan simbol bintang *). Saya coba saja mount partisi /dev/sdb1 untuk melihat isinya :

    root@sysresccd /root % mount /dev/sdb1 /mnt
    root@sysresccd /root % ls /mnt
    config-2.6.39-300.32.1.el5uek  initrd-2.6.39-300.32.1.el5uek.img  symvers-2.6.39-300.32.1.el5uek.gz  vmlinuz-2.6.39-300.32.1.el5uek  xen-4.1.gz  xen.gz
    grub                           lost+found                         System.map-2.6.39-300.32.1.el5uek  xen-4.1.3OVM.gz                 xen-4.gz    xen-syms-4.1.3OVM
    root@sysresccd /root % umount /mnt

    Ternyata /dev/sdb1 bukan partisi root tapi partisi /boot. Karena /dev/sdb3 adalah partisi swap maka saya bisa tebak kalau root partisinya ada di /dev/sdb2 :

    root@sysresccd /root % mount /dev/sdb2 /mnt
    root@sysresccd /root % ls /mnt
    bin  boot  dev  etc  halt  home  lib  lib64  lost+found  media  mnt  opt  OVS  proc  root  sbin  selinux  srv  sys  tmp  u01  usr  var
    root@sysresccd /root %

    Langkah selanjutnya seperti di atas, chroot dulu lalu ganti password-nya.

  2. Sedikit berbeda bila server Linuxnya menggunakan LVM (Logical Volume Manager) :
    root@sysresccd /root % fdisk -l
    
    Disk /dev/sda: 26.8 GB, 26843545600 bytes, 52428800 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 identifier: 0x000c64ed
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63      208844      104391   83  Linux
    /dev/sda2          208845    52420094    26105625   8e  Linux LVM
    
    Disk /dev/sdb: 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
    Disk identifier: 0x00000000
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1              63    20964824    10482381   83  Linux
    
    Disk /dev/mapper/VolGroup00-LogVol00: 20.5 GB, 20468203520 bytes, 39976960 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 /dev/mapper/VolGroup00-LogVol01: 6241 MB, 6241124352 bytes, 12189696 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
    
    root@sysresccd /root %

    Dalam contoh di atas, partisi root-nya berada di /dev/mapper/VolGroup00-LogVol00. Jadi proses mount-nya seperti ini :

    root@sysresccd /root % mount /dev/mapper/VolGroup00-LogVol00 /mnt
    root@sysresccd /root % ls /mnt
    bin  boot  dev  etc  home  lib  lib64  lost+found  media  misc  mnt  net  opt  proc  root  sbin  selinux  srv  sys  tftpboot  tmp  u01  usr  var
    root@sysresccd /root %

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.