Linux Auto partition mount

Source: Internet
Author: User

Using Fdisk partitioning

View the mounted hard drive with the fdisk-l command, assuming that the/DEV/SDC

# fdisk-l

...

disk/dev/sdc:10.7 GB, 10737418240 bytes

Heads, Sectors/track, 10240 cylinders, total 20971520 sectors

Units = sectors of 1 * MB = bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk identifier:0x00000000

DISK/DEV/SDC doesn ' t contain a valid partition table

To partition a hard disk:

# FDISK/DEV/SDC

then, as prompted, enterN, P, 1, as welltwo-time return, and then theWqto complete the save. This way you can see the newly created partition again through Fdisk-l/DEV/SDC1

# fdisk-l

...

disk/dev/sdc:10.7 GB, 10737418240 bytes

Heads, Sectors/track, 10240 cylinders, total 20971520 sectors

Units = sectors of 1 * MB = bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk IDENTIFIER:0X17ADB4CB

Device Boot Start End Blocks Id System

/DEV/SDC1 2048 20971519 10484736-up Linux

Format the second step after partitioning, for example format to EXT4 format

# mkfs-t EXT4/DEV/SDC1

The final step is to mount the hard drive:

# mkdir-p/application && mount-t ext4/dev/sdc1/application

Warning :

In order to prevent the host from a sudden power outage may pose a risk to the data, if the file system is ext3, you need to explicitly specify the "barrier=1" option at mount, such as "Mount-t Ext3-o barrier=1/dev/sdc1/mnt/ Point

2. How can I mount it automatically?

If you need to mount it automatically when the system starts, do not specify/DEV/SDC1 in the/etc/fstab directly, because the sequential encoding of devices in the cloud may change during shutdown and boot, and it is recommended to use the UUID or LABEL method to specify:

If the UUID is used, the disk's UUID is obtained first through the "BLKID/DEV/SDC1" command, for example:

/dev/sdc1:uuid= "185DC58B-3F12-4E90-952E-7ACFA3E0B6FB" type= "Ext4"

Then inside the/etc/fstab, add:

UUID=185DC58B-3F12-4E90-952E-7ACFA3E0B6FB /application ext4 Defaults 0 2

If you use label, you need to specify a label when you format the hard disk, for example:

Mkfs-t ext4-l MY_DISK_LABEL/DEV/SDC1

Then inside the/etc/fstab, add:

Label=my_disk_label/mnt/mydisk EXT4 Defaults 0 2

Script Auto-creation: partition, file system, mount, boot

#!/bin/bash hdd_id= ' fdisk -l | grep sd[cde] | awk  ' {print $2} '  | cut -d: -f1 '  fdisk  $HDD _id << eofnp1  weofecho   "/n/n****** $HDD _id __was fdisked! waiting for 10 second*****/n/n"    sleep 10s mkfs.ext4 ${HDD_ID}1 if [ $? -eq 0 ];then           echo  "/n/n*****${hdd_id}1 _________________was  formated, waiting for 5 second****/n/n "            sleep 5selse     exit 11fimkdir -p / Application && mount -t ext4 /dev/sdc1 /application uuid= ' Blkid  ${HDD_ID}1 | awk  ' {print $2} '  echo  ' $UUID &NBSP;/APPLICATION&NBSP;EXT4  defaults 0 2 " >> /etc/fstab 



Linux Auto partition mount

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.