Kamis, 12 Juni 2008

Cloning Manual Efektif

Tutorial ini ditujukan bagi pengguna Linux overall, tidak disarankan digunakan untuk yang masih beginner, guna menghindari kesalahan. Karena sedikit kesalahan bisa berakibat fatal.
Diasumsikan bahwa kita memiliki 2 harddisk yang dipasang dalam satu komputer.
  • Harddisk pertama adalah /dev/hda
  • Harddisk kedua adalah /dev/hdc
= Harddisk yang akan diclone
= Harddisk yang masih kosong

Buka terlebih dahulu terminal lalu ketikan:



vijaya@vijaya-desktop6:~$ sudo bash
Password:
root@vijaya-desktop6:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 6.5G 3.5G 2.7G 57% /
varrun 125M 128K 125M 1% /var/run
varlock 125M 4.0K 125M 1% /var/lock
udev 125M 120K 125M 1% /dev
devshm 125M 0 125M 0% /dev/shm
lrm 125M 19M 107M 15% /lib/modules/2.6.15-28-386/volatile
/dev/hda3 12G 3.8G 7.2G 35% /home
/dev/hda5 19G 1.2G 18G 6% /media/hda5

//Periksa terlebih dahulu harddisk source dan dest-nya. Dengan perintah:

root@vijaya-desktop6:~# fdisk -l /dev/hd
hda hda1 hda2 hda3 hda4 hda5 hdc

//Bila tidak ada jenis /dev/hdx maka kemungkinan harddisknya bertipe /dev/sdx,
//Tergantung dari jenis harddisk kita, apakah itu SATA (sdx) atau ATA (hdx)
//Misal harddisk yang ingin diformat adalah /dev/hdc

root@vijaya-desktop6:~# fdisk /dev/hdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 4865.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

//Untuk menampilkan help ketik 'm' lalu enter:

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

//Ketik 'n' untuk membuat partisi baru

Command (m for help): n
Command action
e extended
p primary partition (1-4)

//Pilih jenis partisi Primary (maksimal 4 per-harddisk) atau Extended, dimana
//'p' untuk Primary dan 'e' untuk Extended

p

//Pilih nomor partisi (urut):

Partition number (1-4): 1

//Biarkan dalam keadaan default

First cylinder (1-4865, default 1):

//Isikan besar partisi
//Ini diasumsikan sebagai partisi '/'

Last cylinder or +size or +sizeM or +sizeK (1-4865, default 4865): +5Gb

//Kemudian buat partisi lagi

Command (m for help): n
Command action
e extended
p primary partition (1-4)

//Jenisnya Primary

p

//Partisi dengan nomor urut ke-2

Partition number (1-4): 2
First cylinder (610-4865, default 610):
Using default value 610

//Isikan besarnya, ini diasumsikan sebagai partisi '/swap'

Last cylinder or +size or +sizeM or +sizeK (610-4865, default 4865): +1Gb

//Lihat partisi yang telah dibuat

Command (m for help): p

Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 609 4891761 83 Linux
/dev/hdc2 610 732 987997+ 83 Linux

//Buat partisi satu lagi

Command (m for help): n

Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 3
First cylinder (733-4865, default 733):
Using default value 733
Last cylinder or +size or +sizeM or +sizeK (733-4865, default 4865):
Using default value 4865

//Lihat partisi:

Command (m for help): p

Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 609 4891761 83 Linux
/dev/hdc2 610 732 987997+ 83 Linux
/dev/hdc3 733 4865 33198322+ 83 Linux

//Jalankan seluruh perintah yang telah dilakukan

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

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

//Cek ulang dengan fdisk:
//Ternyata partisi kedua harus diubah id sistemnya

root@vijaya-desktop6:~# fdisk /dev/hdc

The number of cylinders for this disk is set to 4865.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 609 4891761 83 Linux
/dev/hdc2 610 732 987997+ 83 Linux //Harus diganti nih...
/dev/hdc3 733 4865 33198322+ 83 Linux

//Gunakan perintah 't' untuk mengganti system id partition:

Command (m for help): t

//Pilih partisi nomor 2 yang akan digunakan sebagai partisi 'swap':

Partition number (1-4): 2

//Beri angka 82:
//Mengenai angka-angka ini bisa dipelajari dimanual fdisk

Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)

//Jalankan seluruh perintah:

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

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

//Buat filesystem bertipe Ext3 pada /dev/hdc1 yang merupakan partisi '/':

