1. 程式人生 > >linux-系統中的磁碟管理

linux-系統中的磁碟管理

####linux系統中的磁碟管理####

  1. 本地儲存裝置的識別
    fdisk -l ##真實存在的裝置
    cat /proc/partitions ##系統識別的裝置
    blkid ##系統可以使用的裝置
    df ##系統正在掛載的裝置

  2. 裝置的掛載和解除安裝
    裝置名稱
    /dev/xdx ##/dev/hd0 /dev/hd1 /dev/sda /dev/sdb /dev/sda1 /dev/sdb1
    /dev/sr0 ##光碟機
    /dev/mapper/* ##虛擬裝置(用軟體模擬出來的)
    裝置的掛載
    mount 裝置 掛載點
    mount /dev/sdb1 /mnt ##掛載sdb1到mnt
    umount /mnt或sdb1 ##解除安裝
    mount -o ro /dev/sdb1 /mnt ##只讀掛載
    mount ##檢視掛載資訊
    mount -o remount,rw /dev/sdb1或 /mnt ##重新讀寫掛載

  3. 解決裝置正忙問題
    [[email protected] ~]# umount /mnt
    umount: /mnt: target is busy.
    (In some cases useful info about processes that use
    the device is found by lsof(8) or fuser(1))

解決方法1:lsof /mnt

[[email protected] ~]# lsof /mnt
lsof: WARNING: can’t stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 12849 root cwd DIR 8,17 8192 1 /mnt

kill -9 12849
umount /mnt

解決方法2:
fuser -vm /mnt ##檢視
fuser -kvm /mnt ##檢視並結束

磁碟分割槽

1.fdisk -l
2.fdisk /dev/vdb
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): 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): ##id用預設
First sector (2048-20971519, default 2048): ##分割槽起始
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M ##分割槽大小
Partition 1 of type Linux and of size 500 MiB is set

Command (m for help): p ##顯示資訊

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xc3a0e4b3

Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 83 Linux
/dev/vdb2 1026048 2050047 512000 83 Linux
/dev/vdb3 2050048 3074047 512000 83 Linux
/dev/vdb4 3074048 20971519 8948736 5 Extended ##把所有剩餘空間都給擴充套件分割槽

4.給裝置安裝檔案系統
cat /proc/partitions
mkfs.xfs /dev/vdb1
vim /etc/fstab
裝置 掛載點 檔案系統 掛載引數 是否備份 是否檢測
/dev/vdb1 /mnt xfs defaults 0 0
mount -a

5.swap分割槽管理
(1)swap分割槽建立
劃分分割槽並設定分割槽標籤為82
mkswap /dev/vdb6
swapon -a /dev/vdb6
swapon -s
Filename Type Size Userd Priority
/dev/vdb6 partition 511996 0 -1

vim /etc/fstab
/dev/vdb6 swap swap defaults 0 0

(2)swap分割槽刪除
vim /etc/fstab

swapoff /dev/vdb6
swapon -s

####6.配額####
1.分割槽,格式化
mkdir /public
mount -o usrquota /dev/vdb7 /public

edquota -u student

vim /etc/fstab
加入:
/dev/vdb /public xfs defaults,usrquota 0 0

測試:
[[email protected] ~]$ dd if=/dev/zero of=/public/studentfile bs=1M count=500

####7.磁碟加密####
cryptsetup luckFormat /dev/vbd8
YES
cryptsetup open /dev/vdb8 westos
mkfs.xfs /dev/mapper/westos
mount /dev/mapper/westos /mnt/
touch /mun/file{1…10}
umount /mnt/
cryptsetup close westos ##關閉之後,/dev/mapper/westos檔案消失,掛載原始裝置也不能檢視其中的內容

cryptsetup open /dev/vdb8 linux
mount /dev/mapper/linux /mnt