CentOS New Hard Disk partitioning and setting automatic mounting for system startup
First, correctly connect the hard disk to the computer, view the BIOS, and ensure that the BIOS can detect and identify the new hard disk when the system starts the self-check, and then perform the following operations.
[Root @ Linux ~] # Fdisk-l// View the current disk information and you will find that the newly added hard disk is not a valid partition, as shown below:
Disk/dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sda1*1 1275 10241406 83 Linux
/Dev/sda2 1276 2349 8626905 83 Linux
/Dev/sda3 2350 2610 2096482 + 82 Linux swap/Solaris
Disk/dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk/dev/sdb doesn' t contain a valid partition table
[Root @ Linux ~] # Fdisk/dev/sdb// Partition the new hard disk as prompted
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 2610.
There is nothing wrong with that, but this is larger than 1024,
And coshould in certain setups cause problems:
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)
// You can enter h to view the help information.
Command (m for help): h
H: unknown command
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)
// This step is required
Command (m for help): n// Enter n to create a partition
Command action
E extended// Create a logical Partition
P primary partition (1-4)// Create a primary Partition
P// Input p to create the primary Partition
Partition number (1-4): 1// A total of four primary partitions can be divided. Input 1 to create the first primary partition.
First cylinder (1-2610, default 1 ):// Select the start disk Number of the partition. If you have no special requirements, we strongly recommend that you select the default disk number, that is, the default disk number is 1 (Press enter directly)
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-2610, default 2610 ):// Define the partition size. If you press the default value (Press ENTER), all available buckets are used. If you want to divide the partition into 1 GB space, enter + 1024 MB.
Using default value 2610
Command (m for help): w// Write the partition information to save the partition information.
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.
[Root @ Linux ~] # Fdisk-l// View the partition you just divided. The content is as follows. Pay attention to the information of the last line:
Disk/dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sda1*1 1275 10241406 83 Linux
/Dev/sda2 1276 2349 8626905 83 Linux
/Dev/sda3 2350 2610 2096482 + 82 Linux swap/Solaris
Disk/dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sdb11 2610 20964793 + 83 Linux// The underlined part is the partition, which must be correctly written during formatting.
[Root @ Linux ~] # Mkfs-t ext3-c/Dev/sdb1 // Format the partition using ext3. If multiple partitions are created,/dev/sdb2,/dev/sdb3, and so on are displayed. Enter this command again, you can format other partitions. Because the-c parameter is added to the new hard disk, it is necessary to check the bad track of the disk first. Therefore, this process takes a long time and requires patience ......
Mke2fs 1.39 (29-may-2006)
Filesystem label =
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632, 2654208,
4096000
Checking for bad blocks (read-only test): done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
[Root @ Linux ~] # Fdisk-l// View hard disk information again
Disk/dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sda1*1 1275 10241406 83 Linux
/Dev/sda2 1276 2349 8626905 83 Linux
/Dev/sda3 2350 2610 2096482 + 82 Linux swap/Solaris
Disk/dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sdb1 1 2610 20964793 + 83 Linux
[Root @ Linux ~] # Mkdir/dir// Create a mount directory
[Root @ Linux ~] # Mount/dev/sdb1/dir// Mount this new Hard Disk
[Root @ Linux ~] # Df-hl// Check whether the partition size is the same as what we reserve
Filesystem (File System) Size (capacity) Used (Used) Avail (available) Use % (Used %) Mounted on (mount point)
/Dev/sda1 9.5G 3.8g5.2G 43%/
/Dev/sda2 8.0G 361 M 7.3G 5%/linux
Tmpfs 506 M 0 506 M 0%/dev/shm
/Dev/sdb1 20G 173 M 19G 1%/dir// The last line is related to the new hard disk.
[Root @ Linux ~] # Vi/etc/fstab// Edit the/etc/fstab file and set the hard disk to be automatically mounted after the system starts. The last line is the added content.
LABEL = // ext3 defaults 1 1
LABEL =/web/linux ext3 defaults 1 2
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 defaults 0 0
LABEL = SWAP-sda3 swap defaults 0 0
/Dev/sdb1/dir ext3 defaults 1 2
"/Etc/fstab" 8L, 571C written
[Root @ Linux ~] # Df-h // view the hard disk information again. The last line is the newly added hard disk information.
Filesystem Size Used Avail Use % Mounted on
/Dev/sda1 9.5 GB 3.8G 5.2G 43%/
/Dev/sda2 8.0G 361 M 7.3G 5%/linux
Tmpfs 506 M 0 506 M 0%/dev/shm
/Dev/sdb1 20G 173 M 19G 1%/dir
[Root @ Linux ~] # Reboot// Restart the system
[Root @ Linux ~] # Df-h// View the hard disk information. At the same time, check whether operations such as adding a hard disk, attaching a hard disk, and automatically attaching a hard disk after the system is started are correct. If the last row appears, then our operation is correct.
Filesystem Size Used Avail Use % Mounted on
/Dev/sda1 9.5 GB 3.8G 5.2G 43%/
/Dev/sda2 8.0G 361 M 7.3G 5%/linux
Tmpfs 506 M 0 506 M 0%/dev/shm
/Dev/sdb1 20G 173 M 19G 1%/dir
// ========================= The following commands and comments, is the lite version ================================ //
[Root @ Linux ~] # Fdisk-l // view the current disk information and you will find that the newly added hard disk is not a valid partition, as shown below:
[Root @ Linux ~] # Fdisk/dev/sdb // partition the new hard disk as prompted
// You can enter h to view the help information.
Command (m for help): h
// This step is required
Command (m for help): n // enter n to create a partition.
Command action
E extended // create a logical Partition
P primary partition (1-4) // create a primary partition
P // input p to create the primary Partition
Partition number (1-4): 1 // a total of four primary partitions can be divided. Input 1 to create the first primary Partition.
First cylinder (1-2610, default 1): // select the number of starting disks for the partition. If you do not have any special requirements, we strongly recommend that you select default, that is, 1 is used for partitioning by default (Press enter directly)
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-2610, default 2610): // defines the partition size. If you press the default value (Press ENTER ), all available buckets are used. To divide the storage space into 1 GB, enter + 1024 MB.
Using default value 2610
Command (m for help): w // write partition information, which is actually to save partition information
[Root @ Linux ~] # Fdisk-l // view the partition you just divided. The content is as follows. Pay attention to the information of the last line:
/Dev/sdb11 2610 20964793 + 83 Linux // The underlined part is the partition, which must be correctly written during formatting
[Root @ Linux ~] # Mkfs-t ext3-c/Dev/sdb1// Format the partition using ext3. If multiple partitions are created,/dev/sdb2,/dev/sdb3, and so on are displayed. Enter this command again, you can format other partitions. Because the-c parameter is added to the new hard disk, it is necessary to check the bad track of the disk first. Therefore, this process takes a long time and requires patience ......
[Root @ Linux ~] # Fdisk-l // view hard disk information again
[Root @ Linux ~] # Mkdir/dir // create a mount directory
[Root @ Linux ~] # Mount/dev/sdb1/dir // mount this new Hard Disk
[Root @ Linux ~] # Df-hl // check whether the partition size is the same as what we reserve
/Dev/sdb1 20G 173 M 19G 1%/dir // The last line is related to the new hard disk.
[Root @ Linux ~] # Vi/etc/fstab // edit the/etc/fstab file, set the hard disk to be automatically mounted after the system starts, and add the last line
[Root @ Linux ~] # Df-h // view the hard disk information again. The last line is the newly added hard disk information.
[Root @ Linux ~] # Reboot // restart the system
[Root @ Linux ~] # Df-h // view the hard disk information. At the same time, check whether operations such as adding a hard disk, attaching a hard disk, and automatically attaching a hard disk after the system is started are correct. If the last row appears, then our operation is correct.