root@vijaya-desktop6:~# mkfs.ext3 /dev/hdc1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
611648 inodes, 1222940 blocks
61147 blocks (5.00%) reserved for the super user
First data block=0
38 block groups
32768 blocks per group, 32768 fragments per group
16096 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

//Buat filesystem bertipe Ext3 pada /dev/hdc3 yang merupakan partisi '/home':

root@vijaya-desktop6:~# mkfs.ext3 /dev/hdc3
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
4153408 inodes, 8299580 blocks
414979 blocks (5.00%) reserved for the super user
First data block=0
254 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@vijaya-desktop6:~# mkswap /dev/hdc2
Setting up swapspace version 1, size = 1011703 kB
no label, UUID=2560a048-ea51-4d72-b216-585b21f768c6

//Kemudian buat direktori /mnt/image, /mnt/hdbaru

root@vijaya-desktop6:~# mkdir /mnt/image
root@vijaya-desktop6:~# mkdir /mnt/hdbaru

//Mount partisi /dev/hdc1 pada direktori /mnt/hdbaru, dimana partisi ini merupakan '/'

root@vijaya-desktop6:~# mount /dev/hdc1 /mnt/hdbaru

//Masuk ke direktori /mnt/hdbaru:

root@vijaya-desktop6:~# cd /mnt/hdbaru/

//Tampilkan isinya:

root@vijaya-desktop6:/mnt/hdbaru# ls
lost+found
root@vijaya-desktop6:/mnt/hdbaru# cd ..
root@vijaya-desktop6:/mnt# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 6.5G 3.5G 2.7G 57% /
varrun 125M 128K 125M 1% /var/run
varlock 125M 4.0K 125M 1% /var/lock
udev 125M 144K 125M 1% /dev
devshm 125M 0 125M 0% /dev/shm
lrm 125M 19M 107M 15% /lib/modules/2.6.15-28-386/volatile
/dev/hda3 12G 3.8G 7.2G 35% /home
/dev/hda5 19G 1.2G 18G 6% /media/hda5
/dev/sda1 1.9G 1.8G 90M 96% /media/JUN
/dev/hdc1 4.6G 129M 4.3G 3% /mnt/hdbaru

//Mount /dev/hda1 pada direktori /mnt/image, dimana hda1 adalah partisi '/' dari harddisk source

root@vijaya-desktop6:/mnt# mount /dev/hda1 /mnt/image

//Masuk kedirektorinya:

root@vijaya-desktop6:/mnt# cd image/

//Tampilkan isinya:

root@vijaya-desktop6:/mnt/image# ls
bin etc initrd.img.old lost+found proc sys vmlinuz
boot home lib media root tmp vmlinuz.old
cdrom initrd lib64 mnt sbin usr
dev initrd.img linux-swap opt srv var
root@vijaya-desktop6:/mnt/image# cd ..
root@vijaya-desktop6:/mnt# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 6.5G 3.5G 2.7G 57% /
varrun 125M 128K 125M 1% /var/run
varlock 125M 4.0K 125M 1% /var/lock
udev 125M 144K 125M 1% /dev
devshm 125M 0 125M 0% /dev/shm
lrm 125M 19M 107M 15% /lib/modules/2.6.15-28-386/volatile
/dev/hda3 12G 3.8G 7.2G 35% /home
/dev/hda5 19G 1.2G 18G 6% /media/hda5
/dev/sda1 1.9G 1.8G 90M 96% /media/JUN
/dev/hdc1 4.6G 3.5G 927M 80% /mnt/hdbaru
/dev/hda1 6.5G 3.5G 2.7G 57% /mnt/image
/dev/hdc3 32G 3.0G 27G 10% /mnt/homebaru

//Setelah seluruh drive ter-mount, lakukan perintah 'cp -arvf' sesuai dengan fungsi dari masing-masing direktori, misal direktori '/home' dicopykan ke '/home' yang baru, sesuai dengan aturan ke

Kemudian edit /etc/fstab sesuai mount drive yang akan dijalankan.

lalu masuk perintah:
# grub
map (hd1) (hd0)
//map
root(hd0,0)
setup (hd0)

Cara Mengembalikan Bootloader Yang HIlang

Untuk mengembalikan GRUB bootloader ternyata tidak susah.
Kita bisa menggunakan Live-CD dari berbagai distro. Pada kasus ini saya menggunakan Ubuntu.
Cukup masuk ke Ubuntu Live-CD, lalu buka terminal, masuk sebagai root, kemudian ketikkan perintah berikut:
# grub
root(hd0,0)
setup (hd0)

Maka GRUB otomatis terinstall pada (hd0,0).