Category Archives: pi

All ip assigned within a network

Many a time you wanted to know the assigned ip addresses in your LAN. My use cases:

I was working on nano pi neo cheapest things can be!!

You don’t want to move from your¬†ass but this is more of a reason when you already know how to do this ūüôā

Okay so on windows you have Advanced ip scanner. You can even log into your router and get to see the client list this is always the easiest way but (ohh but again).. ¬†¬†what if you have reset your router password. Most of the time you will forgot it!! It is not often that you need to login into your router so reset password means forgot. Do you want to reset the router password now just for this with router’s reset button. Or you are in office or you don’t own the router.

Anyway whatever your cause is here is a very easy command to get the list of all assigned ip using linux system:


sudo apt-get install nmap


:~$ sudo nmap 192.168.100.5/24 -sP

Starting Nmap 6.40 ( http://nmap.org ) at 2017-01-04 18:23 IST
Nmap scan report for domain.name.dlink.com (192.168.100.1)
Host is up (0.00024s latency).
MAC Address: 1C:5F:2B:4D:05:71 (Unknown)
Nmap scan report for 192.168.100.26
Host is up (0.00028s latency).
MAC Address: FA:7B:DE:ED:46:55 (Unknown)
Nmap scan report for 192.168.100.4
Host is up.
Nmap done: 256 IP addresses (3 hosts up) scanned in 3.27 seconds

If there are not much of machines in your LAN you will figure out which machine has what ip or you can ssh to each to verify. Without nmpa also you can ping all the ip and get the list but nmpa also tells you the friendly name of the machine.
 

 

Clone an SD-card

You will find many ways to clone an SD-card there are softwares like win32diskimager (A great tool for all practical purposes related to flashing cloning). You have the famous Linux dd command.

The problem arise when you are working on a bigger sd-card say 64 Gb. You have done something really cool and you want this to be in production or just share this with your friend so they will not spend 4-5 hours following your script to recreate the same image. You can just clone your card and zip it that will make the footprint small because anyway most of the 64 Gb part was empty to zip has done it’s trick but what if your friend has a 8 Gb card. You shouldn’t have started with a big card? Anyway cloning the whole card look very ugly to me (time factor is also there).

How to cleanly clone a SD card?

This is very simple I will explain it first then we will walk through a sample use case with all the commands. All the exercise is on Linux machine.

Steps:

  1. Insert the SD-card on Linux machine and get the device name e.g. /dev/sdb sdb1 sdb2
  2. Start Gparted and select your device from top. sudo apt-get install gparted If you do not have this. I like using the GUI interface but if you are the bearded Unix man you can just use the parted command.
  3. Shrink your partition with the graphical interface. You need to unmount the partitions if it is auto mounted. You can do this from the gparted UI itself by right clicking on the partition and selecting unmount. After the device is unmounted(all its partitions) you can select a partition and see the options of deleting the partition shrinking/resizing it.
  4. gparted will automatically recognize the unused space with some margin and give you option to shrink it to that much space. shrink your partition and click save to apply it. This will take some time.
  5. Now you have just sufficient amount of space for each partition unused area is mark unallocated now. We can now clone the SD-card as usual.
  6. Just check the memory used via your favorite software/command then copy using dd   sudo dd if=/dev/sdb of=~/shrinked.img bs=1M count=2470

The way to it

Now let us walk through an example with all the commands:

:~$ sudo gparted

:~$ sudo dd if=/dev/sdb of=~/myRaspberryPi.img bs=1M count=2470

:~$ sudo fdisk -l

Partition table entries are not in disk order

Disk /dev/sdb: 64.0 GB, 64021856256 bytes
64 heads, 32 sectors/track, 61056 cylinders, total 125042688 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: 0x00042380

Device Boot Start End Blocks Id System
/dev/sdb1 49152 131071 40960 83 Linux
/dev/sdb2 131072 5160959 2514944 83 Linux

You need this information to know the size you have to copy with dd command.

:~$ sudo dd if=/dev/sdb of=~/eyerisDvpCam.img bs=1M count=2470

2470+0 records in
2470+0 records out
2589982720 bytes (2.6 GB) copied, 82.9483 s, 31.2 MB/s

Do you know SD stands for Secure Digital?

There are some open points like:

  • What if your partitions are not continuous?
  • What if there is a big unallocated space in the beginning of the sd-card?

You can use skip¬†with dd to reject the initial space I tried once didn’t worked for me got image was corrupted. May be I have done it incorrectly. Then you can also copy your partitions one by one and then create an image separately by joining them.

command with skip

:~$ sudo dd if=/dev/sdb of=~/myCoolTvSkip.img bs=1M skip=23552 count=2444

2444+0 records in
2444+0 records out
2562719744 bytes (2.6 GB) copied, 107.389 s, 23.9 MB/s