1

Actually this is the first time for me with Clonezilla, and I`m not system administrator. I have on my machine (Win7 & Fedora22 workstation).

Fedora each time run shows to me partition size messages,so I need to clone it to resize my HD and reinstall it again with all my packages. To do that I'm using Clonezilla, but in fact when booting with Clonezilla, Clonezilla sees only the windows partition(s) and my partition data and doesn't see Fedora's EXT4 partitions.

Note: Also If there's any another easy way I can achieve my requirements instead of Clonezilla, that would be great.

2

You can resize the partitions with resize2fs for ext-x filesystems and ntfsresize for ntfs.

dd is a good option to move to the left partitions with 10% of empty space.

For example, to shrink /dev/sda1, move to the left and expand /dev/sda2:

  • lsblk: to identify partitions and check if they are unmounted.
  • fdisk /dev/sda or gdisk /dev/sda depending on your partition table type and then the letters p and q: to identify the sector size, alignment, start and end blocks.
  • ntfsresize -s (new size) /dev/sda1: to shrink /dev/sda1 filesystem.
  • dd if=/dev/sda2 of=/dev/sda bs=(sector size) seek=(new start): to move /dev/sda2 filesystem to the left.
  • Shrink /dev/sda1, move to the left and expand /dev/sda2 partitions with fdisk or gdisk.
  • Expand /dev/sda2 filesystem with resize2fs.

The formula to calculate the new start of /dev/sda2 is: ((/dev/sda1 start sector) * sector size + new size of /dev/sda1 in bytes → aligned to partition table alignment) / (sector size)

Real life example (moving and resizing /dev/sdc1 and /dev/sdc2):

#identifying partitions and checking if they are unmounted
> lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdc      8:32   1   1.9G  0 disk 
|-sdc1   8:33   1     1G  0 part 
`-sdc2   8:34   1 910.5M  0 part

#identifying partition type, sector size, alignment, start and end blocks
> gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdc: 3963904 sectors, 1.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): D276E14A-5EB2-42FB-89DF-A742B6199BC3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3963870
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3963870   910.5 MiB   8300  Linux filesystem

Command (? for help): q

#shrinking /dev/sdc1 filesystem to 100M
> ntfsresize -s 100M /dev/sdc1
ntfsresize v2012.1.15AR.5 (libntfs-3g)
Failed to set locale, using default 'C'.
Device name        : /dev/sdc1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 1073738240 bytes (1074 MB)
Current device size: 1073741824 bytes (1074 MB)
New volume size    : 99996160 bytes (100 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 6 MB (0.5%)
Collecting resizing constraints ...
Needed relocations : 1412 (6 MB)
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sdc1'.
You can go on to shrink the device for example with Linux fdisk.
IMPORTANT: When recreating the partition, make sure that you
  1)  create it at the same disk sector (use sector as the unit!)
  2)  create it with the same partition type (usually 7, HPFS/NTFS)
  3)  do not make it smaller than the new NTFS filesystem size
  4)  set the bootable flag for the partition if it existed before
Otherwise you won't be able to access NTFS or can't boot from the disk!
If you make a mistake and don't have a partition table backup then you
can recover the partition table by TestDisk or Parted's rescue mode.

#calculating the new start of /dev/sdc2 in bytes (/dev/sdc1 start block)*(sector size)+(new size of /dev/sdc1 in bytes)
> echo $((2048*512+100*1024*1024))
105906176

#checking alignment (new start in sectors)%(alignment*(sector size)) 0=aligned, >0=not aligned
> echo $((206848%(2048*512)))
0

#calculating the new start of /dev/sdc2 in sectors (new start in bytes)/(sector size)
> echo $((105906176/512))
206848

#moving /dev/sdc2 filesystem to the left bs=(sector size), seek=(new start in sectors)
> dd if=/dev/sdc2 of=/dev/sdc bs=512 seek=206848
1864671+0 records in
1864671+0 records out
954711552 bytes (955 MB) copied, 80.6772 s, 11.8 MB/s

#resizing and moving partitions preserving GUIDs (new start sector of /dev/sdc2 must match)
> gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): i
Partition number (1-2): 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 359B474B-0EE0-46B5-A105-A57C1D60E863
First sector: 2048 (at 1024.0 KiB)
Last sector: 2099199 (at 1.0 GiB)
Partition size: 2097152 sectors (1024.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

Command (? for help): i
Partition number (1-2): 2
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 93FD4BBB-F574-40D2-AC20-4FC162FDDEA3
First sector: 2099200 (at 1.0 GiB)
Last sector: 3963870 (at 1.9 GiB)
Partition size: 1864671 sectors (910.5 MiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

Command (? for help): d
Partition number (1-2): 1

Command (? for help): d
Using 2

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-3963870, default = 2048) or {+-}size{KMGTP}: 2048
Last sector (2048-3963870, default = 3963870) or {+-}size{KMGTP}: +100M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-3963870, default = 206848) or {+-}size{KMGTP}: 206848
Last sector (206848-3963870, default = 3963870) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): x

Expert command (? for help): c
Partition number (1-2): 1
Enter the partition's new unique GUID ('R' to randomize): 359B474B-0EE0-46B5-A105-A57C1D60E863
New GUID is 359B474B-0EE0-46B5-A105-A57C1D60E863

Expert command (? for help): c
Partition number (1-2): 2
Enter the partition's new unique GUID ('R' to randomize): 93FD4BBB-F574-40D2-AC20-4FC162FDDEA3
New GUID is 93FD4BBB-F574-40D2-AC20-4FC162FDDEA3

Expert command (? for help): p
Disk /dev/sdc: 3963904 sectors, 1.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): D276E14A-5EB2-42FB-89DF-A742B6199BC3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3963870
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          206847   100.0 MiB   8300  Linux filesystem
   2          206848         3963870   1.8 GiB     8300  Linux filesystem

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

#expanding /dev/sdc2 filesystem
> resize2fs /dev/sdc2
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sdc2 to 469627 (4k) blocks.
The filesystem on /dev/sdc2 is now 469627 blocks long.

DOS partition table example:

#resizing and moving partitions preserving IDs and active flags (new start sector of /dev/sdc2 must match)
> fdisk /dev/sdc

Command (m for help): p

Disk /dev/sdb: 2029 MB, 2029518848 bytes
63 heads, 62 sectors/track, 1014 cylinders, total 3963904 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: 0x81dc6c28

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576    7  HPFS/NTFS/exFAT
/dev/sdb2         2099200     3963903      932352   83  Linux

Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Selected partition 2

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3963903, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-3963903, default 3963903): +100M

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (206848-3963903, default 206848): 206848
Last sector, +sectors or +size{K,M,G} (206848-3963903, default 3963903): 
Using default value 3963903

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 07
Changed system type of partition 1 to 7 (HPFS/NTFS/exFAT)

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdb: 2029 MB, 2029518848 bytes
63 heads, 62 sectors/track, 1014 cylinders, total 3963904 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: 0x81dc6c28

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sdb2          206848     3963903     1878528   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Caution

Make sure you run the dd and ntfsresize commands without interruptions.

To preserve the IDs and GUIDs may help you to keep the BCD store of the Windows Bootloader healthy. In the worst case, it is relatively easy to repair it using a WindowsRE or WindowsPE environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.