Skip to content

Latest commit

 

History

History
164 lines (161 loc) · 3.9 KB

gnu-linux-disk.md

File metadata and controls

164 lines (161 loc) · 3.9 KB

Table of Contents:

disk

scsi

lsscsi

ubuntu

cat /proc/scsi/scsi

centos

yum install lsscsi

list scsi devices

cat /proc/scsi/scsi

list scsi hosts

ls /sys/class/scsi_host

rescan scsi

echo "- - -" > /sys/class/scsi_host/host#/scan
fdisk -l
tail -f /var/log/message

remove disk from sci

echo 1 > /sys/block/sdc/device/delete

fdisk

list

fdisk -l

format and partition

fdisk /dev/sdx

options :

  • n – create a new partition
  • p – print the partition table
  • can specify size , start and endpoint
  • d – delete a partition
  • w – write the new partition table and exit
  • q – quit without saving changes

mount new disk using the mount command

mkdir /disk1
mount /dev/sdx /disk1
df -H
  • mount automaticaly on reboot ( add to /etc/fstab)
/dev/sdx               /disk1           ext3    defaults        1 2

LVM

install on ubuntu

apt install lvm2

install on centos

yum install lvm2*

enable

systemctl enable lvm2-lvmetad.service
systemctl enable lvm2-lvmetad.socket
systemctl start lvm2-lvmetad.service
systemctl start lvm2-lvmetad.socket

pv ( LVMs physical volume )

create

pvcreate used to prepare a disk partition or a whole disk for use by LVM

pvcreate /dev/sd

list , display

To get LVM's internal view and details, use LVM commands Lists : use the lvs and pvs commands with option --segments Detailed view: use the lvdisplay and pvdisplay commands with option -m 1- lvs

  • List the physical segments used by a logical volume :
lvs --segments /dev/vg_ssd/lv_videos -o +lv_size,devices
  • List the physical extents of a given LV. Useful to move those segments (using pvmove):
lvs  /dev/vg_ssd/lv_videos -o seg_pe_ranges

3- lvdisplay

  • List the physical segments of a given logical volume, among other information:
lvdisplay -m /dev/vg_ssd/lv_videos

4- pvdisplay

  • Display the Logical volume associated with a given physical volume , among other information:
pvdisplay -m /dev/sdb1

5- pvs

  • list the logical volume (segments) inside a given Physical Volume:
pvs  /dev/sdb1  --segments  -o +lv_name,lv_size
  • Complex command, but full list :
 pvs   --segments  -o pv_name,pv_size,seg_size,vg_name,lv_name,lv_size,seg_pe_ranges

vg (volume group)

At least one physical volume is required to create a volume group.

create vg

vgcreate

 vgcreate testvg /dev/sdx1 /dev/sdx2 ...

list VGs or get vg details

vgdisplay testvg #testvg is optional

lv ( logical volume )

create lv in existing vg

lvcreate -n lv_data1 --size 12G testvg
  • options: -n : volume name --size[-L] : volume lv size -p{r|rw} : permision -M{y|n} : persistent

Display

lvdisplay