9. Hard-disk
10.1 Disk Partitioning
The commands df, lsblk, and fdisk -l are all related to disks and file systems, but they have slightly different functionalities and usages.
- df is used to display the usage of mounted file systems, mainly focusing on the filesystem's utilization and available space
 - lsblk is used to list information about block devices, providing a more detailed device hierarchy, including disks, partitions, and mount points
 - fdisk -l is used to display detailed information about the disk partition table, including the starting sector, size, and filesystem type of each partition
 
Please note that the above commands should be executed with superuser or administrator privileges to obtain the complete output information.
10.1.1 df
Open Core3566 terminal and enter:
linaro@linaro-alip:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 5.9G 3.0G 2.7G 53% /
devtmpfs 1.9G 8.0K 1.9G 1% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 17M 1.9G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 1.9G 12K 1.9G 1% /tmp
/dev/mmcblk0p7 123M 13M 104M 11% /oem
/dev/mmcblk0p8 23G 44K 22G 1% /userdata
tmpfs 389M 12K 389M 1% /run/user/1000
/dev/sda 29G 64M 29G 1% /media/linaro/38E6EAF8E6EAB572The following are the meanings of each parameter in the output of the 'df -h' command:
- Filesystem: The name or device path of the filesystem
 - Size: Total size of the filesystem
 - Used: Amount of space used on the filesystem
 - Avail: Available space on the filesystem
 - Use%: Percentage of used space out of the total space
 - Mounted on: The mount point of the filesystem
 
For each line in the output, these parameters display the usage information of the corresponding filesystem:
- The first line represents the '/dev/root' filesystem, with a total size of 5.9GB, 3.0GB used, 2.7GB available, and a usage rate of 53%. It is mounted on the root directory '/'
 - The following lines show other filesystems and their mount points, such as '/dev/mmcblk0p7', '/dev/mmcblk0p8', and '/dev/sda'. '/dev/sda' is a partition mounted via an external USB device
 - Temporary filesystems (tmpfs) with mount points like '/dev/shm', '/run', '/run/lock', '/sys/fs/cgroup', and '/tmp'. These temporary filesystems reside in memory and do not persistently store data
 - '/run/user/1000' is a temporary filesystem specific to a particular user, and the ID may vary depending on the user
 
Note: The names of filesystems, device paths, and mount points may vary depending on the system configuration. The values in the output represent file sizes in GB, MB, or KB units.
10.1.2 lsblk
Open Core3566 terminal and enter:
linaro@linaro-alip:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.9G 0 disk /media/linaro/38E6EAF8E6EAB572
sdb 8:16 0 119.2G 0 disk
└─sdb1 8:17 0 119.2G 0 part /media/linaro/24FC743CFC7409F6
mmcblk0 179:0 0 29.1G 0 disk
├─mmcblk0p1 179:1 0 4M 0 part
├─mmcblk0p2 179:2 0 4M 0 part
├─mmcblk0p3 179:3 0 64M 0 part
├─mmcblk0p4 179:4 0 64M 0 part
├─mmcblk0p5 179:5 0 32M 0 part
├─mmcblk0p6 179:6 0 6G 0 part /
├─mmcblk0p7 179:7 0 128M 0 part /oem
└─mmcblk0p8 179:8 0 22.8G 0 part /userdata
mmcblk0boot0 179:32 0 4M 1 disk
mmcblk0boot1 179:64 0 4M 1 disk
nvme0n1 259:0 0 119.2G 0 disk
└─nvme0n1p1 259:1 0 119.1G 0 partThe following are the detailed meanings of each parameter in the output of the “lsblk” command:
- NAME: The name of the block device
 - MAJ:MIN: The major and minor device numbers of the block device
 - RM: Whether the device is removable (1 for removable devices, 0 for non-removable devices)
 - SIZE: The total size of the device
 - RO: Whether the device is read-only (1 for read-only, 0 for read-write)
 - TYPE: The type of the device (disk for a disk, part for a partition)
 - MOUNTPOINT: The mount point of the device
 
