Senin, 23 September 2019

How to format and mount the new disk on Linux centos 7

  Tidak ada komentar
Check the disk
[[email protected] ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.8M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   71G  1.2G   70G   2% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
tmpfs                    1.6G     0  1.6G   0% /run/user/1000
[[email protected] ~]$
[[email protected] ~]$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0 98.9G  0 part
  ├─centos-root 253:0    0   71G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0   20G  0 lvm  /home
sdb               8:16   0    2T  0 disk
sr0              11:0    1 1024M  0 rom
[[email protected] ~]$
[[email protected] ~]$ cd /var/
[[email protected] var]$ ls
adm    crash  empty  gopher    lib    lock  mail       nis  preserve  spool  yp
cache  db     games  kerberos  local  log   nfsserver  opt  run       tmp
[[email protected] var]$

Make nfs server directory
[[email protected] var]$ sudo mkdir nfsserver
[[email protected] var]$
[[email protected] var]$ ls
adm    crash  empty  gopher    lib    lock  mail       nis  preserve  spool  yp
cache  db     games  kerberos  local  log   nfsserver  opt  run       tmp
[[email protected] var]$
Check the disk
[[email protected] var]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   71G  1.2G   70G   2% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
tmpfs                    1.6G     0  1.6G   0% /run/user/1000
[[email protected] var]$
Check the disk with fdisk -l command
[[email protected] var]$ sudo fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d135e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209469439   103685120   8e  Linux LVM

Disk /dev/sdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 76.2 GB, 76235669504 bytes, 148897792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Run fdisk command to /dev/sdb
[[email protected] var]$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x7867d703.

WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).


Command (m for help): p

Disk /dev/sdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x7867d703

   Device Boot      Start         End      Blocks   Id  System


Create new partition disk
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-4294967295, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294):
Using default value 4294967294
Partition 1 of type Linux and of size 2 TiB is set

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 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 hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x7867d703

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  4294967294  2147482623+  8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
Check the disk
[[email protected] var]$
[[email protected] var]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   71G  1.2G   70G   2% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
tmpfs                    1.6G     0  1.6G   0% /run/user/1000
[[email protected] var]$
[[email protected] var]$ sudo pvs
[sudo] password for myuser:
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <98.88g 4.00m
[[email protected] var]$ sudo lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao---- 20.00g
  root centos -wi-ao---- 71.00g
  swap centos -wi-ao---- <7.88g
[[email protected] var]$
Create physical volume and volume group 
[[email protected] var]$ sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[[email protected] var]$
[[email protected] var]$ sudo vgcreate nfsdata /dev/sdb1
  Volume group "nfsdata" successfully created
[[email protected] var]$
Check the physical volume, volume group and logical volume
[[email protected] var]$ sudo pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  centos  lvm2 a--  <98.88g  4.00m
  /dev/sdb1  nfsdata lvm2 a--   <2.00t <2.00t
[[email protected] var]$ sudo vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  centos    1   3   0 wz--n- <98.88g  4.00m
  nfsdata   1   0   0 wz--n-  <2.00t <2.00t
[[email protected] var]$ sudo lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao---- 20.00g
  root centos -wi-ao---- 71.00g
  swap centos -wi-ao---- <7.88g
[[email protected] var]$
[[email protected] var]$ sudo lvcreate -n nfsdata --size 2000G nfsdata
  Logical volume "nfsdata" created.
[[email protected] var]$
Check the disk partition
[[email protected] var]$ sudo fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d135e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209469439   103685120   8e  Linux LVM

Disk /dev/sdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x7867d703

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  4294967294  2147482623+  8e  Linux LVM

Disk /dev/mapper/centos-root: 76.2 GB, 76235669504 bytes, 148897792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Check the disks size
[[email protected] var]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   71G  1.2G   70G   2% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
tmpfs                    1.6G     0  1.6G   0% /run/user/1000
[[email protected] var]$
[[email protected] var]$ sudo lvs
  LV      VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos  -wi-ao---- 20.00g
  root    centos  -wi-ao---- 71.00g
  swap    centos  -wi-ao---- <7.88g
  nfsdata nfsdata -wi-a-----  1.95t
[[email protected] var]$
Format the disk with ext4 format
[[email protected] var]$ sudo mkfs.ext4 /dev/nfsdata/nfsdata
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072000 inodes, 524288000 blocks
26214400 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2671771648
16000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[[email protected] var]$
[[email protected] var]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   71G  1.2G   70G   2% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
tmpfs                    1.6G     0  1.6G   0% /run/user/1000
[[email protected] var]$
[[email protected] var]$ sudo mount /dev/mapper/nfsdata-nfsdata /var/nfsserver
[[email protected] var]$
Check the disks size

[[email protected] var]$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  8.9M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root       71G  1.2G   70G   2% /
/dev/sda1                   1014M  149M  866M  15% /boot
/dev/mapper/centos-home       20G   33M   20G   1% /home
tmpfs                        1.6G     0  1.6G   0% /run/user/1000
/dev/mapper/nfsdata-nfsdata  2.0T   81M  1.9T   1% /var/nfsserver
[[email protected] var]$
[myuse[email protected] var]$ sudo lvs
  LV      VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos  -wi-ao---- 20.00g
  root    centos  -wi-ao---- 71.00g
  swap    centos  -wi-ao---- <7.88g
  nfsdata nfsdata -wi-a-----  1.95t
[[email protected] var]$
Rename the volume group to data (optional)
[[email protected] var]$ sudo vgrename nfsdata data
  Volume group "nfsdata" successfully renamed to "data"
[[email protected] var]$
[[email protected] var]$ sudo lvs
  LV      VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao---- 20.00g
  root    centos -wi-ao---- 71.00g
  swap    centos -wi-ao---- <7.88g
  nfsdata data   -wi-a-----  1.95t
[[email protected] var]$
Mount the disk to /var/nfsserver mounting point
[[email protected] var]$ sudo mount /dev/mapper/data-nfsdata /var/nfsserver
[[email protected] var]$
[[email protected] var]$ df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                  7.8G     0  7.8G   0% /dev
tmpfs                     7.8G     0  7.8G   0% /dev/shm
tmpfs                     7.8G  8.9M  7.8G   1% /run
tmpfs                     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root    71G  1.2G   70G   2% /
/dev/sda1                1014M  149M  866M  15% /boot
/dev/mapper/centos-home    20G   33M   20G   1% /home
tmpfs                     1.6G     0  1.6G   0% /run/user/1000
/dev/mapper/data-nfsdata  2.0T   81M  1.9T   1% /var/nfsserver
[[email protected] var]$

Tidak ada komentar :

Posting Komentar