«

Linux-centos7 format disk and power on mount

Dreamer Published on Reading: 2211 linux


View all disk information in the system
[ root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0   47G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
Sdb 8:16 0 20G 0 disk The total capacity of the sdb is 20G. 1G has been allocated to sdb1. The mount point is/disk/disk1
└─sdb1            8:17   0    1G  0 part /disk/disk1  
sr0              11:0    1 1024M  0 rom
Partition the disk
[ root@localhost ~]# fdisk  /dev/sdb
Welcome to fdisk (util linux 2.23.2).

Changes remain in memory until you decide to write them to disk.
Think twice before using the write command.


Command (enter m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): the default is to directly enter
Start sector (2099200-41943039, default is 2099200): the default is to directly enter

The default value 2099200 will be used
Last sector,+sector or+size {K, M, G} (2099200-41943039, default is 41943039):+2G gives the partition 2G disk capacity
Partition 2 has been set to Linux type, and the size is set to 2 GiB

Command (enter m for help): w Save
Format Linux partition
[ root@localhost ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)
File System Label=
OS type: Linux
Block size=4096 (log=2)
Block size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: complete
Writing inode table: Done
Creating journal (16384 blocks): complete
Writing superblocks and filesystem accounting information: complete
Mount partition
[ root@localhost ~]#Mkdir/disk/disk2 Create a mount point
[ root@localhost ~]#Mount/dev/sdb2/disk/disk2 Mount the partition on/disk/disk2
Check whether the linux disk is mounted correctly
[ root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0   47G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
├─sdb1            8:17   0    1G  0 part /disk/disk1
▄ - sdb2 8:18 0 2G 0 part/disk/disk2 When this message appears, it indicates that the partition with 2G capacity we divided has been successfully mounted
└─sdb3            8:19   0    4G  0 part 
 
Create power on mount
 
/etc/fstab
# Created by anaconda on Tue Sep 15 22:40:14 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=b4099324-1543-4953-82ce-44dd626e1635 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1 /disk/disk1                                ext4     defaults        0 0   
/dev/sdb2/disk/disk2                                  ext4     defaults        0 0

After modifying the boot configuration file, press ESC and type: wq to save and exit

The command to unload the mounted device in the Linux system: umount/dev/(follow the disk partition here)



Centos7 Format Disk


Scan QR code and read on mobile phone