(Rebels programming) linux command - hard disk partitions and mount

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Mr_Yang888/article/details/102595145

Goal: to be able to mount a new hard disk on a linux system (boot automatically loading)

Step 1: Check the current system disk mount

Check your system's hard to mount the case: lsblk -f (teachers do not leave)

sda
├─sda1 ext4 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]

sda: the current system has one physical disk sda

sda1: a first physical hard disk first partition

ext4: The format of this partition (linux common format)

7cc94e03-8b1a-4845-97fb-49a2c39afd8c: indicates that uniquely identifies the partition (unique ID)

/ Boot: indicates that the partition hung directory

[SWAP]: Swap

Swap: When there are large amounts of data need to write memory, but the memory is insufficient, the remaining data is written to a swap partition

Description swap partitions: big data cluster will close out the swap partition before installing the cluster.

fdisk -l

[root@node01 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00040944

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris

Part II: Adding a new hard disk for the virtual machine

In the vm virtual machine, right - "Set -" hard disk - "add -" Next. . . .

Linux system reboot

Re-view the disk mount case

​[root@node01 ~]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00040944

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris

/ Dev / sdb: represent new hardware (not sdb1 sdb2, no partition is not formatted)

The third step: to partition the disk and format

View the newly added partition

[root@node01 ~]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

The new disk partition

fdisk /dev/sdb

[root@node01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7a1242ed.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
​ switch off the mode (command ‘c’) and change display units to
​ sectors (command ‘u’).

The Command (m for Help): m (Help) (n: adding a partition, d: delete a partition w: for writes)

The Command (m for Help): n- (adding partitions)
the Command Action
E Extended
P Primary Partition (1-4)
P (partition type is set)
the Partition Number (1-4): . 1 (first partition)
First Cylinder (. 1 -1305, default. 1): . 1 (starting position of the first partition)
Last Cylinder, or Cylinders + size + {K, M, G} (1-1305, default 1305): 650 (end of the first partition position)

The Command (m for Help): n- (adding partitions)
the Command Action
E Extended
P Primary Partition (1-4)
P (partition type is set)
the Partition Number (1-4): 2 (second division)
First Cylinder (651 -1305, default 651): (the starting position of the second partition)
the Using default value 651
Last Cylinder, or Cylinders + size + {K, M, G} (651-1305, default 1305): (the second partition end position)
the Using default value 1305

Command (m for help): w(保存)
The partition table has been altered!

View the new partition

[root@node01 ~]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a1242ed

Device Boot Start End Blocks Id System
/dev/sdb1 1 650 5221093+ 83 Linux
/dev/sdb2 651 1305 5261287+ 83 Linux

New format a partition

​ mkfs -t ext4 /dev/sdb1

[amdha01 the root @ ~] # the mkfs -t ext4 / dev / sdb1
the mke2fs 1.41.12 (. 17-On May-2010)
file system label =
Operating System: Linux
block size = 4096 (log = 2)
block size = 4096 (log 2 =)
Stride blocks = 0, 0 = Stripe width blocks
326.4 thousand of inodes, 1,305,273 blocks
65263 blocks (5.00%) The Super User Reserved for
a first data block 0 =
the Maximum filesystem = 1337982976 blocks
40 block Groups
32768 blocks per Group, 32768 per Group fragments
8160 of inodes per Group
of Superblock Backups Stored ON Blocks:
32768, 98304, 163840, 229376, 294 912, 819200, 884 736

Writing inode tables: Finish
Creating journal (32768 blocks): complete
Writing superblocks and filesystem accounting information: complete

This filesystem will be automatically checked every 38 mounts or

After the completion of the disk format will be assigned UUID

[root@node01 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 10023089-17e3-4dbf-af6a-447b7e2011d2
└─sdb2

Step Four: hard mount

Prerequisite: mounted directory must already exist

mkdir /mnt/disk3

mkdir /mnt/disk4

Mount disk 1

​ mount /dev/sdb1 /mnt/disk3

​ mount /dev/sdb2 /mnt/disk4

Unmounted: umount / mnt / disk4

[root@node01 mnt]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3
└─sdb2 ext4 21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4
sda
├─sda1 ext4 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]

or

[root@node01 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4

Mount Disk Method 2

Boot automatically mount

Modify / etc / fstab file, add the configuration file automatically mount

UUID=fe1d0eea-50ea-4d44-853b-1c39e5129021 / ext4 defaults 1 1
UUID=7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot ext4 defaults 1 2
UUID=df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1 ext4 defaults 1 2
UUID=ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2 ext4 defaults 1 2
UUID=10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3 ext4 defaults 1 2
UUID=21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4 ext4 defaults 1 2
UUID=f306ece0-a790-41d7-b685-63585b8534e4 swap swap defaults 0 0

Save and exit

Remount all the hard drives in the system

​ mount -a

[root@node01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4

Guess you like

Origin blog.csdn.net/Mr_Yang888/article/details/102595145