How to add a new hard disk to linux system.
25
Feb
Posted by: admin in: linux
คำสั่งที่เกี่ยวข้อง
1. fdisk เป็นคำสั่งที่เอาไว้ใช้จัดการเรื่อง partition ของ Hard drive
2. partprobe เป็นคำสั่งที่เอาไว้สำหรัรันเพื่อ update partition table
3. mkfs.ext3 คำสั่งในการสร้าง file system ext3
4. e2lable คำสั่งสำหรับไว้ทำ label ของ partition
5. mount คำสั่งสำหรับการนำ partition ที่สร้างเสร็จแล้วมาใช้งาน
[root@localhost ~]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table
; จากตรงนี้ จะมี hdd ขึ้นมาใหม่ชื่อว่า sdb แต่ยังไม่มี partition table
[root@localhost ~]# fdisk /dev/sdb
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 1305.
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 0×0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n ;เพื่อ create partition
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +10GB ;ระบุขนาดตามที่เราต้องการจะสร้าง
Command (m for help): p ;p เพื่อดูว่า partition ที่เราสร้างขึ้นมามีหรือยัง
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 17 136521 83 Linux
Command (m for help): w ;เพื่อทำการ save
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 17 136521 83 Linux
[root@localhost ~]# apt-get install parted
[root@localhost ~]# partprobe ;เป็นคำสั่งที่เอาไว้รันเพื่อ update partition table
[root@localhost ~]# mkfs.ext3 /dev/sdb1 ;สร้าง file system ext3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
34136 inodes, 136520 blocks
6826 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
17 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# e2label /dev/sdb1 /label_hdd2 ; สร้าง label (จะไม่สร้างก็ได้)
[root@localhost ~]# mkdir /mnt/hdd2
[root@localhost ~]# mount -t ext3 /dev/sdb1 /mnt/hdd2/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 7.7G 3.0G 4.4G 41% /
/dev/sda1 99M 15M 80M 16% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/sda3 965M 18M 898M 2% /home
/dev/sdb1 130M 5.6M 117M 5% /mnt/hdd2 <<<< ตรวจสอบ partition ที่เราได้ทำการ mount
;ถ้าต้องการให้ auto mount ทุกครั้งที่ restart
[root@localhost ~]# vi /etc/fstab
LABEL=/label_hdd2 /mnt/hdd2 ext3 defaults 1 2