Disk, fdisk partition, MBR, dd command

CD and disk, u disk, floppy disk, hard disk What is the difference

① CD-ROM:

    cdrom / dvdrom: optical drive (CD-ROM drive)
    ROM: read-only
    ram: you can erase
    cd: 700M
    DVD: 4G

② floppy: floppy: floppy drive (floppy disk drive)
③U disk: U disk, USB flash drive full name, the English name "USB flash disk". Physical drive using a USB interface without miniature high-capacity mobile storage products, connected to the computer via the USB interface, plug and play.
④ Disk: an external memory of the computer also uses a similar apparatus tape, called commonly used disk, magnetic circular disk mounted on a side of the sealing box, the aim is to prevent the disk surface zoned injury, resulting in data loss.
⑤ HDD: hard sealed in a square box is used to store data.

Hard:

    solid state drive (SSD)
    mechanical hard disk (HDD)

    mixing a hard disk (HHD on a traditional mechanical hard new born out of the hard disk)
    the SSD using flash memory to store particles, using a magnetic disk to store an HDD, a hybrid hard disk to a magnetic hard disk and a flash memory integrated with a hard disk.

    Hard disk and what relationship?
    It is a type of hard disk.

SSD (Solid State Drives), referred to as a solid disk, a hard disk SSD (Solid State Drive) using solid state electronic storage array chip made by the control unit and a storage unit (FLASH chip, a DRAM chip) components.
Is the core of the hard disk read and write data from the speed through the interface.
What brand of disk

    Seagate Seagate
    Western Digital western digital
    Toshiba Toshiba
    Samsung samsung

good disk parameters to see what

common disk interface type:

    IDE - "out of
    SCSI -" out of (small computer system interface (Small Computer System Interface))
    Fiber Channel Channel Fiber
    SATA - "Serial Port hard disk - "common
    SAS -" mainstream

    SAS (serial Attached SCSI), serial Attached SCSI, SCSI is the next generation of technology, and pop the same hard disk serial ATA (SATA) now, and are based on serial technology to get more high transmission speed.

    SSD PCI-E - "fast (flash) speed, expensive

disk parameters

    Interface Type: IDE, SCSI, SATA, Fiber Channel
    interface rate: 6Gb / sec 1byte = 8bit byte bit bit byte
    capacity
    buffers: 64M 16M
    speed

track , sector, cylinder

    tracks: track. Comprising 63 sectors (from inside to outside ring number);
    sectors: sector. 512 bytes, the smallest physical storage unit. (Fan-shaped);
    Cylinder: cylinder. The same track on different platters cylinder - "Ring (FIG, cylinder: the same disc track a different composition cylinders.)

Herein described write image

 

 

When the cylinder is divided into partitions as the basic unit to calculate the size.
A cylindrical how much?

    Units = cylinders of 16065 * 512 = 8225280 bytes - " about 8MB
    cylindrical how = 255 * 63 * 512
    cylindrical much = (number of tracks) * (Sector) * (a little sector)

average access time

average access time ( Average Access time) refers to the head from a start position to reach the target track position, and the time required to find the data sector to be read from the target track.
It reflects the average access time to read and write speed of the hard drive, which includes a hard disk seek and latency, namely: the average access time = average seek time + average waiting time.
The average seek time

average seek time of the hard disk (Average Seek Time) refers to a hard disk head is moved to track the time required for the specified disk. The time, of course the smaller the better, an average seek time of the hard disk is typically between 8ms to 12ms, and SCSI hard disk should be less than or equal 8ms.
The average waiting time

hard waiting time, called latency (Latency), it refers to the head has a track to be accessed in the sector to be accessed waiting time to the downward rotation of the head. The average waiting time is half the time required for one rotation of the disc, the following should normally be 4ms.
read and write speed of the disk measured the dd command

[root @ liupeng ~] # dd if = / dev / zero of = dd.dd bs = 1M count = 1000


records read into the 1000 + 0
records 1000 + 0 written
1048576000 byte (1.0 GB) has been copied, 4.781 seconds, 219 MB / sec


In the SCSI system, data flow between the work processing system and a computer disk is done by a dedicated controller.
SAS hot-swappable disks, which is very important to maintain the availability of high demand environments.
Low-cost SATA disks, and SAS disks are not cheap.

SAS read speed: 1200MB / s
Interface Type: SAS (12Gbps)
Hard drive size: 2.5 inches
average seek time: 0.183ms

hard disk data transfer rate and data transfer rate comprises an internal and external data transfer rate.
Cache

