Post

Clone Linux OS to New Disk with Clonezilla

Environment

KeyValue
Hostnamelocalhost.localdomain
OSCentOS Stream 8
Specification6 vCPU / 4 GB RAM
Root Disk (Clone Source)32 GB
New Root Disk Clone Target32 GB
IP AddressDHCP
UEFI/Secure BootSupported
User/Passcentos/password123
  • All is done in Hyper-V virtual machine on Windows 11, any configuration setup is the same as baremetal installation with some name changes.
  • Using Hyper-V Generation 2 Virtual Machine to enable UEFI and Secure Boot support

Verify Machine Before Clone Process

  • Hostname
1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 3370959e29cc4625b34665eeef793b6c
           Boot ID: 4bfd19c46c3f4ea8b987f3d58cfee264
    Virtualization: microsoft
  Operating System: CentOS Stream 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-500.el8.x86_64
      Architecture: x86-64
[root@localhost ~]#
  • Time and Date
1
2
3
4
5
6
7
8
9
[root@localhost ~]# timedatectl
               Local time: Tue 2024-05-07 10:37:52 WIB
           Universal time: Tue 2024-05-07 03:37:52 UTC
                 RTC time: Tue 2024-05-07 03:37:49
                Time zone: Asia/Jakarta (WIB, +0700)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no
[root@localhost ~]#
  • Storage Usage
1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs               tmpfs     1.8G     0  1.8G   0% /dev/shm
tmpfs               tmpfs     1.8G  8.4M  1.8G   1% /run
tmpfs               tmpfs     1.8G     0  1.8G   0% /sys/fs/cgroup
/dev/mapper/cs-root xfs        28G  2.4G   25G   9% /
/dev/sda2           xfs      1014M  223M  792M  22% /boot
/dev/sda1           vfat      599M  7.3M  592M   2% /boot/efi
tmpfs               tmpfs     367M     0  367M   0% /run/user/1000
[root@localhost ~]#
  • List of Drives
1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   32G  0 disk
├─sda1        8:1    0  600M  0 part /boot/efi
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0 30.4G  0 part
  ├─cs-root 253:0    0 27.2G  0 lvm  /
  └─cs-swap 253:1    0  3.2G  0 lvm  [SWAP]
sdb           8:16   0   32G  0 disk
sr0          11:0    1 1024M  0 rom
[root@localhost ~]#
  • Detail of Drives
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@localhost ~]# fdisk -l
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9EB88B7E-445B-47B3-A4ED-2A74ED925FDC

Device       Start      End  Sectors  Size Type
/dev/sda1     2048  1230847  1228800  600M EFI System
/dev/sda2  1230848  3327999  2097152    1G Linux filesystem
/dev/sda3  3328000 67106815 63778816 30.4G Linux LVM


Disk /dev/sdb: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/cs-root: 27.2 GiB, 29213327360 bytes, 57057280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/cs-swap: 3.2 GiB, 3439329280 bytes, 6717440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
[root@localhost ~]#
  • Install some software for verification that services will still available after cloning
1
2
3
4
5
6
7
8
9
10
sudo dnf install mariadb-server nginx -y
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

systemctl enable --now mariadb-server
systemctl enable --now mariadb
systemctl enable --now nginx
  • List of ports used by services

  • Nginx default page

  • Dummy files

Set Bootable to Clonezilla disk

In this guide, we are using Hyper-V virtualization platform. If you use other type of platfrom (virtualization/cloud provider/baremetal) then Your Mileage May Vary.
Refer to your guidelines about how to add ISO file and changing the boot priorities. Make sure you can boot into Clonezilla ISO file.

  • Add Clonezilla image file to DVD Drive component

  • Change the boot priority, select DVD Drive as the first boot

