Create a disk file system in linux

Source: Internet
Author: User
Article Title: Create a disk file system in linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

This article analyzes the shell script program to learn how to create a linux File System on a blank disk.

#! /Bin/bash

# I use a sata Hard Disk Based on the disk type.

DEV =/dev/sda

MNTDIR =/mnt/

### Make sure the size of primary disk is 320 GB #######

### Disk partition command

Fdiskstr = "n \ np \ n1 \ n + 319G \ nn \ np \ n2 \ n \ nt \ n2 \ n82 \ nw \ n"

#####

Grubstr = "root (hd1, 0) \ nsetup (hd1) \ nquit \ n"

Echo "---------------------------------------------"

Echo "-Warning: you are making a new disk, carefully -"

Echo "---------------------------------------------"

If ["$ DEV "! = "/Dev/sda"]; then

Echo "-Warning: the flash disk is not in sda, maybe crash your system -"

Echo "---------------------------------------------"

Exit-1

Fi

Action ()

{

Echo "$1"

$1

}

Hsleep ()

{

Sleep $1

Sync

}

# Dd usage: Convert and copy files. If zero is specified, No IO is generated and disk space is cleared.

If ["$1" = "clean"]; then

Action "dd if =/dev/zero of = $ DEV"

Sleep 1

Sync

Exit 0

Fi

Echo "Make disk partition table ..."

Action "dd if =/dev/zero of = $ DEV bs = 512 count = 1"

Hsleep 1

Echo "fdisk $ DEV"

### Output the command to fdisk $ DEV through the pipeline, disk partition

Echo-e "$ fdiskstr" | fdisk $ DEV

[$? -Ne 0] & exit-1

Hsleep 1

### Set sda2 as a swap Partition

Mkswap/dev/sda2

If [$? -Eq 0]; then

#### Create the linux File System ext3 on a specific partition, block 4096 bytes, set the-B option, the boss said it can improve the disk read/write speed.

#### Prevent some incidents

Action "mkfs-t ext3-B 4096/dev/sda1"

Else

Echo "fdisk $ DEV failed ."

Exit-1

Fi

####### After the partition setting file system ends, it is mounted to the partition and copied to the disk partition.

Echo "Copy file-system to/dev/sda1 ..."

Mount/dev/sda1 $ MNTDIR

Cp-dpRf common/* $ MNTDIR

Umount $ MNTDIR

Hsleep 1

### Forcibly write data in the buffer into the disk

Sync

Sleep 1

### Create a grub boot

Echo "Install grub ..."

Echo-e "$ grubstr" | grub -- no-floppy

Hsleep 1

### Check the file system

Action "fsck/dev/sda1"

Echo "Make new HR NM-3000 disk success, enjoy! "

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.