磁盘管理Part1 :
1. 磁盘或者笔记本设备与Linux
系统的适配性 :
-
不同厂商硬件设备对
Linux
系统的支持与否,可以查看以下链接:RedHat 硬件支持 :
- 不同品牌型号笔记本对
Linux
系统的支持与否,可查看here
2. Linux
系统中的硬件设备
在Linux
系统中,硬件设备均被视为“文件”,而大部分硬件设备文件存放于目录/dev
之下。以SATA
接口的硬盘为例,硬盘的名称形式为/dev/sd[a-d]
. 另外,the linux kernel archives
的详细信息可以查看 here
另外,可以借助虚拟机创建虚拟化环境用于linux
系统的运行,虚拟化技术可以参考 Fedora Document
3. 磁盘分区
实体机器使用的磁盘名,形如/dev/sd[a-d]
, 而虚拟机环境下,可能会使用形如/dev/vd[a-p]
磁盘名,虚拟机以virtlO
接口接入磁盘时,使用virtlO
界面时,磁盘文件名形如/dev/vd[a-p]
, 而SATA/USB/SAS等磁盘接口都是使用SCSI
模块来驱动的,因此这些接口的磁盘设备名称都为/dev/sd[a-p]
的格式。根据Linux
检测到的磁盘顺序对磁盘设备加以命名。
磁盘第一个扇区存储整个磁盘重要信息,这种分区格式称为MBR(Master Boot Record)
。随着磁盘容量的增加,部分操作系统已经不能读取大于2G
的磁盘文件,因此出现了新的磁盘分区格式GPT(GUID partition table)
。
磁盘结构图示: 包括: platter/ actuator arm/disk sector/ track/ track sector/ cluster
分区表的两种格式:
MSDOS(MBR) 分区表格式:
GUID partition table, GPT 磁盘分区表
4. 磁盘操作命令
- 1.
fdisk
: Display or manipulate a disk partition table.
# fdisk --help
Usage:
fdisk [options] <disk> change partition table
fdisk [options] -l [<disk>] list partition table(s)
Display or manipulate a disk partition table.
Options:
-b, --sector-size <size> physical and logical sector size
-B, --protect-boot don't erase bootbits when creating a new label
-c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)
-L, --color[=<when>] colorize output (auto, always or never)
colors are enabled by default
-l, --list display partitions and exit
-o, --output <list> output columns
-t, --type <type> recognize specified partition table type only
-u, --units[=<unit>] display units: 'cylinders' or 'sectors' (default)
-s, --getsz display device size in 512-byte sectors [DEPRECATED]
--bytes print SIZE in bytes rather than in human readable format
-w, --wipe <mode> wipe signatures (auto, always or never)
-W, --wipe-partitions <mode> wipe signatures from new partitions (auto, always or never)
-C, --cylinders <number> specify the number of cylinders
-H, --heads <number> specify the number of heads
-S, --sectors <number> specify the number of sectors per track
-h, --help display this help
-V, --version display version
# fdisk -l
Disk /dev/sda: 45 GiB, 48318382080 bytes, 94371840 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
Disklabel type: dos
Disk identifier: 0x0f689d0d
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM
/dev/sda3 41943040 94371839 52428800 25G 8e Linux LVM
Disk /dev/mapper/cl-root: 37 GiB, 39724253184 bytes, 77586432 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/cl-swap: 2 GiB, 2147483648 bytes, 4194304 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
-
df
: Show information about the file system on which each FILE resides,
or all file systems by default.$ df --help Mandatory arguments to long options are mandatory for short options too. -a, --all include pseudo, duplicate, inaccessible file systems -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below --direct show statistics for a file instead of mount point -h, --human-readable print sizes in powers of 1024 (e.g., 1023M) -H, --si print sizes in powers of 1000 (e.g., 1.1G) -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info --total elide all entries insignificant to available space, and produce a grand total -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit $ df -a Filesystem 1K-blocks Used Available Use% Mounted on sysfs 0 0 0 - /sys proc 0 0 0 - /proc devtmpfs 5002356 0 5002356 0% /dev securityfs 0 0 0 - /sys/kernel/security tmpfs 5020460 0 5020460 0% /dev/shm devpts 0 0 0 - /dev/pts tmpfs 5020460 10204 5010256 1% /run tmpfs 5020460 0 5020460 0% /sys/fs/cgroup cgroup 0 0 0 - /sys/fs/cgroup/systemd pstore 0 0 0 - /sys/fs/pstore bpf 0 0 0 - /sys/fs/bpf cgroup 0 0 0 - /sys/fs/cgroup/perf_event ... cgroup 0 0 0 - /sys/fs/cgroup/devices cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio cgroup 0 0 0 - /sys/fs/cgroup/pids ... configfs 0 0 0 - /sys/kernel/config /dev/mapper/cl-root 38782976 23065508 15717468 60% / selinuxfs 0 0 0 - /sys/fs/selinux debugfs 0 0 0 - /sys/kernel/debug hugetlbfs 0 0 0 - /dev/hugepages mqueue 0 0 0 - /dev/mqueue systemd-1 0 0 0 - /proc/sys/fs/binfmt_misc /dev/sda1 999320 146144 784364 16% /boot sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs tmpfs 1004092 1180 1002912 1% /run/user/42 tmpfs 1004092 6956 997136 1% /run/user/1000 gvfsd-fuse 0 0 0 - /run/user/1000/gvfs fusectl 0 0 0 - /sys/fs/fuse/connections
-
lvs
: Display information about logical volumes -
parted
:# parted Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...] Apply COMMANDs with PARAMETERS to DEVICE. If no COMMAND(s) are given, run in interactive mode. OPTIONs: -h, --help displays this help message -l, --list lists partition layout on all block devices -m, --machine displays machine parseable output -s, --script never prompts for user intervention -v, --version displays the version -a, --align=[none|cyl|min|opt] alignment for new partitions COMMANDs: align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted
-
lsblk
: List information about block devices.# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 45G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 19G 0 part │ ├─cl-root 253:0 0 37G 0 lvm / │ └─cl-swap 253:1 0 2G 0 lvm [SWAP] └─sda3 8:3 0 25G 0 part └─cl-root 253:0 0 37G 0 lvm / sr0 11:0 1 1024M 0 rom
-
pvs
: Display information about physical volumes# pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- <19.00g 0 /dev/sda3 cl lvm2 a-- <25.00g <5.00g
-
resize2fs
:# resize2fs resize2fs 1.45.6 (20-Mar-2020) Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [-b|-s|new_size] [-S RAID-stride] [-z undo_file]
-
xfs_growfs
:Usage: xfs_growfs [options] mountpoint Options: -d grow data/metadata section -l grow log section -r grow realtime section -n don't change anything, just show geometry -i convert log from external to internal format -t alternate location for mount table (/etc/mtab) -x convert log from internal to external format -D size grow data/metadata section to size blks -L size grow/shrink log section to size blks -R size grow realtime section to size blks -e size set realtime extent size to size blks -m imaxpct set inode max percent to imaxpct -V print version information
-
vgdisplay
: Display volume group informationvgdisplay [ -A|--activevolumegroups ] [ -c|--colon ] [ -C|--columns ] [ -o|--options String ] [ -S|--select String ] [ -s|--short ] [ -O|--sort String ] ...
-
vgextend
: Add physical volumes to a volume groupvgextend VG PV ... [ -A|--autobackup y|n ] [ -f|--force ] [ -Z|--zero y|n ] [ -M|--metadatatype lvm2 ] [ --labelsector Number ] [ --metadatasize Size[m|UNIT] ] ...
-
`lvdisplay
: Display information about a logical volumelvdisplay [ -a|--all ] [ -c|--colon ] [ -C|--columns ] [ -H|--history ] [ -m|--maps ] [ -o|--options String ] [ -O|--sort String ] [ -S|--select String ] ...
-
lvextend
: Add space to a logical volumeExtend an LV by a specified size. lvextend -L|--size [+]Size[m|UNIT] LV [ -l|--extents [+]Number[PERCENT] ] [ -r|--resizefs ] [ -i|--stripes Number ] [ -I|--stripesize Size[k|UNIT] ] [ --poolmetadatasize [+]Size[m|UNIT] ] [ COMMON_OPTIONS ] [ PV ... ] Extend an LV by specified PV extents. lvextend LV PV ... [ -r|--resizefs ] [ -i|--stripes Number ] [ -I|--stripesize Size[k|UNIT] ] [ COMMON_OPTIONS ] Extend a pool metadata SubLV by a specified size. lvextend --poolmetadatasize [+]Size[m|UNIT] LV_thinpool [ -i|--stripes Number ] [ -I|--stripesize Size[k|UNIT] ] [ COMMON_OPTIONS ] [ PV ... ] Extend an LV according to a predefined policy. lvextend --usepolicies LV_snapshot_thinpool [ -r|--resizefs ] [ COMMON_OPTIONS ] [ PV ... ]
-
du -sch *
Usage: du [OPTION]... [FILE]... or: du [OPTION]... --files0-from=F Summarize disk usage of the set of FILEs, recursively for directories.
-
虚拟机中磁盘管理 :
Issue : CentOS8 in the VMware: No space left on device
1. Issue Description :
Initially, 20G Hard Disk(SCSI) was portioned to the CentOS8 in the virtual machine. For disk room occupied by the genome index file
, genome reference
,rawdata
and so on, and larger room would be required in the downstream analysis, so the disk resize would be rather necessary.
2. Solutions :
extend the logical volume :
NOTE : backup of the virtual machine through snapshots
or commands (e.g. cp
)
- identify the device and confirm the size :
fdisk -l
: -
create a new primary partition :
- (1) operate on the new device :
fdisk /dev/sd[a-p]
- (2) print the partition table : press
p
- (3) create a new primary partition: press
n
- (4) primary type : press
p
- (5) partition number , depending on the output of the partition table print. :
- (6) change system's partition ID :
t
- (7) select the newly creation partition :
- (8) change the Hex Code of the partition for Linux LVM : type
8e
- (9) write the change to the partition table : press
w
- (1) operate on the new device :
- identify the device and confirm the size :
-
reboot
the system CentOS8 - verify the changes has been written into the partition table and the type of the new partition is
8e
:fdisk -l
- convert the new partition to a physical volume :
pvcreate /dev/sd*
-
extend the physical volume :
- (1)
df
: show information about the file system , identify thehigh used
,low available
andMountpoint
- (2)
vgdisplay
: to check the volume group - (3) extend physical volume :
vgextend VolumeGroup /dev/sd*
- (1)
- verify how many physical extents are available to the VolumeGroup :
vgdisplay VolumeGroup | grep "Free"
- extend the logical volume :
lvdisplay
: to determine which logical volume to extendlvextend -L+*G /dev/VolumeGroup/LogicalVolume
: - expand the
ext3
filesystem online , inside of logical volume :xfs_growfs dir
:dir
is the volume group mountpoint - verify that the
dir
file system has the new space available :df -h dir
----
reference :
1.Extending a logical volume in a virtual machine running Red Hat or Cent OS
-