Cloning

  1. Boot into Clonezilla. Select Clonezilla Live (VGA 800x600 & To RAM)

  2. Choose English languages

  3. Keep the default keyboard to English

  4. Start Clonezilla GUI mode

  5. Because we only want to clone our OS from 1 disk to another, we can use device-to-device deployment mode

  6. You can either use Beginner mode or Expert mode. We will only use the default options, so you can choose Beginner mode to skip selecting all the options. We choose Expert mode to show you whats all the options available for cloning disk to disk

  7. Because we want to clone the entire disk, and also because we don’t have RAID, means that disk_to_local_disk mode is enough for us

  8. Select the source disk. Make sure to not selecting the wrong disk because then we will wipe our entire disks and losing data. The first disk for OS usually start at /dev/sda

  9. Select the target disk. Make sure to not selecting the wrong disk because then we will wipe our entire disks and losing data

  10. Select the options we want for cloning this disk. Clonezilla’s default options is enough for disk-to-disk cloning so we will leave it as is. Usually the first 5 is the default options we need to checks

  11. Skip the file system checking if we are sure that our disk and file system did not have any problem

  12. Select -k0 to make Clonezilla using the same configuration from the source disk when building the partition table on the new disk

  13. The action after everything is finished. We can select -p poweroff so that our machine will automatically turned off. Here we will use -p choose so we need to choose the actions again after cloning activity is finished

  14. Confirm the cloning process, click Enter once and y twice to confirm. This will start the cloning process. The target disk will get wipe out and cannot be reverted back

  15. Disk cloning is in progress

  16. When cloning process is finished, click Enter to go back to the finishing actions

  17. Choose poweroff to turn off the machine. Next we will detach the old disk and changing the boot priority again

Detach Old Disk and Clonezilla ISO

In this guide, we are using Hyper-V virtualization platform. If you use other type of platfrom (virtualization/cloud provider/baremetal) then Your Mileage May Vary.
Refer to your guidelines about how to detach/remove disk and changing the boot priorities. Make sure you can boot into the new disk.

  • Removing old Hard Drive (centos-stream-8-sda) and Clonezilla DVD Drive

  • Changing boot priority to EFI file and new Hard Drive

Start Machine

If everything goes well, the machine will boot to the new disk and we can start using it.

  • Hostname
1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 3370959e29cc4625b34665eeef793b6c
           Boot ID: eb4addeaacc549da8fc0d0622470c861
    Virtualization: microsoft
  Operating System: CentOS Stream 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-552.1.1.el8.x86_64
      Architecture: x86-64
[root@localhost ~]#
  • Time and Date
1
2
3
4
5
6
7
8
9
[root@localhost ~]# timedatectl
               Local time: Tue 2024-05-07 11:33:33 WIB
           Universal time: Tue 2024-05-07 04:33:33 UTC
                 RTC time: Tue 2024-05-07 04:33:30
                Time zone: Asia/Jakarta (WIB, +0700)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no
[root@localhost ~]#
  • List of Drives
1
2
3
4
5
6
7
8
9
[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   32G  0 disk
├─sda1        8:1    0  600M  0 part /boot/efi
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0 30.4G  0 part
  ├─cs-root 253:0    0 27.2G  0 lvm  /
  └─cs-swap 253:1    0  3.2G  0 lvm  [SWAP]
[root@localhost ~]#
  • Storage Usage
1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs               tmpfs     1.8G     0  1.8G   0% /dev/shm
tmpfs               tmpfs     1.8G   17M  1.8G   1% /run
tmpfs               tmpfs     1.8G     0  1.8G   0% /sys/fs/cgroup
/dev/mapper/cs-root xfs        28G  3.4G   24G  13% /
/dev/sda2           xfs      1014M  292M  723M  29% /boot
/dev/sda1           vfat      599M  7.3M  592M   2% /boot/efi
tmpfs               tmpfs     367M     0  367M   0% /run/user/1000
[root@localhost ~]#
  • Detail of Drives
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@localhost ~]# fdisk -l
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9EB88B7E-445B-47B3-A4ED-2A74ED925FDC

Device       Start      End  Sectors  Size Type
/dev/sda1     2048  1230847  1228800  600M EFI System
/dev/sda2  1230848  3327999  2097152    1G Linux filesystem
/dev/sda3  3328000 67106815 63778816 30.4G Linux LVM


Disk /dev/mapper/cs-root: 27.2 GiB, 29213327360 bytes, 57057280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/cs-swap: 3.2 GiB, 3439329280 bytes, 6717440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
[root@localhost ~]#
  • List of Ports Used by Services
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    [root@localhost ~]# netstat -pntul
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1413/nginx: master
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      862/sshd
    tcp6       0      0 :::3306                 :::*                    LISTEN      939/mysqld
    tcp6       0      0 :::80                   :::*                    LISTEN      1413/nginx: master
    tcp6       0      0 :::22                   :::*                    LISTEN      862/sshd
    [root@localhost ~]#
    
  • All the dummy files is still available

  • We can still access the Nginx default web page

References

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.