For each line in the output, these parameters provide detailed information about the block devices. In the output, there are mainly the following devices:
- sda is a USB flash drive that supports hot-plugging, RM=1, with a total size of 32GB (approximately 28.9GB in the system), and it is readable and writable
 - sdb is an msata hard drive connected via USB to SATA, not supporting hot-plugging, RM=0, with a total size of 120GB (approximately 119.2GB in the system), and it is readable and writable. It has only one partition, sdb1, which is mounted at /media/linaro/24FC743CFC7409F6
 - mmcblk0 is an onboard eMMC chip, not supporting hot-plugging, RM=0, with a total size of 32GB (approximately 29.1GB in the system), and it is readable and writable. It has eight partitions: mmcblk0p6 is the root file partition, containing the root file system and mounted at /(root directory); mmcblk0p7 is mounted at /oem with a size of 128MB; mmcblk0p8 is mounted on the /userdata partition with a size of 22.8GB
 - nvme0n1 is an NVMe hard drive, not supporting hot-plugging, RM=0, with a total size of 120GB (approximately 119.2GB in the system), and it is readable and writable. It is not mounted
 
10.1.3 fdisk
Open Core3566 terminal and enter:
linaro@linaro-alip:~$ sudo fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 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 /dev/mmcblk0: 29.1 GiB, 31272730624 bytes, 61079552 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
Disklabel type: gpt
Disk identifier: 29520000-0000-4513-8000-796200006B99
Device Start End Sectors Size Type
/dev/mmcblk0p1 16384 24575 8192 4M unknown
/dev/mmcblk0p2 24576 32767 8192 4M unknown
/dev/mmcblk0p3 32768 163839 131072 64M unknown
/dev/mmcblk0p4 163840 294911 131072 64M unknown
/dev/mmcblk0p5 294912 360447 65536 32M unknown
/dev/mmcblk0p6 360448 12943359 12582912 6G unknown
/dev/mmcblk0p7 12943360 13205503 262144 128M unknown
/dev/mmcblk0p8 13205504 61079487 47873984 22.8G unknown
Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SAMSUNG MZALQ128HBHQ-000L1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe998fbfc
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 303104 250067631 249764528 119.1G 7 HPFS/NTFS/exFAT
Disk /dev/sda: 28.9 GiB, 31029460992 bytes, 60604416 sectors
Disk model: DataTraveler 3.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x73736572
Device Boot Start End Sectors Size Id Type
/dev/sda3 0 0 0 0B 0 Empty以下是各个参数的详细含义:
- Disk /dev/ram0: A 4MB RAM disk.
- Units: Size units in sectors
 - Sector size (logical/physical): Logical and physical sector sizes
 - I/O size (minimum/optimal): Minimum and optimal input/output sizes
 
 - Disk /dev/mmcblk0: The built-in EMMC disk on Core3566 with a size of 29.1GB
- Units: Size units in sectors
 - Sector size (logical/physical): Logical and physical sector sizes
 - Disklabel type: Type of disk partition table (gpt indicates GUID partition table)
 - Disk identifier: Identifier of the disk
 - Device: Device name
 - Start: Starting sector of the partition
 - End: Ending sector of the partition
 - Sectors: Number of sectors in the partition
 - Size: Size of the partition
 - Type: Type of the partition
 
 - Disk /dev/nvme0n1: A 119.2GB NVMe disk.
- Disk model: Model of the disk
 - Units: Size units in sectors
 - Sector size (logical/physical): Logical and physical sector sizes
 - Disklabel type: Type of disk partition table (dos indicates MBR partition table)
 - Disk identifier: Identifier of the disk
 - Id: Identifier of the partition
 - In the output, there is only one partition /dev/nvme0n1p1, which is an HPFS/NTFS/exFAT type partition with a size of 119.1GB
 
 - Disk /dev/sda: A 28.9GB USB drive with only one partition, /dev/sda3, but it is an empty partition.
 
