Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

4/16/2017

How to Shrink RAW Disk Image to Actual Used Disk Space

Related Questions

  1. How to save disk space for raw disk images
  2. How to shrink raw disk image to actual space used
  3. How to compress raw disk image to actual space used

Note: This method is only for Linux Users

Step 1 (Clone or Download bash Script)

https://github.com/Drewsif/PiShrink Make your pi images smaller!
ssp@ssp-pc:~/Downloads$
=> git clone https://github.com/Drewsif/PiShrink.git
Cloning into 'PiShrink'...
remote: Counting objects: 72, done.
remote: Total 72 (delta 0), reused 0 (delta 0), pack-reused 72
Unpacking objects: 100% (72/72), done.
Checking connectivity... done.

Lets Check Syntax of Command pishrink.sh

ssp@ssp-pc:~/Downloads$
=> cd PiShrink/
ssp@ssp-pc:~/Downloads/PiShrink$
=> ls
LICENSE  pishrink.sh  README.md
ssp@ssp-pc:~/Downloads/PiShrink$
=> ./pishrink.sh 
Usage: ./pishrink.sh [-s] imagefile.img [newimagefile.img]

You need sudo permission to Use this Script

ssp@ssp-pc:~/Downloads/PiShrink$
=> ./pishrink.sh -s /media/ssp/Linux_DATA/raspberry-pi.img /media/ssp/Linux_DATA/raspberry-pi.min.img 
ERROR: You need to be running as root.

ssp@ssp-pc:~/Downloads/PiShrink$
=> sudo ./pishrink.sh -s /media/ssp/Linux_DATA/raspberry-pi.img /media/ssp/Linux_DATA/raspberry-pi.min.img 
Copying /media/ssp/Linux_DATA/raspberry-pi.img to /media/ssp/Linux_DATA/raspberry-pi.min.img...
Skipping autoexpanding process...
e2fsck 1.42.9 (4-Feb-2014)
/dev/loop0: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 152923/480496 files (0.1% non-contiguous), 1059531/1924096 blocks
resize2fs 1.42.9 (4-Feb-2014)
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/loop0 to 1066992 (4k) blocks.
Begin pass 2 (max = 98529)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 59)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 13514)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0 is now 1066992 blocks long.

Shrunk /media/ssp/Linux_DATA/raspberry-pi.min.img from 7.5G to 4.2G

Result

As you can see that Actual Size of Disk Image was about 8 GB and now it is about 4 GB, So this script is really useful When you want to save disk space and now you can easily restore raw disk image fatster (in short time). After that You can expand file system to use all available disk space.

10/27/2014

working with Linux OS behind proxy server (Linuxmint 17)

# Configuring proxy servers when you are using Linux/Windows operating system.

# In this case i am using Linux mint 17 - XFCE x64bit

# There are mostly two ways to configure proxy for Linux operating system tools.
    #1. First you can look for tool configuration file, that can be found in Linux System /etc directory,
    For example: If you are using WGET (Linux download manager) that its configuration file in
        /etc/wgetrc
        ~ And you need to edit this file to setup proxy for wget,
   
        #NOTE
                ~ This proxy will be configured for wget will be used every time you run wget.
           So, if you are using proxy for a while than you should avoid this method.

    #2. Second method for configuring proxy is using console/Terminal environment variable.

----------------------------------NOTE------------------------------------------------------------
Environment variables are very important and allows you to directly communicate with another 
command line application or look for any configuration file where that defined for your specific
Application.
A simple example is, So you have installed JAVA_JDK or you are going to install java into your SYSTEM,
How your SYSTEM is going to find that you have installed JAVA_JDK installed,
    -> You can say that path can be defined using windows registry. ok but what about linux?

Their is one another way to use it even without installing it,

    -> This is using Environment variables, these are specific for two scopes
        -> LOCAL Environment Variables
        -> GLOBAL Environment Variables    => need admin privileges
    -> export JAVA_HOME environment variable for that Directory where you have installed/extract
        java_jdk contents.
    -> And you are ready to go ..