Cache (Cache memory) is a memory chip on the hard disk controller with fast access speed of the hard disk which is a buffer between the internal storage and external interfaces. Since the data transmission speed different internal and external interfaces of the hard disk transfer rate, which functions as a cache buffer. Cache size and speed is an important factor directly related to hard disk transfer rate, and can greatly improve the overall performance of the hard disk. When the hard disk access fragmented data need to constantly exchange data between the hard disk and memory, a large cache, the data may be temporarily stored in the cache that fragmented, reducing the load of the external system, but also increases the speed of data transmission.
Partition

Disks - "Partition -" Format - "To Mount

    ① # fdisk -l -" All disk
    ② # fdisk / dev / sdb (the disk name) - "partition (interactive dynamic partitioning)
    ③ # mkfs. ext4 / dev / sdb1 - "format sdb1 (Make fileSystem ext4 file system)
    # mkfs.ext4 / dev / sdb2 -" format sdb2
    ④ # Mount / dev / sdb1 / Music / - "To Mount
    Mount # / dev / sdb2 / Vedio /
    # df -Th - "disk to view the current use of
    ⑤ # mkdir / music -" Use a disk
    # cd / Music /
    # mkdir liudehua - "Use a disk
    # LS liudehua Lost + found

PS : script automatically partitioning
requirements: script automatically formatted partition + + + boot mount automatically mount, sdc (co 30G)
30G, 2 zones, ext4, sdc1 - "/ E, SDC2 -" / F

