Linux System Management: File System mounting and automatic formatting scripts

Source: Internet
Author: User

In the morning, it is the final exam for training 033. Although it is 033, it is far more difficult than 033 under the guidance of Marco Polo... In the afternoon, I learned how to mount and left a small job to write a script to implement automatic partitioning. If you don't want to talk about it much, let's get into the question.

 

Classification of file systems:

Ext2, ext3, ext4, NTFS, XFS, JFS, reiserfs, ISO, swap, vfat, and so on ..

When there is a problem with so many file systems, I \ O should be taken into account in programming to identify the file system, then write the I \ O recognition program for different file systems, it is a big job.

Therefore, there is a middle-layer Virtual File System: VFS is located between the file system and the user, coordinates the user and the file system, and provides the same Calling Interface

 

Hard Disk category (by Interface ):

1. ATA
2. SATA: the serial port is 300 MB/S, 600 Mb/s, 4 Gbit/s, and a line is not disturbed.
3. SCSI: Parallel samll computer system interface with high throughput, long service life, high speed, enterprise application adapter with controller, similar to CPU, can fully control I/O, this greatly reduces the CPU burden and allows external storage.
4. SAS: Serial SCSI Simulation
5. There are other USB

With the concept of file system and hard disk, we can enter the topic of partitioning:

A hard disk can have up to four primary partitions. Why? This is due to technical reasons. The first 512 bytes of each hard disk is its boot block: bootloader, and 446 bytes are used to store a boot program to guide the operating system, the remaining 64 bytes are used to store partition information, that is, the familiar hard disk partition table MBR. The partition information of each partition is 16 bytes, so 64/16 = 4 partitions, is the primary partition or extended partition.

 

Linux partitions are divided into four major steps:

Fdisk:

Assume the hard disk is/dev/SDA.

Enter fdisk/dev/SDA in the command line.

The number of cylinders for this disk is set to 15665. there is nothing wrong with that, but this is larger than 1024, and cocould 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): // here press m

Relationship case attributes

M help
D is used to delete a partition.
N: Create a New partition + 10g and divide it into 10g. Due to the cylindrical size, the partition is not accurate.
P prints the partition and displays the existing partition type.
T adjust the partition type
W write to disk
Q: I regret it. Exit and do not save it.
A. Modify the active partition.

If you enter N, the system prompts you to select the start and end columns. After you select N, select the extended partition and press W to save and exit.

This completes the first step.

   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          13      104391   83  Linux/dev/sda2              14        5235    41945715   8e  Linux LVM/dev/sda3            5236        5300      522112+  82  Linux swap / Solaris/dev/sda4            5301       15665    83256862+   5  Extended/dev/sda5            5301       15665    83256831   83  Linux

Step 2: Reload partition table information

Command:

[root@server45 ~]# partprobe /dev/sda

Step 3: format the partition

mkfs -t  ext2 /dev/sda5

Or

mkfs.ext2 /dev/sda5

Last step: Mount

mkdir /mnt/sda5mount /dev/sda5 /mnt/sda5

Supplement: to enable automatic mounting upon startup, edit the/det/fstab file.

/dev/vol0/root          /                       ext3    defaults        1 1/dev/vol0/home          /home                   ext3    defaults        1 2LABEL=/boot             /boot                   ext3    defaults        1 2tmpfs                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0LABEL=SWAP-sda3         swap                    swap    defaults        0 0

There are 6 key fields.
1. devices to be mounted:/dev/sda5, label = nydata, UUID = ""
2. mount point:
3. File System Type:
4. Mount options: if multiple options are available, the options are separated by commas (,). Default Value: ults. If more options are required, defaults and ACL are used.
5. Dumping frequency: 0. No backup is performed. 1 indicates daily backup, and 2 indicates backup is not commonly used the next day.
6. File System self-check order: 0-9 0 no self-check, 1 Boot direct self-check (only root), 2 second (home), 3 ..

 

Automatic formatting script:

#!/bin/bashfdisk /dev/sda << EndnewEnd

In this script, assume that three primary partitions exist on the hard disk and format the last partition as an extended partition.

Let's extend this script. Assume that the hard disk has three primary partitions and one extended partition. The script is used:

1. Execute one operation to automatically create a 10 Gb logical partition and re-read the MBR.

2. format the new logical New Area
3. Create a folder with the new partition name under the/mint directory and automatically mount the partition.

#!bin/bashfdisk /dev/sda << Endn+10GwEndpartprobe /dev/sdaF=`fdisk -l /dev/sda | tail -1 | cut -d/ -f3 | awk '{print $1}'`mkfs /dev/$Fmkdir /mnt/$Fmnt /dev/$F /mnt/$F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.