Clone Disk to a Smaller Disk using Clonezilla

On and off I need to clone a larger disk to a smaller disk. There are some software to do that but usually it is paid. As I don’t like to spend time to evaluate the quality of those software, I still kept using Clonezilla as my tool to do disk clone.

So back to the topic, how to clone a larger disk to a smaller disk? There are 2 choices. I am not going to the details step, but a high level steps only.

Choice 1: Clone all partitions in the source disk

If the destination disk is big enough to hold all data in the source disk, but smaller than the source disk, probably you want to choose this. The screenshot below is taken using clonezilla-live-20170905-zesty-i386.

  1. Shrink and move the partitions of the source disk, so that the size of sum of all partitions is less than the size of the destination disk. You can do that using Disk Management in Windows, or GParted in Ubuntu live CD. If you need to move partitions, then you will need to use GParted to do that.
  2. Optionally create a disk image from the source disk.
  3. Boot to Clonezilla, choose restoredisk if the source is an image, or choose disk-to-local-disk is the source is a disk.
  4. Follow the instruction on screen. When come to mode selection, choose Expert mode.
  5. Make sure the -icds is selected in the advanced extra parameters screen.
    Clonezilla Skip Destination Disk Size Check
  6. Make sure to use the partition table from the source disk or source image. Although this post suggest to Create partition table proportionally, but during my testing with 3 partitions in a source disk, it generate errors.
    Use Partition Table from Source Image
  7. Follow the rest of the instruction on screen to complete the clone.

Choice 2: Clone selected partitions in the source disk

You may want to use this method when you don’t want all partitions to be cloned to the destination disk. For example, you may want to clone the recovery partition only, and have a blank OS partition for factory restore, or you may want to clone only OS partition but drop the recovery partition because the recovery partition is too big.

  1. Shrink all source partitions which want to clone to the destination disk, so that each destination partition is equal or larger than the source partition. Use Disk Management in Windows, or GParted in Ubuntu live CD to do that.
  2. In the destination disk, create all partitions which you want to clone from the source disk. Each destination partition must be equal or larger than the source partition. Use Disk Management in Windows, or GParted in Ubuntu live CD to do that.
  3. Create any additional partitions which you will need. For example, you want to clone the recovery partition only, but you want to perform a factory restore next, then you may want to create an blank OS partition.
  4. Set the destination partition type same as the source partition type. For well known partition type such as NTFS or FAT32, you can do that by perform file system format. For other partition type such as Dell Utility, you will need to use fdisk command in Linux to set it.
  5. Port all partition flags from each source partition to destination partition. For example, setting the boot flag to OS partition and setting diag flag to recovery partition.
  6. Using Clonezilla, clone the source partition to the destination partition one by one.

Building Linux RPM Package from Source Code

Sometimes for some reasons you might not be able to find RPM package that you needed on the Internet. In that case you have to build the binary by your own. Certainly an easy way is just build the binary and install it, but a better way is to build a RPM package so that it is distributable and can be under Linux package management. So below is the steps for building RPM package from source code, referencing from with some changes.

# Step: 1
# Install rpmbuild

yum install rpm-build

# Step: 2
# Create rpmbuild folders in your home directory

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Step: 3
# Download the source file

wget -P ~/rpmbuild/SOURCES ""
tar -xzvf ~/rpmbuild/SOURCES/git- -C /tmp

# Step: 4
# Prepare the .spec file, and made any necessary changes
# If the source file did not include .spec file, you have to prepare one by your own
ls -l /tmp/git-*.spec
cp -p /tmp/git- ~/rpmbuild/SPECS
vim ~/rpmbuild/SPECS/git.spec

# Step: 5
# Build rpm
# If you get any errors during build, it is usually because of dependencies. Simply
# install the dependencies with `yum install [dependency]` and run rpmbuild again.

rpmbuild -ba --define "_topdir %(echo $HOME)/rpmbuild" ~/rpmbuild/SPECS/git.spec

You can also find the above code at

Open Video File using omxplayer on Raspberry Pi without Terminal

I was trying to make Raspberry Pi running Raspbian OS to turn it as a media player with can play video without using a keyboard so that it is portable for a trip.

The only software that allow video playback on Raspbian is omxplayer. It is a command line tool and therefore need a keyboard to start playing video. Searched on the Internet and found that it is possible create an application, allowing you to play the video via right clicking the video file and choosing the application to open. However most of scripts included in the Internet are not working on my Raspbian. After a long research I finally figured out a working one.

