Add a new hard disk in Linux and a hard disk in Linux

Source: Internet
Author: User

Add a new hard disk in Linux and a hard disk in Linux

1. Find the new hard disk in the/dev/directory. sda is the local hard disk, sda1, and sda2. it is the partition, and sdb is the newly added hard disk, such:

[root@wusuyuan ~]# ls -ltr /dev/sd*
Brw-rw ----. 1 root disk 8, 0 November 14 14:12/dev/sda
Brw-rw ----. 1 root disk 8, November 14 14:12/dev/sda3
Brw-rw ----. 1 root disk 8, November 14 14:12/dev/sda2
Brw-rw ----. 1 root disk 8, November 14 14:12/dev/sda1
Brw-rw ----. 1 root disk 8, November 14 14:12/dev/sdb

The learned machine is a virtual machine, which is slightly different from the real physical machine. The real machine may be hda or hdb.

2. Use the Administrator permission to partition the New Hard Disk/dev/sdb:

[Root @ wusuyuan ~] # Fdisk/dev/sdb #### enter the partition
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb7ee5a9d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): m #### query help
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)
Command (m for help): n #### create a new partition
Command action
   e   extended
   p   primary partition (1-4)
E #### select the partition type (extended partition and primary partition)
Partition number (1-4): 1 #### number of partitions, which are divided into 1 Partition.
First cylinder (1-2610, default 1): 2610 #### enter the partition size. The default unit is mb.
Command (m for help): p #### view partition table information
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x35b64cad
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2610        2610        8032+   5  Extended
Command (m for help): w #### write partition information. If you are not sure or want to cancel the operation, enter q to exit.
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

When writing partition information, you must carefully check and confirm the information. After writing partition information, you cannot change it. After partitioning, the new hard disk is still unavailable and needs to be formatted.

3. Format hard disk partitions using mkfs:

[sywu@wusuyuan ~]$ mkfs
Usage: mkfs [-V] [-t fstype] [fs-options] device [size]
#-T format the partition type, such as ext3 and ext4
[Root @ wusuyuan ~] # Mkfs-t ext4/dev/sdb # format the partition, type: ext4
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
What should I do? (Y, n) y
File System tag =
Operating System: Linux
Block size = 4096 (log = 2)
Part size = 4096 (log = 2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000
Writing to inode table: complete
Creating journal (32768 blocks): Done
Writing superblocks and filesystem accounting information: 
Complete
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

After the partition is formatted, run the mount command to load the new partition:

[Root @ wusuyuan ~] # Mount/dev/sdb/disk2 # Load partitions
[Root @ wusuyuan ~] # Df-h # query partitions
File System capacity in use available % mount point
/dev/sda2              97G  9.9G   82G  11% /
tmpfs                 1.9G  200M  1.7G  11% /dev/shm
/dev/sda1             194M   52M  133M  28% /boot
/dev/sdb               20G  1.9G   17G  11% /disk2

4. Configure Automatic loading of New partitions:

# Configure Automatic partition loading in/etc/fstab
[root@wusuyuan ~]# vim /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Sun Jan  5 08:17:56 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9c738ca5-810a-46ec-b896-57fc8286b2a5 /                       ext4    defaults        1 1
UUID=05b44d26-bd3a-4688-81e1-c83da70512a7 /boot                   ext4    defaults        1 2
UUID=7146f132-f77b-4a17-8686-d7c9c9be10ad swap                    swap    defaults        0 0
                                        
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/Dev/sdb/disk2 ext4 defaults 1 2 # Add new partition information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.