简介
A
ab
accept
ack
ag
alias
apachectl
apk
apropos
apt-get
aptitude
apt-key
apt-sortpkgs
ar
arch
arj
arp
arpd
arping
arptables
arpwatch
as
at
atop
atq
atrm
awk
axel
B
badblocks
base64
basename
batch
bc
bg
bind
blkid
blockdev
bmodinfo
break
builtin
bunzip2
bye
bzcat
bzcmp
bzdiff
bzgrep
bzip2
bzip2recover
bzless
bzmore
C
cal
cancel
cat
cd
cdrecord
chage
chattr
chcon
chfn
chgrp
chkconfig
chmod
chown
chpasswd
chroot
chsh
cksum
clear
clock
clockdiff
cmp
col
colrm
column
comm
command
compress
consoletype
continue
convertquota
cp
cpio
createrepo
crontab
csplit
cu
cupsdisable
cupsenable
curl
cut
D
date
dc
dd
declare
depmod
df
dhclient
dhcpd
dhcrelay
diff
diff3
diffstat
dig
dircolors
dirname
dirs
disown
dmesg
dmidecode
dnf
dnsdomainname
docker
domainname
dos2unix
dpkg-deb
dpkg-divert
dpkg-preconfigure
dpkg-query
dpkg-reconfigure
dpkg-split
dpkg-statoverride
dpkg-trigger
dpkg
dris
dstat
du
dump
E
e2fsck
e2label
echo
ed
edquota
egrep
eject
elinks
elm
emacs
enable
env
ethtool
ex
exec
exit
expand
export
exportfs
expr
F
false
fc
fdisk
fg
fgrep
file
find
findfs
finger
firewall-cmd
fishshell
fmt
fold
fping
free
fsck
ftp
ftpcount
ftpshut
ftptop
ftpwho
fuser
G
gcc
gcov
gdb
get_module
getenforce
getent
getsebool
git
gpasswd
gpm
grep
groupadd
groupdel
groupmems
groupmod
groups
grpck
grpconv
grpunconv
grub
grub2-mkconfig
grub2-set-default
gunzip
gzexe
gzip
H
halt
hcitool
hdparm
head
help
hexdump
history
host
hostid
hostname
hostnamectl
hping3
htdigest
htop
htpasswd
hwclock
I
iconv
id
ifcfg
ifconfig
ifdown
ifstat
iftop
ifup
indent
info
init
inotifywait
insmod
install
iostat
iotop
ip
ip6tables-restore
ip6tables-save
ip6tables
ipcalc
ipcrm
ipcs
iperf
iptables-restore
iptables-save
iptables
iptraf
iptstate
iscsiadm
ispell
J
jed
jobs
joe
join
journalctl
jq
jwhois
K
kernelversion
kexec
kill
killall
L
last
lastb
lastlog
ld
ldconfig
ldd
less
let
lftp
lftpget
lha
lilo
ln
lnstat
local
locate
logger
login
logname
logout
logrotate
logsave
logwatch
look
losetup
lp
lpadmin
lpc
lpq
lpr
lprm
lpstat
ls
lsattr
lsb_release
lsblk
lscpu
lsmod
lsof
lspci
lsusb
ltrace
lvcreate
lvdisplay
lvextend
lvreduce
lvremove
lvresize
lvscan
lynx
M
mail
mailq
mailstat
make
man
mapfile
md5sum
mesg
mii-tool
mkbootdisk
mkcert
mkdir
mke2fs
mkfs
mkinitrd
mkisofs
mknod
mkswap
mktemp
modetest
modprobe
more
mount
mpstat
mtools
mtr
mv
mysql
mysqladmin
mysqldump
mysqlimport
mysqlshow
N
named-checkzone
nano
nc
ncftp
neofetch
nethogs
netstat
newusers
nfsstat
ngrep
nice
nisdomainname
nl
nm
nmap
nmcli
nohup
nologin
nproc
nslookup
ntpdate
ntsysv
O
objdump
od
openssl
P
pacman
parted
partprobe
passwd
paste
patch
pathchk
perl
pfctl
pgrep
php
pico
pidof
pidstat
pigz
ping
ping6
pip
pkexec
pkill
pmap
popd
poweroff
ppp-off
pr
printf
protoize
prtstat
ps
pssh
pstack
pstree
pushd
pv
pvchange
pvck
pvcreate
pvdisplay
pvremove
pvs
pvscan
pwck
pwconv
pwd
pwdx
pwunconv
Q
quota
quotacheck
quotaoff
quotaon
R
rcconf
rcp
read
readelf
readonly
reboot
reject
rename
renice
reposync
repquota
resize
restore
restorecon
return
rev
rexec
rlogin
rm
rmdir
rmmod
route
rpm
rpm2cpio
rpmbuild
rpmdb
rpmquery
rpmsign
rpmverify
rsh
rsync
runlevel
S
sar
scp
screen
script
scriptreplay
sed
seinfo
semanage
sendmail
seq
service
sesearch
set
setfacl
setpci
setsebool
setsid
sftp-server
sftp
sh
sha256sum
shift
shopt
showmount
shuf
shutdown
skill
slabtop
sleep
slocate
smartmontools
smbclient
smbpasswd
sort
source
speedtest-cli
spell
split
squid
squidclient
ss
ssh-add
ssh-agent
ssh-copy-id
ssh-keygen
ssh-keyscan
ssh
sshd
sshpass
startx
stat
strace
strings
stty
su
sudo
sum
supervisord
suspend
swapoff
swapon
sync
sysctl
syslog
systemctl
systool
T
tac
tail
tailf
talk
tar
tcpdump
tcpreplay
tee
telinit
telnet
tempfile
test
tftp
time
timedatectl
times
tload
tmux
top
touch
tput
tr
tracepath
traceroute
trap
tree
true
tty
type
U
ulimit
umask
umount
unalias
uname
unarj
uncompress
unexpand
uniq
unlink
unprotoize
unrar
unset
unzip
updatedb
uptime
useradd
userdel
usermod
usernetctl
users
uucico
uupick
uuto
V
vdfuse
vgchange
vgconvert
vgcreate
vgdisplay
vgextend
vgreduce
vgremove
vgrename
vgscan
vi
vmstat
volname
W
w
wait
wall
watch
wc
wget
whatis
whereis
which
who
whoami
write
X
xargs
xauth
xclip
xhost
xinit
xlsatoms
xlsclients
xlsfonts
xrandr
xset
xz
Y
yes
ypdomainname
yum
Z
zcat
zfore
zip
zipinfo
zipsplit
znew
其他
7z
fdisk - Linux命令大全 - 笔下光年
网站首页
fdisk
查看磁盘使用情况和磁盘分区 ## 补充说明 **fdisk命令** 用于观察硬盘实体使用情况,也可对硬盘分区。它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。 ### 语法 ```shell fdisk [选项] <磁盘> 更改分区表 fdisk [选项] -l [<磁盘>...] 列出分区表 ``` ### 选项 ```shell 选项: -b, --sectors-size <大小> 显示扇区计数和大小 -B, --protect-boot 创建新标签时不要擦除 bootbits -c, --compatibility[=<模式>] 模式,为“dos”或“nondos”(默认) -L, --color[=<时机>] 彩色输出(auto, always 或 never)默认启用颜色 -l, --list 显示分区并退出 -x, --list-details 类似 --list 但提供更多细节 -n, --noauto-pt 不要在空设备上创建默认分区表 -o, --output <列表> 输出列 -t, --type <类型> 只识别指定的分区表类型 -u, --units[=<单位>] 显示单位,“cylinders”柱面或“sectors”扇区(默认) -s, --getsz 以 512-字节扇区显示设备大小[已废弃] -b, --bytes 以字节为单位而非易读的格式来打印 SIZE --lock[=<模式>] 使用独占设备锁(yes、no 或 nonblock) -w, --wipe <模式> 擦除签名(auto, always 或 never) -W, --wipe-partitions <模式> 擦除新分区的签名(auto, always 或 never) -C, --cylinders <数字> 指定柱面数 -H, --heads <数字> 指定磁头数 -S, --sectors <数字> 指定每条磁道的扇区数 -h, --help 显示此帮助 -V, --version 显示版本 ``` ### 参数 设备文件:指定要进行分区或者显示分区的硬盘设备文件。 ### 实例 首先选择要进行操作的磁盘: ```shell [root@localhost ~]# fdisk /dev/sdb ``` 输入`m`列出可以执行的命令: ```shell 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 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) ``` 输入`p`列出磁盘目前的分区情况: ```shell Command (m for help): p Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 1 8001 8e Linux LVM /dev/sdb2 2 26 200812+ 83 Linux ``` 输入`d`然后选择分区,删除现有分区: ```shell Command (m for help): d Partition number (1-4): 1 Command (m for help): d Selected partition 2 ``` 查看分区情况,确认分区已经删除: ```shell Command (m for help): print Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help): ``` 输入`n`建立新的磁盘分区,首先建立两个主磁盘分区: ```shell Command (m for help): n Command action e extended p primary partition (1-4) p //建立主分区 Partition number (1-4): 1 //分区号 First cylinder (1-391, default 1): //分区起始位置 Using default value 1 last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区 Command (m for help): n //再建立一个分区 Command action e extended p primary partition (1-4) p Partition number (1-4): 2 //分区号为2 First cylinder (101-391, default 101): Using default value 101 Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M ``` 确认分区建立成功: ```shell Command (m for help): p Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 125 200812+ 83 Linux ``` 再建立一个逻辑分区: ```shell Command (m for help): n Command action e extended p primary partition (1-4) e //选择扩展分区 Partition number (1-4): 3 First cylinder (126-391, default 126): Using default value 126 Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): Using default value 391 ``` 确认扩展分区建立成功: ```shell Command (m for help): p Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 125 200812+ 83 Linux /dev/sdb3 126 391 2136645 5 Extended ``` 在扩展分区上建立两个逻辑分区: ```shell Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l //选择逻辑分区 First cylinder (126-391, default 126): Using default value 126 Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (176-391, default 176): Using default value 176 Last cylinder or +size or +sizeM or +sizeK (176-391, default 391): Using default value 391 ``` 确认逻辑分区建立成功: ```shell Command (m for help): p Disk /dev/sdb: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 125 200812+ 83 Linux /dev/sdb3 126 391 2136645 5 Extended /dev/sdb5 126 175 401593+ 83 Linux /dev/sdb6 176 391 1734988+ 83 Linux Command (m for help): ``` 从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6) 注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。 最后对分区操作进行保存: ```shell Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ``` 建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。 在sdb1上建立ext2分区: ```shell [root@localhost ~]# mkfs.ext2 /dev/sdb1 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 100576 inodes, 200804 blocks 10040 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=209715200 7 block groups 32768 blocks per group, 32768 fragments per group 14368 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. ``` 在sdb6上建立ext3分区: ```shell [root@localhost ~]# mkfs.ext3 /dev/sdb6 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 217280 inodes, 433747 blocks 21687 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=444596224 14 block groups 32768 blocks per group, 32768 fragments per group 15520 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# ``` 建立两个目录`/oracle`和`/web`,将新建好的两个分区挂载到系统: ```shell [root@localhost ~]# mkdir /oracle [root@localhost ~]# mkdir /web [root@localhost ~]# mount /dev/sdb1 /oracle [root@localhost ~]# mount /dev/sdb6 /web ``` 查看分区挂载情况: ```shell [root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/VolGroup00-LogVol00 6.7G 2.8G 3.6G 44% / /dev/sda1 99M 12M 82M 13% /boot tmpfs 125M 0 125M 0% /dev/shm /dev/sdb1 773M 808K 733M 1% /oracle /dev/sdb6 1.7G 35M 1.6G 3% /web ``` 如果需要每次开机自动挂载则需要修改`/etc/fstab`文件,加入两行配置: ```shell [root@localhost ~]# vim /etc/fstab /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/sdb1 /oracle ext2 defaults 0 0 /dev/sdb6 /web ext3 defaults 0 0 ```
上一篇:
fc
下一篇:
fg