Friday, March 24, 2023

AWS

 Aws Profiles 

https://www.youtube.com/watch?v=oYsa9TNHMVI



Monday, October 18, 2021

RECOVERY PASSWORD Raspberry Pi - Do not Panic


We have a lot of things going on every day, sometimes we forget appointments or some anniversaries. But who did not forget passwords? 

Here I will show how to recover your password of your Raspberry Pi (RPI).  

PREREQUISITES

  • Physical access to RPI.
  • A computer with Windows or Linux or MacOS.
  • Adapter to connect microSD to the computer.
  • Keyboard and screen (HDMI) to connect RPI.
STEP 1. Turning off 

1. Turn off the RPI. 

If you have access to a GUI (monitor+keyboard) you can try to turn off the RPI safely, but if you don    have access or do not have a GUI installed just UNPLUG IT :(. 

2. Extract the microSD from the RPI. 

STEP 2. Single-Process mode

1. Connect the microSD card to the computer through the adapter if you need it. 

2. in your computer navigate to the microSD card and you will find the file cmdline.txt 

3. Edit the file adding to the end that you want to start in single-process mode

init=/bin/sh

you should have something similar to this line 

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/sh

4. keep on eye that the cmdline.txt will maintain its structure of ONE LINE file. 

5. Save the file and put in the RPI.

STEP 3. Change the password

1. Connect your monitor and keyboard to the RPI and boot it. (if your keyboard is not working go to the PROBLEMS section down in this page)  

2. Mount the system file 
mount -o remount, rw /

3. Now you just have to change the password
passwd pi 

4. Once you set the password run these lines
sync
exec /sbin/init

5. The screen will turn dark but wait at least 30 seconds. 

STEP 4. REVERT cmdline file

1. Unplug the RPI, take out the microSD and connect to your computer, 

2. Edit the file cmdline.txt and delete the part that you added in step 2.3. 

3. Save the file and eject safely the microSD and put it back to the RPI. 

4. You should be able to login with your new password  (step 3.3.)

5. Done!

PROBLEMS

you might have the problem that init=/bin/sh do not work because the OS do not enable your keyboard. :( DO NOT PANIC we have two more options:

OPTION 1.

Instead you append init=/bin/sh to the cmdline.txt file try to append

systemd.unit=emergency.target

OPTION 2. 

If option 1 did not work you should append this line to the same file 

systemd.unit=rescue.target

after you have keyboard now change the password in the console with 

sudo passwd pi 



Pi Fr, R. (2018, March 14). How to recover the password of your Raspberry Pi if you lost it. 2018 Update. –. Howto Raspberry Pi. https://howtoraspberrypi.com/recover-password-raspberry-pi/

Resseting password using init=/bin/sh - Keyboard doesn’t work. (2018, June 19). Raspberry Pi Stack Exchange. https://raspberrypi.stackexchange.com/questions/85146/resseting-password-using-init-bin-sh-keyboard-doesnt-work


VNC small window - How to change resolution permanently in your Raspberry

NICE!!! you made to work VNC on your Raspberry but when you want to access from your PC Bummer!!! bad news your window is too small, in other words the resolution is really tiny for your monitor. 

EASY SOLUTION 

1. If you have access to your RPI edit the file /boot/config.txt will do the work! 

sudo nano /boot/config.txt

2. uncomment the lines framebuffer and set your desire resolution as shown bellow:

# uncomment to force a console size. By default it will be display's size minus

# overscan. framebuffer_width=1600 framebuffer_height=900

2. Reboot your RPI 

sudo reboot 

3. DONE!!!

ANOTHER SOLUTION

# Enable DRM VC4 V3D driver on top of the dispmanx display stack

#dtoverlay=vc4-fkms-v3d max_framebuffers=2


BONUS 

 You might want to know most common screen resolutions:

  • 1280 x 1024 Super-eXtended Graphics Array (SXGA)
  • 1366 x 768 High Definition (HD)
  • 1600 x 900 High Definition Plus (HD+)
  • 1920 x 1080 Full High Definition (FHD)
  • 1920 x 1200 Wide Ultra Extended Graphics Array (WUXGA)
  • 2560 x 1440 Quad High Definition (QHD)
  • 3440 x 1440 Wide Quad High Definition (WQHD)
  • 3840 x 2160 4K or Ultra High Definition (UHD)

  

Create a custom image ISO for Raspberry

Who was in this position?

I changed the default configuration of certain OS in my raspberry and I installed some applications, NOW do I need to do this every time that I want to replicate it? 

THE ANSWER: NO!!! you just need to make an image of your memory. 

You have TWO options: 

OPTION 1. Copy your entire SD card to your local disk and then restore in a different micro SD CARD with software like Win32DiskImager 
 

PROBLEM #1 

The SIZE of this image is going to be the same as the capacity of your micro SD CARD. 

PROBLEM #2 

Too difficult to upload to the Cloud in order to share with friends or co-workers.

OPTION 2. Obtain a SHRINK image of your  microSD card then share it into the cloud.

** (in my test I had a image of 32GB SD-Card and I obtained 3.7 GB image with this method) **

***(instead of using a Raspberry Pi OS you can follow the same steps using your Linux computer)***

Five Steps and you will be in the Cloud

What do you need:

    1. Raspberry pi ( I am using RBP 3B+) 

    2. Micro SD card that you want to replicate (called microSD Source)

    3. Adapter for reading micro SD card to USB 

    4. Micro SD card with Raspberry Pi OS (RPI OS)  with  free space,  at least the size of the SD-Source. 

    5. Keyboard, mouse.

NOTE: You can work everything in the Raspberry directly or you can work through your Windows or Mac with VNC.  

STEP 1: 

1. Insert the memory (microSD Source) with the OS that you want to have the image. 

2. Log in with your user and password and install Cockpit

sudo apt install cockpit

STEP 2: 

1. Shutdown properly your session and take out the micro SD card from RBP. 

STEP 3: 

1. Insert the second micro SD card  with RPI OS and log in. 

STEP 4: 

1. Insert the micro SD card - Source to the adapter (4a in the figure)

2. Connect the adapter to the Raspberry (4b in the figure) 

3. In the console of the raspberry  check if your system has mounted the microSD -Source with the command 

lsblk -p


in the capture of screen we can see that the microSD is the device /dev/sda, before making the copy we need to unmount the device: 

umount /dev/sda1 && umount /dev/sda2

4. Now we can start the copy of the image

sudo dd if=/dev/sda of=~/MyImage.img bs=32M

be patient it will take a while remember you are coping the entire  SD card (my case 32GB) and each block is 32MB. 

5. When it is done you will obtain a similar message :

6. Once the copy is finished, it is time to shrink the image. We will use PiShrink.

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

7. Run the script

sudo pishrink.sh -z ~/MyImage.img

-z parameter will zip the file with gzip.

If you do not use the parameter -z you will obtain a larger file. In my test with -z the file was 1.7 GB without 3.6 GB and not shrinking gave me a file of 31 GB 

STEP 5:

1. Upload to you desire cloud and share it.
2. END.

 
BONUS

You can install the ISO as you are used to or try this option:

Installing the custom ISO in a new microSD Card

1. Put the card in the adapter and insert to the RPI. 
2. Check if it is mounted properly. 
lsblk -p
3. Unmount the microSD
umount /dev/sda1 && umount /dev/sda2
4. copy the image to the microSD
dd if=/path/to/image.img of=/dev/sda bs=32M conv=fsync
5. Done!


References:

Avenwedde, S., Formy-Duval (Correspondent), A., & Fallon, K. (2021, July 28). Create your own custom Raspberry Pi image. Opensource.Com. https://opensource.com/article/21/7/custom-raspberry-pi-image