Disk Management in unit15 linux System

###################### Identification of Local Storage Devices
You can see by inserting u-disk

Plug in the U-disk to see the equipment
 Fdisk-l # # real device (not necessarily system-recognized)
Other devices in cat/proc/partition # system
 Bluekid # System Available Devices
 df \ The device on which the system is mounting


############# Mounting and unloading of equipment
# Device Name:

/dev/xdx	##/dev/hd0 /dev/hd1 /dev/sda /dev/sdb  /dev/sda1 /dev/sda2 /dev/sdb1
/dev/sr0	##CD drive
/dev/mapper/*	##Virtual Devices (Devices Simulated by Software)


###################### Equipment mounting

mount  equipment	mount point
mount /dev/sdb1	 /mnt			##Mount sdb1 to mnt
umount /mnt| /dev/sdb1			##uninstall
mount -o ro /dev/sdb1	 /mnt		##Read-only mounting
mount 					##View mount information
mount -o remount,rw /dev/sdb1  /mnt	##Reread, write and mount



######################################### Solve equipment busy situation

[root@foundation0 ~]# umount /mnt/
umount: /mnt: target is busy.			##There are programs that use this device.
        (In some cases useful info about processes that 
         the device is found by lsof(8) or fuser(1))
//Solution 1
fuser -vm /mnt	#See who's using / mnt
fuser -kvm /mnt	#View and end (open a shell to enter mnt and end in another shell)
umount /mnt

//Solution 2
lsof /mnt
[root@foundation0 ~]# 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    27446 root  cwd    DIR   8,17     4096    2 /mnt

kill -9 27446 #Kill-9: Manually kill a process
umount /mnt


################################### Disk partitioning####
1. The information recorded in 512 bytes of track 1 sector of hard disk 0 is as follows

512=446     +              64      +        2
     ^			    ^		    ^	
   MBR (master boot record) MPT (master partition table) 55AA (hard disk validity labeling)

########### Partition step

1.fdisk -l
2.fdisk /dev/vdb
m
a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition	##delete
   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 ##Newly build
   o   create a new empty DOS partition table
   p   print the partition table  ##display partition information
   q   quit without saving changes ##Sign out
   s   create a new empty Sun disklabel
   t   change a partition's system id  ##Modify partition id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit	##Save partition label information to hard disk
   x   extra functionality (experts only)


### Establish primary partition

Command (m for help): n		##Newly build
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p		##Main partition
Partition number (1-4, default 1): 	##id with default
First sector (2048-20971519, default 2048):     ##Partition initiation
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M ##Partition size
Partition 1 of type Linux and of size 500 MiB is set

Command (m for help): p	##display information

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: 0xb2cb6457

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   83  Linux

Command (m for help): wq


## When the system already has three primary partitions

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e		##Extended partitions should be partitioned before three main partitions appear
Selected partition 4
First sector (3074048-20971519, default 3074048): 
Using default value 3074048
Last sector, +sectors or +size{K,M,G} (3074048-20971519, default 20971519): 
Using default value 20971519
Partition 4 of type Extended and of size 8.5 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: 0xb2cb6457

   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	##Give all space to E

###### Install File System for Equipment####

mkfs.xfs	 /dev/vdb1	
mount /dev/vdb1	 /mnt
man 5 fstab
vim /etc/fstab
 Device, Mount Point, File System, Mount Parameters, Backup or Detection
/dev/vdb1	/mnt	xfs		defaults	0		0

mount -a
 # fstab is faster than rc.local and will be mounted when the hardware is checked out and the kernel starts

###################### swap partition management##

mkswap	/dev/vdb6
swapon	-a /dev/vdb6	
swapon -s
vim /etc/fstab                                    ###Auto Mount
/dev/vdb6	swap	swap	defaults	0 0                          


################################## swap partition deletion

vim /etc/fstab                                                ###Delete Automount
swapoff	 /dev/vdb6                                   ##Delete swap
swapon -s

########### Quotas###
Divide another vdb7 into 100M, format xfs, establish / public, change permission to 777
Mount vdb7 to / public, change the permissions (first hang the device, then change the permissions, the permissions are recorded in the device)

Quotas are for zoning. Because only in vdb7 are constraints imposed

mount -o usrquota /dev/vdb7 /public
chmod 777 /public
Switch to student user, dd if=/dev/zero of=/public/studentfile bs=1M count=20
30
If more people use this directory, no one will restrict it.

edquota -u studnet
Disk quotas for user student (uid 1000): (hard limit, how much to write at most)
Filesystem blocks soft hard inodes soft hard
/ dev/vdb7 0 (soft limit, over warning) 0 000 000
The size of data that users already have on the device
(Facts)
Inodes (number of files)
## Change the time limit

vim /etc/fstab
/dev/vdb7 /public xfs defaults,usrquota 0 0

test
[student@dns-server ~]$ dd if=/dev/zero of=/public/studentfile bs=1M count=200

########### Disk Encryption###

Place file system luks encryption on the lock

cryptsetup luksFormat /dev/vdb8
YES
cryptsetup open /dev/vdb8 westos
ll /dev/mapper/westos
mkfs.xfs  /dev/mapper/westos
mount /dev/mapper/westos  /mnt/
touch /mnt/file{1..10}
umount /mnt/
cryptsetup close westos After closure/dev/mapper/westos File disappearance
//It's not good to mount the original device / dev/vdb8. It's encrypted by luks.
cryptsetup open /dev/vdb8 westos
mount /dev/mapper/westos  /mnt/


Keywords: Linux lsof vim shell

Added by ciaranmg on Mon, 26 Aug 2019 15:29:42 +0300