# / bin /! the bash
c_part_fs () {
# partition
the fdisk / dev / SDC the EOF <<
n-
P
. 1

+ 1OG
n-
P
2

+ 1OG
W
the EOF
# format
mkfs.ext1 / dev / sdc1
mkfs.ext1 / dev / SDC2
[-d / E] mkdir || / E
[-d / F] || mkdir / F
# mount using
Mount / dev / sdc1 / E
Mount / dev / SDC2 / F
# automatic loading start using
     Exit the else      c_part_fs Fi parted software using # yum install parted to install parted software ① # parted / dev / sdb - " on sdb partition ② (parted) mklabel GPT -" New GPT type partition table ③ (parted) the mkpart Music. 1 3,000,000 # Create a new partition name for the music (this name is to identify the main role), the default size in MB compare fdisk and parted the     ①fdisk does not support large disk partition, especially when greater than 2T. Recommended GPT partition table format, use the parted command partition.     ②fdisk modify commands by default it does, if you do not save only operate in memory, does not really take effect. parted commands take effect immediately, the risk is relatively high.




























Exercise Title:

done on a virtual machine

    1. Add the two disks, and 50G to 100G size
    2. 50G will be divided into two main disk partitions, size and 20G and 10G, respectively an extended partition, dividing the next partition 2 extended logical partition, the size and 5G, respectively. 15G
    3. then four partitions formatted as ext4 file system, the new mount directory, the following specific mount
    10G - "/ mail -" ext4- " write
    20G-- "/ software-" ext4-- "mounted read only
    5G -" / movie - "ntfs- " reader
    15G - "/ photo -" vfat- " reader
    4. 100G disk partition table using GPT embodiment, the new size are two partitions 40G and 60G
    5. The system then formatted ext4 file, the new mount directory, the following specific loading:
    40G - "/ FTP-" ext4- "reader
    60G -" / www- "ext4-" write

answer:

! # / bin / the bash
fdisk_2 () {
the fdisk / dev / SDD the EOF <<
n-
P
. 1

+ 1OG
n-
P
2

+ 20G
n-
E
. 3


n-
L

+. 5G
n
l


w
EOF
mkfs.ext4 /dev/sdd1
mkfs.ext4 /dev/sdd2
mkfs.ext4 /dev/sdd5
mkfs.ext4 /dev/sdd6
[ -d /mail ]||mkdir /mail
[ -d /software ]||mkdir /software
[ -d /movie ]||mkdir /movie
[ -d /photo ]||mkdir /photo
mount /dev/sdd1 /mail
mount /dev/sdd2 /software
mount /dev/sdd5 /movie
mount /dev/sdd6 /photo
egrep "sdd1" /etc/rc.local||echo "mount /dev/sdd1 /mail" >>/etc/rc.local
egrep "sdd2" /etc/rc.local||echo "mount /dev/sdd2 /software" >>/etc/rc.local
egrep "sdd5" /etc/rc.local||echo "mount /dev/sdd5 /movie" >>/etc/rc.local
egrep "sdd6" /etc/rc.local||echo "mount /dev/sdd6 /photo" >>/etc/rc.local
}
fdisk_gpt () {
the parted / dev / SDE &> / dev / null << the EOF
mklabel GPT
the mkpart 40000 AA. 1
the mkpart BB 40001 100000
quit
the EOF
mkfs.ext4 / dev / sde1,
mkfs.ext4 / dev / SDe2
[-d / FTP] mkdir || / FTP
[-d / WWW] || mkdir / WWW
Mount / dev / sde1, / FTP
Mount / dev / SDe2 / WWW
}
IF the fdisk -l / dev / SDD | grep "^ / dev / SDD" &> / dev / null
the then
        echo "Your Disk alreadly the format !!"
        Exit
the else
        fdisk_2
        fdisk_gpt
Fi

  
the MBR (master boot record)

the MBR: the record the boot master: the master boot record. Each disk has MBR.
Hard disk cylinder 0, head 0, 1 sector is called the master boot sector
MBR size of 512 bytes, divided into three parts:

    ① The master boot program: 446 bytes to enable the system to find our system in that partition means
    ② the DPT hard disk partition table: Table 64 bytes Partition Disk
    ③ partition end marker: 2 bytes of

the DPT: partition table:

    the DPT size 64 bytes 16 bytes to account for each partition, so only divided into four partitions.
    Each primary partition to use 16 bytes describing
    the extended partition should occupy 16 bytes of primary partition space

to back up and restore the MBR MBR

consequences MBR is destroyed: the system will not start, all the partition information is lost, can not read the partition table I do not know how many partitions, since partition can not be read, so the partition file also can not read.
dd command function: backup, restore.
dd if = input file of = = output file block size BS count the number of blocks =

EG: dd if = / dev / SDA of = / Backup / sda.mbr BS = 512. 1 count =
dd is a command:

    IF input file input files to be backed up file
    of the output file output file to back up that file to go.
    the size of the backup data when the block size bs specified block units can define their own particular how the actual situation. The default is bytes. Units can be used k, M, G
    the number of count of the total block size BS * count =

the MBR backup, restore; create a file

    backup MBR: dd if = / dev / sda of = mba.bak bs = 512 count = 1
    restore MBR: dd if = mbr.bak of = / dev / sda bs = 512 count = 1
    Create the file 10M: dd if = / dev / zero of = test bs = 1M count = 10

simulation experiment MBR destruction:
1. Backup

backup sda: # dd if = / dev / sda of = / music / sda.mbr bs = 512 count = 1
backup sdb: #dd IF = / dev / sdb of = / sdb.mbr BS = 512 count = 1
2. sdb damage

by covering sdb 0 (destroyed): # dd if = / dev / zero of = / dev / sdb = 512 BS = COUNT. 1
(see sdb partition with fdisk -l / dev / sdb, will not discovery)
3. recovery sdb

recovery partition: # dd if = / sdb.mbr of = / dev / sdb bs COUNT = 512. 1 =
(re fdisk -l / dev / sda, so you can see)
4. sda destruction

destruction sda: # dd if = / dev / zero of = / dev / sda bs = 512 count = 1
restart, found inaccessible. (First guide disk, the second guide is an optical disc, so will require loading system.)

 

 
(Here there are pictures)

(Select "Boot from local drive", we found the entrance, because MBR sda has been destroyed)

 

 
(Here there are pictures)
partition table type, all three partition disk

relational partitions and disks: the zoning on disk.
Type (partition table) partition table:

    the MBR type (limited to four primary partitions)
    the GPT type (popular, unlimited primary partition)

the MBR partition table type (DOS disklabel):

    primary partition primary partition (up to 4)
        primary partitions can be used to install the operating system, up to four primary partitions. System starts, event, the primary partition
    extended partition Extension Partition (1)
    logical partitions logical partition (no number)

partition requires more than four time the remaining space can be used as an extended partition (only one extended partition).
Extended partition will occupy a primary partition location.
Extended partition can not store files directly - "extended just a concept
into logical partitions to store files
(Figure: Three partitions relations)
here Write Image Caption

 

 
No partition

disk number:

    behalf of a disk sda
    sdb disk 2 represents the

section number:

    primary partitions number: 1-4
    extended partition representing a primary partition number
    and logical partitions numbers: from 5 starts

first sda1 represents the disk 1 a primary partition
sda2 represent the first disks second main area
of a logical partition sda5 behalf of a disk
sda6 representative of first disks of 2 logical partitions
GPT partition table and the MBR (MSDOS) partition table distinction

globally unique identifier partition table (GUID partition table, abbreviations: GPT) is a physical hard partition structure. And support volumes up to 2 TB (Terabytes) and each disk has up to four primary partitions (or three primary partitions, an extended partition, and unlimited logical drives) style compared MBR partition, GPT partition style supports volumes up to 18 EB (Exabytes) and the number of partitions per disk is no upper limit, only by the operating system restrictions (due to the partition table itself needs to occupy a certain space, the initial planning hard disk partition, leaving the partition table space determines the maximum how many partitions, IA-64 version of Windows has a limit up to 128 partitions, the minimum size of the partition table is specified in this standard EFI).
Why the letter c system from the beginning?

A: Because A, B is a floppy disk. Floppy disk to be eliminated, are now almost in a state of being abandoned.

linux where everything is a file.
Linux in the hard disk, partition and other equipment are represented as files.

    hd - "IDE
    SD -" the USB SCSI SAS SATA

Detailed fdisk command partition will

use: partition management in an interactive operating environment
Format: fdisk [disk device]
interaction mode common instruction:

    m: View help information operation instruction
    P: List View partition information
    n: New Partition
    d : delete a partition
    w: save the partition settings and exit
    q: give up the partition settings and exit

partition: fdisk command
format: mkfs.ext3
mount use: mount

command formats:

    can not be formatted extended partition
    behind fdisk disk access device files
    parted / dev / print sdc
    back mkfs.ext3 access partition device file (the make ext3 filesystem)

Linux file systems: ext2 ext3 ext4 xfs and other
windows file system: ntfs, fat32

    classic default partitioning scheme:
    Linux inside: 1T
    ① / ext4 the Boot 500M boot linux core of the system file storage partition. - "windows in c drive;
    ②swap swap 32000M make use of virtual memory, when the shortage of real memory acts as a real memory usage. Follow the principle, twice the size of the real memory;
    ③ / ext4 all the remaining space to the root partition. By default, all the files are stored in the root partition.

    Ftp server:
    ① / the Boot ext4 500M
    ②swap swap 32000M
    ③ / Home ext4 200G
    ④ / var ext4 500G
    ⑤ / ext4 remaining space all to the root partition

is recommended you when the disk partitions, plan ahead specify the partition scheme, divided into many areas future good use.
Divided into many areas, can not use, I want to use when you can use.

Solution area of the disk's partition already in use, so that the back of the new points that can be used:

# df
file system 1K- block is mounted in% of available points with
/ dev / sda2 16,105,416 14,271,956 7% 1015336 /
tmpfs 508 336 0 508 336 0% / dev / SHM
/ dev / sda1 495 844 30235 440 009 7% / the Boot
/ dev / sda3 2,015,824 35768 1877656 2% / Home
/ dev / sdc1 10,325,748 154 136 9,647,092 2% / Software
# umount / Software / unmount the partition being used
# partprobe / dev / sdc - " partprode detection zones
LS # / dev / SDC *
/ dev / SDC / dev / sdc1 / dev / SDC2 / dev / SDC3

rescue mode

(there should be a diagram)

    1. Set the boot from the CD
    2. Select the Installed System Rescue
        fdisk the -l look at each disk the partition information
    3. Create a mount point mkdir / backup
    4. mount / dev / sdb1: Mount / dev / sdb1 / backup
        DF See mount case
    5. Go / backup directory
    6. recovery MBR

dd = IF / backup / of = sda.mbr / dev / sda bs = 512 COUNT = 1
fdisk the -l / dev / sda sda see if the recovery disk mbr
[#fsck / dev / sdc3 -y - "fix superblock]   



    7. Reboot the system to see if the hard disk into the system
    reboot
    8. re-set the first boot order to boot from the hard disk

into single-user mode

root user can change any user's password, ordinary users can only change their own passwords.
Password cracking step

    1. Restart the system
    2. The inner boot countdown time, knocking any key
    3. alphabetical to edit e
    4. Select the beginning of kernel rows, again by letter e edit, then enter the number 1 knock box, then hit ENTER. Single-user mode, to crack the code. This bypasses the password verification mode
    5. alphabetical key b to boot into the system
    6. passwd directly modify the root password
    7. Enter init 3 init 5 or into the system, the system restart or reboot

Vim / etc / inittab

0 HALT shutdown
1 single-user mode - "crack the code when
more than two-user mode -" You can not use NFS features
3 full multi-user mode, you can use the network function - "character interface
5 GUI
6 Reboot

init 0 shutdown
init 6 restart
init 3 to enter characters interface
----------------
Disclaimer: This article is the original article CSDN bloggers, "he has made Shenshan", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_18312025/article/details/78179548

Guess you like

Origin www.cnblogs.com/idyllcheung/p/11549876.html