Feeds:
Posts
Comments

Archive for the ‘Uncategorized’ Category

It is a common practice in programming to use a variable as template for another and then later changing the value of the new variable, something like

b=a

b = 3

at this point, variable a still has its old value, it was not replaced by 3. So far so good. This works in python like other programming languages, but what about compound objects (compound objects contain other objects = lists, dictionary, tuple)? Compound object will NOT work like this.

Lets have a closer look into problem. We can check the memory address of a given variable like this:

print(id(a), id(b))

the id() function returns memory address of its variable so one can instantly check if the two are pointing to the same address or not.

In case of compound variables, the situation is different as we start from a shallow copy:

x1 = [“a”, “b”]
>>> x2 = x1
>>> print(x1)
[‘a’, ‘b’]
>>> print(x2)
[‘a’, ‘b’]
>>> print(id(x1),id(x2))
43746416 43746416

> x2 = [“c”, “d”]
>>> print(x1)
[‘a’, ‘b’]
>>> print(x2)
[‘c’, ‘d’]
>>> print(id(x1),id(x2))
43746416 43875200

x1 and x2 are originally pointing to the same memory address but as soon as one variable is modifies, it allocates a new memory address: this is a shallow copy. It is so because our list in this example is not nested. In this case if we change only one element of x2, x1 will be modified as well:

>>> x1 = [“a”, “b”]
>>> x2 = x1
>>> x2[1] = “h”
>>> print(x1)
[‘a’, ‘h’]
>>> print(x2)
[‘a’, ‘h’]

x1 and x2 are originally pointing to the same memory address but as soon as one variable is modifies, it allocates a new memory address: this is a shallow copy. It is so because our list in this example is not nested. Now if we change only one element of x2, x1 will be modified as well:

>> x1 = [“a”, “b”]
>>> x2 = x1
>>> x2[1] = “h”
>>> print(x1)
[‘a’, ‘h’]
>>> print(x2)
[‘a’, ‘h’]

be careful !

we had actually two names for one variable, it was just a shallow copy, we did not assign a new object to x2. To avoid this problem, use deep copy:

from copy import deepcopy

x2 = deepcopy(x1)

 

hopefully it helps to prevent confusing errors in your python codes.

Read Full Post »

Clonezilla is a partition and disk cloning program. If you want to do one of the following, it can be very helpful:

  1. a full backup of your system including program files, master boot partition etc.
  2. backup of one partition of your disk
  3. clone your hard disk to a solid state drive (SSD) to improve the performance.
  4. replace hard disk or SSD of your laptop with a larger one.

My case was number four: I bought a used laptop which had a 256 GB SSD. I wanted to replace it with a 500 GB SSD.

I connected the new SSD to a USB3 gate via cable as seen below and booted the laptop with Clonezilla ISO image.

SATA 6GB/s connector with both USB 2 and USB 3 connections.

SATA 6GB/s connector with both USB 2 and USB 3 connections.

20150819_145657

The process was rather fast since both read and write was on SSD and the connection was via a USB3 gate.

Clonezilla copies partitions one by one. Here you see that it copies the main partition of the Windows 7 operating system.

Clonezilla copies partitions one by one. Here you see that it copies the main partition of the Windows 7 operating system.

So after copying was finished, I replaced the old SSD of the laptop with the new one and booted the system. It was identical to the previous system, nothing was changed at all !

so far so good. so it was time to format the extra space of the new SSD. But the partition on the new and large SSD was copied from the small SSD !!!! The system could not recognise that there are 250 GB more space on the disk !

After some googling, I realized that I can fix the partition using Fixpart.

So I booted the system via Debian 8 live CD and then downloaded the fixpart and installed that via dpkg command. Then I followed the instructions step by step and finally got an updated partition table. After that I installed gparted in the live environment of the Debian Jessie and it could recognise the unallocated memory as you can see in the following image:

Gparted could see the unallocated memory only after I fixed the partition table via Fixpart.

Gparted could see the unallocated memory only after I fixed the partition table via Fixpart.

The rest was easy, just a normal Linux installation which I explain in the next post !

Read Full Post »