Linux automatic mount file system details

Source: Internet
Author: User

Automatic mounting of Linux disks is required and necessary. Otherwise, it will be too troublesome to mount the disks after each restart.

1. view the disk information in the system and determine whether partitions are required.
First, add a new disk to the linux host as needed,
The purpose is to format the Newly Added Disk Partition and enable automatic mounting as the system starts.
[Root @ localhost ~] # Fdisk-l
[Here is the sda disk Information]
Disk/dev/sda: 299.4 GB, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sda1*1 13 104391 83 Linux
/Dev/sda2 14 36404 292310707 + 8e Linux LVM

[This is the disk information of sdb]
Disk/dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk/dev/sdb doesn't contain a valid partition table [this shows that the Disk dev/sdb has not been formatted]

As shown above, there are two disks, sda and sdb, and the system prompts that sdb does not contain a partition table. You need to perform partitioning.

2. partitioning a disk
Relationship between disk capacity and primary partition, extended partition, and logical partition:

Hard disk capacity = primary partition capacity + extended partition capacity
Capacity of extended partitions = total capacity of each logical Partition

A physical hard disk can only contain:
One to four primary partitions (but only one of them is an active primary partition ),
Or one or three primary partitions and one extended partition. Corresponding to hda1, hda2, hda3, hda4.

Linux stipulates that each hard disk device can contain up to four primary partitions (including extended partitions,
Any extended partition occupies a primary partition number, that is, in a hard disk, a maximum of four primary and extended partitions are used.

You can set only the primary partition for one hard disk. In this case, you can set four partition numbers for the primary partition.

You can also set it to primary partition + logical partition. At this time, it is also a maximum of four partition numbers, but it is changed to 4 = 3 + 1.
. 4 is a maximum of four primary and extended partitions;
. 3 is the primary partition, which can be less than or equal to 3;
. 1 refers to the extended partition number, which occupies a primary Partition Number.

[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 182024.
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)

Command (m for help): p [display basic disk Information]
Disk/dev/sdb: 1497.1 GB, 1497198755840 bytes
255 heads, 63 sectors/track, 182024 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

[We can see that the disk has not been partitioned]
Command (m for help): n [n: add a new partition]
Command action
E extended [select primary partition or extended partition]
P primary partition (1-4)
P
Partition number (1-4): 1 [select the number of partitions]
First cylinder (1-182024, default 1): [set the partition size. Select the default value here and press Enter]
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-182024, default 182024 ):
Using default value 182024
Command (m for help): w (if no error occurs, enter w to save the configuration information, if not, enter q to exit]
The partition table has been altered!

Calling ioctl () to re-read partition table.
Syncing disks

[Check whether the partition is successful]
$ Fdisk/dev/sdb
The number of cylinders for this disk is set to 182024.
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)

Command (m for help): p [view the disk information after partitioning as follows]
Disk/dev/sdb: 1497.1 GB, 1497198755840 bytes
255 heads, 63 sectors/track, 182024 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 182024 1462107748 + 5 Extended

Command (m for help): q

[If You Want To divide multiple partitions, perform the following operations]
[Root @ localhost ~] # Fdisk/dev/sdb
Command (m for help): p [p: print the partintion table]
Disk/dev/sdb: 6442 MB, 6442450944 bytes [display basic Disk Information]
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
We can see that the disk has not been partitioned.
Command (m for help): n [n: add a new partition]
Command action
E extended [select the primary partition or the extended partition, and select the primary partition here]
P primary partition (1-4)
P
Partition number (1-4): 3 [select the number of partitions]
First cylinder (1-783, default 1): [set the partition size. The value is 1000 MB. Is the number of the cylinder closest to MB]
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-783, default 783): + 1000 M
Command (m for help): w (if no error occurs, enter w to save the configuration information, if not, enter q to exit]
Command (m for help): p [view the disk information after partitioning as follows]
Disk/dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sdb1 368 783 3341520 83 Linux
/Dev/sdb2 124 367 1959930 83 linux
/Dev/sdb3 1 123 987966 83 Linux

3. format the partitioned Disk
[Root @ localhost ~] # Mkfs. xfs-f/dev/sdb [format disk sdb1 as xfs file system]
Meta-data =/dev/sdb isize = 256 agcount = 32, agsize = 137318400 blks
= Sectsz= 512 attr = 0
Data = bsize = 4096 blocks = 4394188800, imaxpct = 25
= Sunit = 0 swidth = 0 blks, unwritten = 1
Naming = version 2 bsize = 4096
Log = internal log bsize = 4096 blocks = 32768, version = 1
= Sectsz= 512 sunit = 0 blks, lazy-count = 0
Realtime = none extsz = 4096 blocks = 0, rtextents = 0

4. Mount the disk after the partition is formatted. Check whether the partition is formatted.
[Root @ localhost/] # mkdir/data [create a directory data]
[Root @ localhost/] # mount/dev/sdb/data/[mount the disk sdb to the system]

[Root @ localhost/] # cd/data
[Root @ localhost data] # ls [Perform a file write test to check whether the disk can be read/written (formatted)
[Root @ localhost data] # vim test.txt [write test]
[Root @ localhost data] # cat test.txt [read Test]

5. Uninstall the tool after the test is correct.
[Root @ localhost mnt] # umount/dev/sdb1

6. Modify the fstab file as follows:
[Root @ localhost mnt] # vim/etc/fstab
/Dev/VolGroup00/LogVol00/ext3 defaults 1 1
LABEL =/boot 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
/Dev/VolGroup00/LogVol01 swap defaults 0 0
Add a row]
/Dev/sdb/data xfs defaults 0 0

[If multiple partitions exist, add the following rows]
/Dev/sdb1/mnt/sdb1 ext3 defaults 0 0
/Dev/sdb2/mnt/sdb2 ext3 defaults 0 0
/Dev/sdb3/mnt/sdb3 ext3 defaults 0 0

7. Restart the linux system and check the mounting status.
[Root @ localhost sdb1] # df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/VolGroup00-LogVol00
238 GB 8.5G 218G 4%/
/Dev/sda1 99 M 13 M 81 M 14%/boot
Tmpfs 16G 0 16G 0%/dev/shm
/Dev/sdb 1.4 T 5.1 M 1.4 T 1%/data

[When multiple partitions exist]
File System 1 K-block used available % mount point
/Dev/sda1 8022104 2893532 4714500 39%/
Tmpfs 127720 0 127720 0%/dev/shm
/Dev/sdb1 3288944 71328 3050540 3%/mnt/sdb1
/Dev/sdb2 1929100 35696 1795408 2%/mnt/sdb2
/Dev/sdb3 972404 17640 905368 2%/mnt/sdb3

As shown above, the three partitions of the new disk are successfully mounted to the system.

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.