Later on, I actually found that there other OS such as Raspbmc, OpenELEC which is actually designed turn Raspberry Pi to be a media center and I have another Raspberry Pi for that now. Anyway below are the steps to create applications for video playback on the LXDE desktop environment on Raspbian OS:

  1. Create a file with the following content at /usr/share/applications/omxplayer-hdmi.desktop. This will allow you to hear the sound output to HDMI.
    [Desktop Entry]
    Name=OMXPlayer (HDMI)
    Exec=lxterminal --command "sudo omxplayer -r -o hdmi %f"
  2. Create a file with the following content at /usr/share/applications/omxplayer-local.desktop. This will allow you to hear the sound output to the 3.5mm audio jack.
    [Desktop Entry]
    Name=OMXPlayer (3.5mm)
    Exec=lxterminal --command "sudo omxplayer -r -o local %f"

Workaround Inability in NAT Loopback on DD-WRT r15760 or above

Recently I found that my router running DD-WRT is not able to handle NAT loopback (Accessing router’s public IP from internal network). After searching through the Internet, I found this post mentioned that it is a problem in DD-WRT since revision r15760. It is stated that the problem will not be fixed. As a user, we can only apply workaround to the issue. Here are the steps:

  1. Make sure your DD-WRT version is r15760 or newer
  2. Navigate to your router administrator page
  3. Go to the Administrator section, Commands section
  4. In the Commands text box, input the following command:
    insmod ipt_mark
    insmod xt_mark
    iptables -t mangle -A PREROUTING -i ! `get_wanface` -d `nvram get wan_ipaddr` -j MARK --set-mark 0xd001
    iptables -t nat -A POSTROUTING -m mark --mark 0xd001 -j MASQUERADE
  5. Press the Save Firewall button. You should see the following screen:
    DDWRT NAT Loopback
  6. Reboot your router, the NAT loopback should be function now

Configure RedHat Linux as Router

In my case, because a normal router doesn’t come with support of 802.1x security and I only have 1 IP address, I got to set up a Red Hat Linux server as a router with perform NAT and packet forwarding function.


  1. Suppose your server is using static IP, your network interface is eth0, and there is another PC with IP address connected to the server directly
  2. Enable IPv4 packet forwarding on Linux
    echo 1 > /proc/sys/net/ipv4/ip_forward
  3. Enable SNAT
    # Example
    iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source
  4. (Optional) Enable DNAT (port fowarding) for services such as web server
    # Example
    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to


If you want to save the rules in iptables or restore them after edit, you can use these commands!

Edit 2013-05-08: The previous command were incorrect and has been updated.
Edit 2014-11-20: Added a command for persistent change on RedHat 5

# Save iptables rules to a file
iptables-save > /tmp/iptables.txt

# Restore iptables rules from a file
iptables-restore < /tmp/iptables.txt

# (For RedHat 5) Save the iptables rules so that changes is persistent (across reboot)
service iptables save


Edit 2014-11-20: I have more IP addresses now after moving to new office. So today I rollback the configuration.

  1. Edit the file at /etc/sysctl.conf and locate the following line:
    net.ipv4.ip_forward = 1

    Edit it to read as follows:

    net.ipv4.ip_forward = 0
  2. As the root user, run the following command to enable the change to the sysctl.conf file:
    sysctl -p /etc/sysctl.conf
  3. You can then verify the result by the following command, which should give you zero as output:
    cat /proc/sys/net/ipv4/ip_forward

Adding Red Hat Enterprise Linux 6.2 Installation Disc as YUM Package Repository

Notice: This guide is for Red Hat Enterprise Linux 6.2 only. It may not work on other versions of Red Hat.

There are times that after you have installed the OS and found that you have forgotten to install some of the packages during the initial set up. But for some reasons your only source of packages is only the installation disc you have. Here is the way to make the packages on the disc available as yum package repository.

Just create a new file under the directory /etc/yum.repos.d with any file name ended with extension .repo. For example:


and have the file configured to point to the installation disc. For example:

name=Red Hat Enterprise Linux Installation Disc
baseurl="file:///media/RHEL_6.2 x86_64 Disc 1"

Be sure to change the /media/RHEL_6.2 x86_64 Disc 1 with the path pointing to your installation disc in case it is different from the one here!

I was preparing to set up another new servers running RHEL6 with channel bonding and got a chance to retouch what I have wrote.

Hidden Base

Notice: The article is for Red Hat Enterprise Linux (RHEL) 5.7 and 6.2. It may also suitable for other newer version of Red Hat.

This article is inspired by this article.


  • You have a fresh installed server running RHEL
  • The server has two Ethernet interface eth0 and eth1
  • The server has no bond device set up before
  • You want to configure eth0 and eth1 to be load balancing or active-standby
  • You will use static IP for the network connection

Step 1: Add a bond device configuration file

2012-06-11 Edit 1: Till now I am still wondering if MACADDR or HWADDR should be specified in the configuration file because in sample configuration file in the Red Hat official document here it does not contain such fields. At this stage I would recommend not specifying both MACADDR and HWADDR unless you run into physical address conflict problem.

2012-06-11 Edit…

View original post 669 more words