Settings when adding an HDD in Linux


Although I learned in LPIC 1, I actually tried to execute the method such as creating a logical volume in Linux, which I did not have the opportunity to practice, so I summarized it.


--OS is Cent OS 8 --Additional devices are recognized by the OS -/ data01 (mount destination) has been created

Check device

Execute the lsblk command to check the device. This time, mount sdb with a disk capacity of 30 GB.

Execution command

# lsblk
sda           8:0    0   20G  0 disk 
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   19G  0 part 
  ├─cl-root 253:0    0   17G  0 lvm  /
  └─cl-swap 253:1    0    2G  0 lvm  [SWAP]
sdb           8:16   0   30G  0 disk <-Make this guy available
sr0          11:0    1  6.7G  0 rom  /run/media/centos/CentOS-8-BaseOS-x86_64

Create LVM volume

Execute the fdisk command to create an LVM volume.

Execution command

# fdisk /dev/sdb
fdisk (util-linux 2.32.1)welcome to.
The contents set here are retained only in the memory until the write command is executed.
Be careful when using the write command.

The device does not contain any recognizable partition information.
You have created a new DOS disk label. The identifier is 0x1a7585c5.

command(Help with m): m


a Toggle the bootable flag
b Edit the nested BSD disklabel
c Toggle DOS compatibility flag

d Delete the partition
F List areas without partitions
l List known partition types
n Add a new partition
p Display partition information
t Change partition type
v Validate partition information
i Display partition information

m Show this menu
u Change the display item unit
x Go to special features(Features for experts)

Read the iDisk layout from an sfdisk compatible script
O Write the disk layout to an sfdisk compatible script

Save and exit
w Write partition information to disk and exit
q Exit without saving changes

Create a new label
g new(nothing)Create a GPT partition table
G new(nothing) SGI (IRIX)Create a partition table
o new(nothing)Create a DOS partition table
s new(nothing)Create a Sun partition table

command(Help with m): n
Partition type
p primary partition(0 primary,0 extension,4 free)
e Extended area(Contains a logical partition)
Choice(Default value p): 

Consider it to be the default answer p.
Partition number(1-4,Default value 1): 
First sector(2048-62914559,Default value 2048): 
Last sector, +Sector number or+size{K,M,G,T,P} (2048-62914559,Default value 62914559): 62914559

I created a new partition 1 with type Linux, size 30 GiB.

command(Help with m): t
Select partition 1
Hexic code(List the codes available in L): L

0 Sky 24 NEC DOS 81 Minix/Old Li bf Solaris
1 FAT12 27 Hidden NTFS WinRE 82 Linux Swap c1 DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 Hidden OS/2 Also c6 DRDOS/sec (FAT-
 4  FAT16 <32M 40 Venix 80286 85 Linux Extended Region c7 Syrinx
5 Extended space 41 PPC PReP Boot 86 NTFS volume da non-FS data
6 FAT16 42 SFS 87 NTFS volume db CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x 88 Linux Plain de Dell Utility
 8  AIX             4e  QNX4.x 2nd par 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd par 93 Amoeba e1 DOS access
 a  OS/2 Boot Manager 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M a0 IBM Thinkpad Ha ea Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
f W95 extended area(L 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC  
12 Compaq Diagnosis 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16<32M 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or af HFS/ HFS+f2 DOS secondary
17 Hidden HPFS/NTFS  64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT32 70 DiskSecure Mult bb Hidden Boot Wizar fd Linux raid Automatic
1c Hidden W95 FAT32 75 PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e Hidden W95 FAT16 80 Old Minix be Solaris Boot ff BBT
Hexic code(List the codes available in L): 8e
Partition type'Linux'From'Linux LVM'Changed to.

command(Help with m): w
The partition information has changed.
ioctl()To reload the partition information.
The disks are syncing.

The settings are not written until the last "w" is executed, so if you make a mistake, end with "q".

Check partition

Check the status of the partition.

Execution command

# fdisk -l /dev/sdb
disk/dev/sdb: 30 GiB,32212254720 bytes,62914560 sector
unit:sector(1 * 512 =512 bytes)
Sector size(logic/Physics):512 bytes/512 bytes
I/O size(minimum/Recommendation):512 bytes/512 bytes
Disc label type: dos
Disk identifier: 0x1a7585c5

Device boot start position end position sector size Id type
/dev/sdb1           2048 62914559 62912512    30G 8e Linux LVM

Creating a physical volume

Execute the pvcreate command to create a physical volume.

Execution command

# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Check physical volume

Execute the pvdisplay command and check the creation result.

Execution command

# pvdisplay
"/dev/sdb1" is a new physical volume of "<30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               <30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Ix3Usf-par2-FMNM-XW0A-6tBl-5clP-4CmxxJ

Creating a volume group

Create a volume group. This time, we will name it VG01.

Execution command

# vgcreate VG01 /dev/sdb1
Volume group "VG01" successfully created

Check volume group

Execute the vgdisplay command.

Execution command

# vgdisplay
--- Volume group ---
  VG Name               VG01
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <30.00 GiB
  PE Size               4.00 MiB
  Total PE              7679
  Alloc PE / Size       0 / 0   
  Free  PE / Size       7679 / <30.00 GiB
  VG UUID               nuCPxf-O2hG-7XyC-YGgZ-yGJu-om25-IMtsqU

Execute the vgscan command.

Execution command

# vgscan
Reading all physical volumes.  This may take a while...
Found volume group "VG01" using metadata type lvm2

Creating a logical group

Execute the lvcreate command to create a logical group.

Execution command

# vcreate --name data -l 100%FREE VG01
  Logical volume "data" created.

Checking the logical group

Execute the lvdisplay command and check the creation result.

Execution command

# lvdisplay
--- Logical volume ---
  LV Path                /dev/VG01/data
  LV Name                data
  VG Name                VG01
  LV UUID                zHliYv-65wo-VmiQ-fRCO-YXR1-UBj8-5U7ZdI
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2020-06-17 12:52:27 +0900
  LV Status              available
  # open                 0
  LV Size                <30.00 GiB
  Current LE             7679
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

Creating a file system

Execute the following command to create a file system.

Execution command

# mkfs.xfs /dev/VG01/data
meta-data=/dev/VG01/data         isize=512    agcount=4, agsize=1965824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=7863296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=3839, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Perform mount

Add to the end of / etc / fstab and execute mount.


/dev/VG01/data /data01 xfs defaults 0 0

Reflect the settings.

Execution command

# mount -a

If no error message is output, OK.

Check the disk size

Finally, check the disc size.

Execution command

# df -h
/dev/mapper/VG01-data    30G  247M   30G    1% /data01

It is mounted properly and you can check the disk size.

Recommended Posts

Settings when adding an HDD in Linux
Be careful when adding an array to an array
Precautions when adding items using DateField to an existing model later in Django
[Linux] DNS settings
An app that you must put in Linux
Initial settings when using the foursquare API in python
I get an error when I put opencv in pyautoGUI
Read logging settings from an external file in Flask
When you get an error in python scraping (requests)
[Linux] [Initial Settings] System Settings
[Linux] su, sudo settings
Linux, Windows proxy settings
Seurat in Linux (installation)