Cài linux tren ổ cứng rời

Khi thêm một ổ cứng với vào hệ thống, cần dùng lệnh fdisk -l để kiểm tra xem Linux gán cho ổ cứng mới device nào.

Disk /dev/hda: 80.0 GB, 80060424192 bytes

255 heads, 63 sectors/track, 9733 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris

/dev/hda2 * 263 2873 20972857+ 83 Linux

/dev/hda3 2874 9733 55102950 83 Linux

Disk /dev/sda: 40.0 GB, 40007761920 bytes

64 heads, 32 sectors/track, 38154 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Lấy ví dụ trên máy đang có một harddisk 80GB được gán vào /dev/hda và chia thành 3 partition hda1, hda2, hda3. Harddisk thứ 2 40GB được gán vào /dev/sda, và harddisk này chưa được định dạng.

Cần chú ý rằng với một số hệ điều hành Linux, sẽ quy định khe IDE0 tương ứng với /dev/hda, khe IDE1 tương ứng với /dev/hdb,…

Các ổ cứng SCSI, hay USB sẽ được gán vào /dev/sda, /dev/sdb,… Với /dev/sda mới chưa được định dạng nói trên, trước hết ta dùng lệnh fdisk như sau:

255 heads, 63 sectors/track, 9733 cylinders0

255 heads, 63 sectors/track, 9733 cylinders1

255 heads, 63 sectors/track, 9733 cylinders2

255 heads, 63 sectors/track, 9733 cylinders3

255 heads, 63 sectors/track, 9733 cylinders4

255 heads, 63 sectors/track, 9733 cylinders5

255 heads, 63 sectors/track, 9733 cylinders6

255 heads, 63 sectors/track, 9733 cylinders7

255 heads, 63 sectors/track, 9733 cylinders8

255 heads, 63 sectors/track, 9733 cylinders9

Units = cylinders of 16065 * 512 = 8225280 bytes0

Units = cylinders of 16065 * 512 = 8225280 bytes1

Units = cylinders of 16065 * 512 = 8225280 bytes2

Units = cylinders of 16065 * 512 = 8225280 bytes3

Units = cylinders of 16065 * 512 = 8225280 bytes4

Units = cylinders of 16065 * 512 = 8225280 bytes5

Units = cylinders of 16065 * 512 = 8225280 bytes6

Khi dùng lệnh fdisk /dev/sda, sẽ xuất hiện chế độ gõ lệnh của fdisk, ấn m để đưa ra các hướng dẫn về lệnh của fdisk.

Trong ví dụ này, chọn n để thêm một partition mới.

Units = cylinders of 16065 * 512 = 8225280 bytes7

Units = cylinders of 16065 * 512 = 8225280 bytes8

Units = cylinders of 16065 * 512 = 8225280 bytes9

Device Boot Start End Blocks Id System0

Sau khi chọn n, xuất hiện 1 số lựa chọn như:

  • p để tạo primary partition – phân vùng có thể boot được.
  • e để tạo một phân vùng extended.

Đến đây ta chọn p. Sau khi chọn p, chương trình sẽ hỏi Partition number [1-4], gõ số 1.

Chương trình sẽ cho phép bạn thay đổi First cylinder và Last cylinder.

Chọn First cylinder = 1 và Last cylinder =20480.

Fdisk sẽ quay trở lại chế độ gõ lệnh chính của nó.

Tại chế đô gõ lệnh chính, dùng w để ghi lại các thông tin nói trên.

Device Boot Start End Blocks Id System1

Device Boot Start End Blocks Id System2

Sau khi chọn w, các thông tin sẽ được fdisk ghi lại trên hard-disk và fdisk tự động thoát, quay trở lại chế độ gõ lệnh của Linux.

Tại đây, gõ lệnh fdisk -l để kiểm tra các thay đổi.

Disk /dev/hda: 80.0 GB, 80060424192 bytes

255 heads, 63 sectors/track, 9733 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris

/dev/hda2 * 263 2873 20972857+ 83 Linux

/dev/hda3 2874 9733 55102950 83 Linux

Disk /dev/sda: 40.0 GB, 40007761920 bytes

64 heads, 32 sectors/track, 38154 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris4

Sau khi gõ lệnh fdisk -l, có thể nhận thấy một partition /dev/sda1 mới được tạo.

Và để format partition này, sử dụng lệnh mkfs

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris5

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris6

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris7

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris8

/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris9

/dev/hda2 * 263 2873 20972857+ 83 Linux0

/dev/hda2 * 263 2873 20972857+ 83 Linux1

/dev/hda2 * 263 2873 20972857+ 83 Linux2

/dev/hda2 * 263 2873 20972857+ 83 Linux3

/dev/hda2 * 263 2873 20972857+ 83 Linux4

/dev/hda2 * 263 2873 20972857+ 83 Linux5

/dev/hda2 * 263 2873 20972857+ 83 Linux6

Tuỳ vào dự định của bạn tạo dạng hệ thống file cho /dev/sda1 là ext2, ext3 hay một định dạng khác mà tao sẽ dùng tham số thích hợp.

Trong ví dụ trên, ta format /dev/sda1 với ext3. Sau khi format, để sử dụng được /dev/sda1, cần phải mount nó vào một mount point, giả sử mount vào /media/data

/dev/hda2 * 263 2873 20972857+ 83 Linux7

Để Linux tự động mount /dev/sda1 vào mount point nói trên, cần phải thêm vào file /etc/fstab dòng sau:

Chủ Đề