- Disk /dev/ram0: A 4MB RAM disk.
 
10.2 Disk Partitioning Operation
Specify the hard disk to be partitioned and enter the partitioning mode:
linaro@linaro-alip:~$ sudo fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition tableIn the fdisk interactive interface, enter "m" to get help, which lists the interactive commands recognized by fdisk. Let's explain these commands:
Command Explanation a Toggle a bootable flag b Edit bsd disklabel c Toggle the DOS compatibility flag d Delete a partition 1 Display known file system types. 82 for Linux swap partition, 83 for Linux partition m Display the help menu n Create a new partition 0 Create an empty DOS partition table p Display the partition list q Quit without saving s Create a new 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) 
10.2.1 Creating Partitions
We want to create a primary partition, the command is as follows:
linaro@linaro-alip:~$ sudo fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p  #View the partition list
Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SAMSUNG MZALQ128HBHQ-000L1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe998fbfc
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)       # p for primary partition
   e   extended (container for logical partitions)   # e for extended partition
Select (default p): p                                # I choose to create a primary partition, press Enter
Partition number (1-4, default 1): 1                 # I choose to create a primary partition, press Enter
First sector (2048-250069679, default 2048):         # Press Enter here, typically use the end size of the previous partition as the                                                            start size of this partition
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-250069679, default 250069679): +5G #Create a 5GB partition
Created a new partition 1 of type 'Linux' and of size 5 GiB.
Command (m for help): p 
Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SAMSUNG MZALQ128HBHQ-000L1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe998fbfc
Device         Boot Start      End  Sectors Size Id Type
/dev/nvme0n1p1       2048 10487807 10485760   5G 83 Linux
Command (m for help): w  #Finally, save and exit
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
10.2.2 Delete Partition
The command to delete a partition is as follows:
linaro@linaro-alip:~$ sudo fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): p
Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SAMSUNG MZALQ128HBHQ-000L1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe998fbfc
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
10.3 Disk Formatting
Formatting refers to the process of creating a specific file system on a partition. In Linux, there are various file system types such as ext2, ext3, ext4, xfs, and more. To view all available file system types, you can use the "mkfs" command followed by pressing TAB twice. (Please exercise caution when using this command and ensure that you have removed any unnecessary devices and backed up your data.)
linaro@linaro-alip:~$ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda            8:0    1  28.9G  0 disk /media/linaro/38E6EAF8E6EAB572
mmcblk0      179:0    0  29.1G  0 disk
├─mmcblk0p1  179:1    0     4M  0 part
├─mmcblk0p2  179:2    0     4M  0 part
├─mmcblk0p3  179:3    0    64M  0 part
├─mmcblk0p4  179:4    0    64M  0 part
├─mmcblk0p5  179:5    0    32M  0 part
├─mmcblk0p6  179:6    0     6G  0 part /
├─mmcblk0p7  179:7    0   128M  0 part /oem
└─mmcblk0p8  179:8    0  22.8G  0 part /userdata
mmcblk0boot0 179:32   0     4M  1 disk
mmcblk0boot1 179:64   0     4M  1 disk
nvme0n1      259:0    0 119.2G  0 disk
linaro@linaro-alip:~$ sudo mkfs
mkfs         mkfs.bfs     mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.ntfs
linaro@linaro-alip:~$ sudo mkfs.ext4 /dev/nvme0n1
mke2fs 1.44.5 (15-Dec-2018)
Found a dos partition table in /dev/nvme0n1
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 31258710 4k blocks and 7815168 inodes
Filesystem UUID: aa2d60dc-8d46-46e3-820f-e90dbd5cd968
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
10.4 Disk Mounting
10.4.1 Manual Mounting
First, create a mount point under the root directory:
sudo mkdir /mnt/luckfoxMounting Hard Drive:
linaro@linaro-alip:~$ sudo mount /dev/nvme0n1 /mnt/luckfox/
linaro@linaro-alip:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.9G 0 disk /media/linaro/38E6EAF8E6EAB572
mmcblk0 179:0 0 29.1G 0 disk
├─mmcblk0p1 179:1 0 4M 0 part
├─mmcblk0p2 179:2 0 4M 0 part
├─mmcblk0p3 179:3 0 64M 0 part
├─mmcblk0p4 179:4 0 64M 0 part
├─mmcblk0p5 179:5 0 32M 0 part
├─mmcblk0p6 179:6 0 6G 0 part /
├─mmcblk0p7 179:7 0 128M 0 part /oem
└─mmcblk0p8 179:8 0 22.8G 0 part /userdata
mmcblk0boot0 179:32 0 4M 1 disk
mmcblk0boot1 179:64 0 4M 1 disk
nvme0n1 259:0 0 119.2G 0 disk /mnt/luckfoxAfter mounting, there will be a 'lost+found' file in the /mnt/luckfox/ directory.
linaro@linaro-alip:~$ ls /mnt/luckfox/
lost+foundUnmounting a mount point using the umount command:
sudo umount /mnt/luckfox/
或者
sudo umount /dev/nvme0n1
10.4.2 Automatic Mounting (Use with Caution)
Note: This operation requires careful verification of the configuration file parameters and timely backup of your data. Incorrect configurations may result in the device being unable to boot. Manual mounting is recommended.
Use blkid to view the UUID of partitions. UUID uniquely identifies each partition to prevent incorrect mounting. Additionally, it will display the partition type.
linaro@linaro-alip:~$ sudo blkid
/dev/mmcblk0: PTUUID="29520000-0000-4513-8000-796200006b99" PTTYPE="gpt"
/dev/mmcblk0p1: PARTLABEL="uboot" PARTUUID="c2400000-0000-4e2e-8000-5abf000040fa"
/dev/mmcblk0p2: PARTLABEL="misc" PARTUUID="58640000-0000-443f-8000-6e6b00004a4b"
/dev/mmcblk0p3: PARTLABEL="boot" PARTUUID="b2660000-0000-4131-8000-062f00006ed5"
/dev/mmcblk0p4: PARTLABEL="recovery" PARTUUID="9a560000-0000-4b13-8000-5bd1000034dd"
/dev/mmcblk0p5: PARTLABEL="backup" PARTUUID="d6270000-0000-4b18-8000-0919000046ae"
/dev/mmcblk0p6: UUID="621abe90-b0a0-496c-a99c-b0a58f899d64" TYPE="ext4" PARTLABEL="rootfs" PARTUUID="614e0000-0000-4b53-8000-1d28000054a9"
/dev/mmcblk0p7: LABEL="oem" UUID="0ecbbe64-5664-4b7a-a9cc-d9e5139b6336" TYPE="ext2" PARTLABEL="oem" PARTUUID="6d240000-0000-4c0a-8000-4ebf000036c7"
/dev/mmcblk0p8: UUID="9b683981-e9c2-488b-8756-40f82c41d907" TYPE="ext2" PARTLABEL="userdata" PARTUUID="582b0000-0000-4e10-8000-10ad00001f9f"
/dev/nvme0n1: UUID="aa2d60dc-8d46-46e3-820f-e90dbd5cd968" TYPE="ext4"
/dev/sda: UUID="38E6EAF8E6EAB572" TYPE="ntfs"Create a mount point in the root directory:
sudo mkdir /mnt/luckfoxTo mount the NVME hard drive, modify the /etc/fstab file and add the following content at the end:
UUID="aa2d60dc-8d46-46e3-820f-e90dbd5cd968" /mnt/luckfox auto defaults 0 2- /mnt/luckfox is the directory to be mounted.
 - auto is the file system format of the hard drive partition to be mounted. "auto" automatically determines the file system format; other options include "ext4", "ntfs", and others.
 - defaults are the default options for the configuration file. "defaults" is the default option, and other options include "mode=1777", "rw,noauto", etc.
 - 0 and 2 are for backups and filesystem checks, respectively.