Sunday, September 18, 2016

create live cd to reset windows 7/ windows 10 password

1- install necessary packages
$ sudo apt-get install debootstrap syslinux squashfs-tools genisoimage

2- create working directory and create the ubuntu bootstrap for  precise x64
$ mkdir -p livecd/chroot
$ cd livecd
$ sudo debootstrap --arch=amd64 precise chroot

3- preparing for chroot the bootstrap
$ sudo mount --bind /dev chroot/dev
$ sudo cp /etc/hosts chroot/etc/hosts
$ sudo cp /etc/resolv.conf chroot/etc/resolv.conf

- update chroot/etc/apt/sources.list with the following content

deb precise main universe

4- chroot the bootstrap and install packages
$ sudo chroot chroot 
$ mount none -t proc /proc
$ mount none -t sysfs /sys
$ mount none -t devpts /dev/pts
$ export HOME=/root
$ export LC_ALL=C

$ apt-get update
$ apt-get install --yes dbus
$ dbus-uuidgen > /var/lib/dbus/machine-id
$ dpkg-divert --local --rename --add /sbin/initctl

$ apt-get install chntpw
$ apt-get install --yes ubuntu-standard casper lupin-casper
$ apt-get install --yes discover laptop-detect os-prober
$ apt-get install --yes linux-generic

(when ask to install grub on device, just ignore it, because it will install grub on your real devices)

5- cleanup before exit chroot
$ rm /var/lib/dbus/machine-id
$ rm /sbin/initctl
$ dpkg-divert --rename --remove /sbin/initctl

$ apt-get clean
$ rm -rf /tmp/*

$ umount -lf /proc
$ umount -lf /sys
$ umount -lf /dev/pts
$ exit

- after exit the chroot unmount the /dev directory
 $ sudo unmount chroot/dev

6 prepare for creating live cd
$ mkdir -p image/{casper,isolinux,install}
$ sudo cp chroot/boot/vmlinuz* image/casper/vmlinuz
$ sudo cp chroot/boot/initrd.img image/casper/initrd.lz
$ cp /usr/lib/ISOLINUX/isolinux.bin image/isolinux/
$ cp /usr/lib/syslinux/modules/bios/* image/isolinux

7- create boot menu by create file image/isolinux/isolinux.cfg with the following content
LABEL live
  menu label ^Start or install Ubuntu Remix
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash --
LABEL check
  menu label ^Check CD for defects
  kernel /casper/vmlinuz
  append  boot=casper integrity-check initrd=/casper/initrd.lz quiet splash --
LABEL memtest
  menu label ^Memory test
  kernel /install/memtest
  append -
  menu label ^Boot from first hard disk
  localboot 0x80
  append -
DISPLAY isolinux.txt

8- compress filesystem and create live cd
$ sudo mksquashfs chroot image/casper/filesystem.squashfs
$ printf $(sudo du -sx --block-size=1 chroot | cut -f1) > image/casper/filesystem.size

$ cd image
$ sudo mkisofs -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -o ../resetpassword-live.iso .

after finishing, it will produce a livecd iso livecd/resetpassword-live.iso

-snapshot of using to change password on windows 7

No comments:

Post a Comment