Linux之系統分割槽管理
系統分割槽管理
/sda 系統第一塊串列埠硬碟,a代表第一塊
/cdrom,/dev/sr0 代表光碟機
/hd0 系統閉口硬碟
/mapper/ 軟體虛擬的裝置
硬碟的分割槽:MBR、擴充套件分割槽、邏輯分割槽
裝置的管理
查詢裝置的幾種方式:
fdisk -l # 發現磁碟,檢視系統當中真實存在的裝置,檢測硬體資訊,不一定被系統識別
df #預設顯示大小k,檢視系統中正在使用的
cat /proc/partitions #檢視系統識別的裝置,不一定可以用
blkid #系統中正在用或可以用的裝置
下面是用上述方法檢視裝置的測試:
1、fdisk -l #發現磁碟,檢視系統當中真實存在的裝置,檢測硬體資訊,不一定被系統識別
[[email protected] Desktop]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 534527 260M EFI System EFI System Partition
2 534528 567295 16M Microsoft reser Microsoft reserved partition
3 567296 210282495 100G Microsoft basic Basic data partition
4 210282496 783722495 273.4G Microsoft basic Basic data partition
5 783722496 1357162495 273.4G Microsoft basic Basic data partition
6 1566877696 1923518463 170.1G Microsoft basic Basic data partition
7 1923520512 1925568511 1000M Windows recover Basic data partition
8 1925568512 1951475711 12.4G Windows recover Basic data partition
9 1951475712 1953523711 1000M unknown Basic data partition
10 1357162496 1358186495 500M Microsoft basic
11 1358186496 1374441471 7.8G Linux swap
12 1374441472 1566877695 91.8G Microsoft basic
Disk /dev/sdb: 15.5 GB, 15500574720 bytes, 30274560 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: 0x491e3623
Device Boot Start End Blocks Id System
/dev/sdb1 63 30274271 15137104+ b W95 FAT32
2、cat /proc/partitions #檢視系統識別的裝置,不一定可以用
[root@foundation69 Desktop]# cat /proc/partitions
major minor #blocks name
8 0 976762584 sda
8 1 266240 sda1
8 2 16384 sda2
8 3 104857600 sda3
8 4 286720000 sda4
8 5 286720000 sda5
8 6 178320384 sda6
8 7 1024000 sda7
8 8 12953600 sda8
8 9 1024000 sda9
8 10 512000 sda10
8 11 8127488 sda11
8 12 96218112 sda12
7 0 3655680 loop0
7 1 3948544 loop1
8 16 15137280 sdb
8 17 15137104 sdb1
3、blkid #系統中正在用或可以用的裝置
[[email protected] Desktop]# blkid
/dev/sda1: LABEL="SYSTEM_DRV" UUID="2C9D-3FF5" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="42ff9e47-dded-464d-821a-f5a0c208241e"
/dev/sda2: PARTLABEL="Microsoft reserved partition" PARTUUID="39b1cdff-4bcd-4698-8692-0b869eadf047"
/dev/sda3: LABEL="Windows" UUID="D69CA0BA9CA09691" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="11d14992-fa38-4605-bbab-7e4fb1ad591a"
/dev/sda4: UUID="C2762FEE762FE241" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="c4432fec-f9d7-4bd6-ac98-2a5bfc44fd7f"
/dev/sda5: UUID="A8FE5AD7FE5A9CFE" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="da859020-9702-4ab6-8c89-ab9d0d30bb9a"
/dev/sda6: LABEL="M-fM-^\M-,M-eM-^\M-0M-gM-#M-^AM-gM-^[M-^X" UUID="FCCC321DCC31D31E" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="adf65f15-1033-4d6d-8433-7bb2dbc0f313"
/dev/sda7: LABEL="WINRE_DRV" UUID="4A389058389044BB" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="bf76e1f5-4e25-4e4d-abe8-e7b69b5281ac"
/dev/sda8: LABEL="LENOVO_PART" UUID="9EF894D0F894A7D3" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="a907a59f-84aa-4e45-bf6d-00f711474db0"
/dev/sda9: LABEL="LRS_ESP" UUID="76AA-2F71" TYPE="vfat" PARTLABEL="Basic data partition" PARTUUID="32751b55-dc09-4c92-9991-c96c0fb4577c"
/dev/sda10: UUID="e2951939-b44d-461c-aa97-61451d314755" TYPE="xfs" PARTUUID="24e182f5-e5c0-4677-ba99-3cc5bfed71b0"
/dev/sda11: UUID="78167bd6-fb99-4b6b-93b4-34e8dca06c82" TYPE="swap" PARTUUID="93964b3e-a068-4a32-8c69-5a82b5c0fe63"
/dev/sda12: UUID="ae1be246-09c6-4293-b590-89f8356a422f" TYPE="xfs" PARTUUID="e0144b46-05cc-417e-912d-11240366c076"
/dev/loop0: UUID="2014-05-07-03-58-46-00" LABEL="RHEL-7.0 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/loop1: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb1: LABEL="KINGSTON" UUID="08E4-2A63" TYPE="vfat"
4、
df #預設顯示大小k,檢視系統中正在使用的
df -H #10的n次方,1兆為1000k
df -h #2的n次方,1兆為1024k,更精確
[root@foundation69 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda12 96171132 19536600 76634532 21% /
devtmpfs 3910380 0 3910380 0% /dev
tmpfs 3925144 552 3924592 1% /dev/shm
tmpfs 3925144 9308 3915836 1% /run
tmpfs 3925144 0 3925144 0% /sys/fs/cgroup
/dev/sda10 505580 150328 355252 30% /boot
/dev/sda1 262144 37276 224868 15% /boot/efi
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 785032 24 785008 1% /run/user/1000
/dev/sdb1 15122312 7738320 7383992 52% /run/media/kiosk/KINGSTON
[root@foundation69 Desktop]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda12 92G 19G 74G 21% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 552K 3.8G 1% /dev/shm
tmpfs 3.8G 9.1M 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/sda10 494M 147M 347M 30% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
/dev/loop0 3.5G 3.5G 0 100% /var/www/html/source7.0
/dev/loop1 3.8G 3.8G 0 100% /var/www/html/source7.2
tmpfs 767M 24K 767M 1% /run/user/1000
/dev/sdb1 15G 7.4G 7.1G 52% /run/media/kiosk/KINGSTON
[root@foundation69 Desktop]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda12 99G 21G 79G 21% /
devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs 4.1G 566k 4.1G 1% /dev/shm
tmpfs 4.1G 9.6M 4.1G 1% /run
tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/sda10 518M 154M 364M 30% /boot
/dev/sda1 269M 39M 231M 15% /boot/efi
/dev/loop0 3.8G 3.8G 0 100% /var/www/html/source7.0
/dev/loop1 4.1G 4.1G 0 100% /var/www/html/source7.2
tmpfs 804M 25k 804M 1% /run/user/1000
/dev/sdb1 16G 8.0G 7.6G 52% /run/media/kiosk/KINGSTON
sdb1代表系統上的第一個分割槽
mount /dev/sdb1 /mnt #將裝置掛載在mnt上,讀寫掛載
[root@foundation69 Desktop]# mount /dev/sdb1 /mnt #將裝置vdb1掛載在mnt上
[root@foundation69 Desktop]# df #檢視掛載情況
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda12 96171132 19536604 76634528 21% /
devtmpfs 3910380 0 3910380 0% /dev
tmpfs 3925144 552 3924592 1% /dev/shm
tmpfs 3925144 9308 3915836 1% /run
tmpfs 3925144 0 3925144 0% /sys/fs/cgroup
/dev/sda10 505580 150328 355252 30% /boot
/dev/sda1 262144 37276 224868 15% /boot/efi
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 785032 24 785008 1% /run/user/1000
/dev/sdb1 15122312 7738320 7383992 52% /mnt
umount /mnt|/dev/sdb1 #解除安裝裝置,當裝置有任務執行時不能解除安裝裝置
[root@foundation69 Desktop]# umount /mnt
[root@foundation69 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda12 96171132 19536604 76634528 21% /
devtmpfs 3910380 0 3910380 0% /dev
tmpfs 3925144 552 3924592 1% /dev/shm
tmpfs 3925144 9308 3915836 1% /run
tmpfs 3925144 0 3925144 0% /sys/fs/cgroup
/dev/sda10 505580 150328 355252 30% /boot
/dev/sda1 262144 37276 224868 15% /boot/efi
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 785032 24 785008 1% /run/user/1000
/dev/sdb1 15122312 7738320 7383992 52% /run/media/kiosk/KINGSTON
lsof /dev/sdb1|/mnt #執行時,底下會顯示任務號,然後 kill -9 任務號,就可以結束該任務
fuser -kvm /dev/sdb1|/mnt #結束這個任務
fuser -vm /dev/sdb1|/mnt #檢視這個任務的程序
mount -o ro /dev/sdb1 /mnt #只讀掛載
注意:當只讀掛載時,可能會提示裝置正在忙或著已經掛載,這時我們解除安裝裝置然後進行只讀掛載就會成功
[root@foundation69 ~]# mount -o ro /dev/sdb1 /mnt
[root@foundation69 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda12 96171132 19538040 76633092 21% /
devtmpfs 3910380 0 3910380 0% /dev
tmpfs 3925144 160 3924984 1% /dev/shm
tmpfs 3925144 9248 3915896 1% /run
tmpfs 3925144 0 3925144 0% /sys/fs/cgroup
/dev/sda10 505580 150328 355252 30% /boot
/dev/sda1 262144 37276 224868 15% /boot/efi
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 785032 24 785008 1% /run/user/1000
/dev/sdb1 15122312 7769376 7352936 52% /mnt
[root@foundation69 ~]# cd /mnt #可以進入到掛載的目錄裡面
[root@foundation69 mnt]# touch file
touch: cannot touch ‘file’: Read-only file system #提示是隻讀形式,不能建立檔案
mount -o remount,rw /dev/sdb1 #重新讀寫掛載
[root@foundation69 mnt]# mount -o remount,rw /dev/sdb1
[root@foundation69 mnt]# touch file
[root@foundation69 mnt]# ls #檢視檔案是否建立
?? linux python-3.6.5-amd64 (1).exe rhel-server-7.0-x86_64-dvd.iso
file ??.py software
man mount #檢視引數
劃分分割槽
分割槽是硬體資訊,在分割槽表裡面
硬碟引導最少可寫446,最接近的共有512位元組,其中
mbr 主引導,最少可寫446位元組
mpt 主分割槽表,64位元組
55aa 硬碟的有效性標識,2位元組
一個分割槽用16個位元組記錄
分割槽有主分割槽p和擴充套件分割槽e,主分割槽有4個
擴充套件分割槽e裡面的分割槽為邏輯分割槽
分割槽步驟:
1、fdisk -l #檢視裝置,fdisk是用於管理磁碟分割槽的實用程式
2、fdisk /dev/vdb #給vdb劃分分割槽
3、cat /proc/partitions #檢視系統識別的分割槽資訊
4、如果沒有分割槽資訊:partprobe #手動同步分割槽表到核心
分割槽時的一些引數:
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 #修改分割槽功能id
u change display/entry units
v verify the partition table
w write table to disk and exit #儲存更改到分割槽表中
x extra functionality (experts only)
具體步驟如下:
[[email protected] ~]# fdisk -l
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
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
[[email protected] ~]# fdisk /dev/vdb
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 0x630ec371.
Command (m for help): n #新建分割槽
Partition type: #建立分割槽型別
p primary (0 primary, 0 extended, 4 free) #分割槽型別位主分割槽
e extended #分割槽型別位擴充套件分割槽
Select (default p): p #選擇分割槽型別
Partition number (1-4, default 1): 1 #主分割槽id
First sector (2048-20971519, default 2048): #此分割槽起始位置,一般預設
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M #分割槽大小,用+大小的方式指定
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M
Partition 3 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (616448-20971519, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519): +100M
Partition 4 of type Linux and of size 100 MiB is set
Command (m for help): n
If you want to create more than four partitions, you must replace a
primary partition with an extended partition first.
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 #標籤型別dos
Disk identifier: 0x630ec371
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 821247 102400 83 Linux
Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (616448-20971519, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Extended and of size 9.7 GiB 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: 0x630ec371
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
Command (m for help): wq #儲存分割槽策略,退出fdisk介面
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# cat /proc/partitions #檢視分割槽表
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 102400 vdb1
253 18 102400 vdb2
253 19 102400 vdb3
253 20 1 vdb4
裝置掛載
劃分好的分割槽還不可以用,需要將其格式化,才可用
1、mkfs.xfs /dev/vdb1 #將裝置vdb1格式化,在裝置上安裝檔案系統xfs
2、blkid #檢視可用裝置,可以看到被格式化好的/dev/vdb1
3、mount /dev/vdb1 /mnt #臨時掛載
測試:
[[email protected] ~]# mount /dev/vdb1
mount: can't find /dev/vdb1 in /etc/fstab
[[email protected] ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="35c735ac-b6e7-4ad8-8638-0c54bf6634aa" TYPE="xfs"
[[email protected] ~]# mount /dev/vdb1 /mnt
[[email protected] ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3190484 7283416 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 84 484848 1% /dev/shm
tmpfs 484932 12796 472136 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/vdb1 98988 5280 93708 6% /mnt
設定gpt分割槽格式
解決分割槽不能超過1TB的問題
1、先將原分割槽刪掉,同部分割槽表,看是否刪除
2、parted /dev/vdb #更改分割槽型別
3、格式化,掛載
測試:
[[email protected] ~]# fdisk -l #檢視是否有原分割槽
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start