----------------------------------------------------------------------------------------------------

         ~  for BASH shell on Linux mint17-XFCE-x64
         ~ I have used this command-
              $ export http_proxy=http://172.16.200.3:3128
          
              ~ So, what actually this is going to do?
                   ~ This actually create a new environment variable using :
                             KEY = http_proxy
                             VALUE= http://172.16.200.3:3128

            ~ If you want to see Environment variable, use env  command,
                   ~ $ env
                    # This is going to print every environment variable KEY and corresponding
                       key VALUES.

    # If you are using Linux tools using CYGWIN package
     https://www.cygwin.com/
     http://x.cygwin.com/

      ~You can set environment variable using set command on windows, 
            ~ There is Syntax
              >set http_proxy=http://172.16.200.3:3128
              >wget http://www.google.co.in 



    # Linux == export ( to define environment variables temporarily)
        ~ And to view them use == env  command
         http://www.computerhope.com/unix/uenv.htm

    # Windows == set ( to define environment variables temporarily on windows OS  )
        ~ And to view all of them use   == set command
        http://www.computerhope.com/sethlp.htm
       http://ss64.com/nt/set.html

# Some examples:
    #1. using wget command line download manager for UNIX like systems.
        ~LINUX
        $ export http_proxy=http://172.16.200.3:3128
       $ wget -o home.html http://python.org

                               OR

       $ http_proxy=http://172.16.200.3:3128 wget -o home.html http://python.org

                              OR

      ~ Use wget  configuration, edit and define proxy server and port for http, https, ftp protocol.
         # nano /ect/wgetrc

    #2. using pip python modules/packages management tool
        ~ LINUX
        $  export http_proxy=http://172.16.200.3:3128
        $ sudo pip install ipython[test, notebook, zmq, qtconsole]
        # This is how we can install IPython with notebook, qtconsole, zmq dependencies.

                                OR

        $ http_proxy=http://172.16.200.3:3128 pip install ipython[test, notebook, zmq, qtconsole]

                                 OR

        # use pre-defined option for proxy server
            $ sudo pip --proxy http://172.16.200.3:3128 install ipython

    #3. using apt-get to install Linux packages form console/terminal
    ~ Although you can use Synaptic package manager or GDebi package manager which are GUI
         for Linux package management, yet apt-get is most basic tool for managing packages on
         debian based Linux operating systems.

         ~ LINUX
         $ export http_proxy=http://172.16.200.3:3128
         $ sudo apt-get install ipython

                               OR

         # http_proxy=http://172.16.200.3:3128 apt-get install ipython

                               OR

       ~ edit configuration file for apt-get tool
          ~ which is apt.conf
          ~ PATH == /etc/apt/apt-conf
               # and now define proxy for this file, note that you can not edit this file untill
                  you have root user privileges.

                  #
         Acquire::http::Proxy "http://172.16.200.3:3128";
         #
 
    # edit your BASH configuration file that can be found in your HOME directory.
       ~/.bachrc 
 
       # Time to edit this file, nano is my favorite command line editor.
       # nano ~/.bashrc
         # go to the bottom of file and this line of code,
           of-course you are familiar with this code. 

         #
         http_proxy=http://172.16.200.3:3128
         export http_proxy
         # 

             # Save using ( CTRL+O )  and exit using ( CTRL+X )

    #4. Using easy_install behind proxy server
        $ export http_proxy=http://172.16.200.3:3128
        $ sudo -E easy_install  ipython



3/14/2014

Recover your LOST PARTITION TABLE

# If you lost partition table of your data storage device, such as your Hard Drive or a flash memory chip.
# oh, there was my very important data on my device.
# Does there is any way to recover my Partition table of Hard Drive.

I am going to share what i have done in past accidentally and i have lost my partition table and if go for data recovery options than i had been lost by 300GB data, means very important data.

# you already know that "No backup, no sympathy", i must follow this rule.

# after some research i found "testdisk" utility, just for recovering my files from my Internal hard drive.
# after exploring its features i am very impressed that this tool is able to recover your lost partition table, than i follow these simple steps and now i am happy, because i recover my 300GB data within 1 minute.

# actually i fixing my windows partition and accidentally i run this command.
/>diskpart
==>clean

! what i have done?

# there are those simple steps to recover lost partition table.

# install testdisk
sudo apt-get install testdisk

# run testdisk utility
sudo testdisk

# step_first>>create


# step_second>>>browse for given Hard drive.

# step_third>>> select partition table type.

# step_fourth>>> analyse partition structure and for lost structure

# step_next>>>testdisk will show you the current partition table on that device.
so go for quick search.

# step_next>>> testdisk will show you your lost partition table on that device.
hit 'Enter'

#step_next>>> here you have recover, your lost partition table,
select 'Write' > hit 'Enter'

# step_next>>> haha, we have done, I am happy with playing with testdisk, this utility is much more useful than any other utility you came to know, ...
# this utility is free, and you may wonder that how much content you can recover even after deleting or formatting of your data storage device.