Wednesday, September 18, 2013

LIST DISK PARTITIONS COMMAND – CÔNG CỤ DÒNG LỆNH PARTITION

Làm thể nào để liệt kê tất cả các Hard Disk Partition trên hệ thống Linux?

Thông thường, Hard Disk được chia làm 1 hoặc nhiều ổ đĩa logic gọi là partition. Sự phân chia đó được tìm thấy trong partition table tại khu vực sector 0 của Hard Disk.
Trên Linux, thông thườn các Hard Disk được gán /dev/sda, /dev/sdb hoặc… Tên thiết bị liên quan đến chuẩn của Hard Disk. Ví dụ:
  1. /dev/hd* – IDE Disk . /dev/hda sẽ là Hard Disk đầu tiên, /dev/hdb sẽ là Hard Disk thứ hai,…
  2. /dev/sd* – SCSI hoặc SATA disk. /dev/sda sẽ là Hard Disk SCSI/SATA đầu tiên, còn /dev/sdb sẽ là Hard Disk SCSI/SATA thứ  2 và..
Lưu ý: Bạn nên thận trọng khi sử dụng các command dưới đây. Khi bất kỳ thao tác nào không đúng sẽ dẫn đến mất data.

lsblk Command

Liệt kê tất cả các Block Devices, chạy:
[root@linux24h ~]# lsblk
Outputs:
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                           8:0    0   20G  0 disk 
|-sda1                        8:1    0  500M  0 part /boot
|-sda2                        8:2    0 19.5G  0 part 
  |-VolGroup-lv_root (dm-0) 253:0    0 18.6G  0 lvm  /
  |-VolGroup-lv_swap (dm-1) 253:1    0  992M  0 lvm  [SWAP]
sr0                          11:0    1    4G  0 rom  

fdisk command – List Partitions Under Linux

Liệt kê chi tiết về Partition, run:
[root@linux24h ~]# fdisk -l
Outputs:
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005e900

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 19.9 GB, 19906166784 bytes
255 heads, 63 sectors/track, 2420 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 1040 MB, 1040187392 bytes
255 heads, 63 sectors/track, 126 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

sfdisk command

Ngoài fdisk command bạn có thể sử dụng sfdisk command, run:
[root@linux24h ~]# sfdisk -l /dev/sda
[root@linux24h ~]# sfdisk -lu /dev/sda
[root@linux24h ~]# sfdisk -ls /dev/sda
Outputs:
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+     63-     64-    512000   83  Linux
/dev/sda2         63+   2610-   2547-  20458496   8e  Linux LVM
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
Sử dụng tùy chọn để biết thêm thông tin, run:
[root@linux24h ~]# sfdisk --h

parted Command

Lưu ýfdisk và sfdisk command sẽ không làm việc nếu partition hệ thống lớn hơn 2TB, công cụ parted command được sinh ra để giải quyết vấn đề đó
Nếu hệ thống chưa được cài đặt parted tool. Run:
[root@linux24h ~]# yum install parted parted-devel -y
Sử dụng, run:
[root@linux24h ~]# parted /dev/sda
Outputs:
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
Bạn có thể set hiển thị dung lượng = TB hoặc GB thông qua unit command, run:
(parted) unit GB
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      0.00GB  0.53GB  0.52GB  primary  ext4         boot
 2      0.53GB  21.5GB  20.9GB  primary               lvm

(parted) quit      
Để liệt kê chi tiết tất cả Partition Layout trên tất cả Block Devices? Run:
[root@linux24h ~]# parted -l
Outputs:
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   21.5GB  20.9GB  primary               lvm


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/VolGroup-lv_swap: 1040MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system     Flags
 1      0.00B  1040MB  1040MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/VolGroup-lv_root: 19.9GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system  Flags
 1      0.00B  19.9GB  19.9GB  ext4

lsscsi command

Nếu hệ thống chưa được cài đặt công cụ giao diện dòng lệnh lsscsi, run:
[root@linux24h ~]# yum install lsscsi -y
Sử dụng:
[root@linux24h ~]# lsscsi
Outputs:
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[2:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 

Related Posts:

  • Vps config install vim # apt-get install libncurses5-dev python-dev # wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2 -O /data/vim-7.4.tar.bz2 # cd /data/ && tar jxf vim-7.4.tar.bz2 # cd vim74 && ./config… Read More
  • RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages RPM command is used for installing, uninstalling, upgrading, querying, listing, and checking RPM packages on your Linux system. RPM stands for Red Hat Package Manager. With root privilege, you can use the rp… Read More
  • Supervisor Supervisor is a great tool to start and manage long-running processes and the log files associated with them. It offers a lot of helpful features and is easy to get up and running. Install & Start Supervisor yum … Read More
  • Hướng dẫn biên dịch và cấu hình NginX Cài trình biên dịch và các gói phần mềm cần thiết để phục vụ quá trình biên dịch sudo apt-get install build-essential libssl-dev libpcre3 libpcre3-dev \ libxml2-dev libxslt1-dev libgd2-xpm-dev libgeoip-dev  Tải về mã n… Read More
  • Introducing vtop — A Terminal Activity Monitor in Node.js Command-line tools like “top” make it difficult to see CPU usage across multi-process applications (like Apache and Chrome), spikes over time, and memory usage. That’s why we created vtop. Vtop is a free and open so… Read More