日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

基于Ubuntu的linux环境制作嵌入式SD/TF启动卡

發(fā)布時間:2023/12/9 linux 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于Ubuntu的linux环境制作嵌入式SD/TF启动卡 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

基于ubuntu在linux環(huán)境下對TF/SD卡進行分區(qū)、格式化,并完成文件寫入。

1. ubuntu連接TF/SD卡

將讀卡器插入電腦USB端口,點擊虛擬機vmware的如下圖標(biāo)連接到ubuntu系統(tǒng)

選擇連接(斷開與 主機的連接)(C)。
正常連接ubuntu后,可以通過如下命令查看卡的掛載情況:

ubuntu16@ubuntu:linux$ df -l Filesystem 1K-bloubuntu Used Available Use% Mounted on udev 1977084 0 1977084 0% /dev tmpfs 401592 16688 384904 5% /run /dev/sda1 122735644 31807804 84670128 28% / tmpfs 2007952 212 2007740 1% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 2007952 0 2007952 0% /sys/fs/cgroup /dev/loop0 113408 113408 0 100% /snap/core/12821 /dev/loop1 224512 224512 0 100% /snap/code/93 /dev/loop2 113280 113280 0 100% /snap/core/12834 /dev/loop3 224512 224512 0 100% /snap/code/94 vmhgfs-fuse 393942012 340255184 53686828 87% /mnt/hgfs tmpfs 401592 72 401520 1% /run/user/1000 /dev/sdb1 15549952 3300128 12249824 22% /media/ubuntu16/3762-3239 ubuntu16@ubuntu:linux$

我們的卡連接后對應(yīng)的設(shè)備是/dev/sdb1

2. 分區(qū)

首先去除卡的掛載

ubuntu16@ubuntu:linux$ sudo umount /dev/sdb1 [sudo] password for ubuntu16: ubuntu16@ubuntu:linux$ df -l Filesystem 1K-bloubuntu Used Available Use% Mounted on udev 1977084 0 1977084 0% /dev tmpfs 401592 16680 384912 5% /run /dev/sda1 122735644 31807784 84670148 28% / tmpfs 2007952 212 2007740 1% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 2007952 0 2007952 0% /sys/fs/cgroup /dev/loop0 113408 113408 0 100% /snap/core/12821 /dev/loop1 224512 224512 0 100% /snap/code/93 /dev/loop2 113280 113280 0 100% /snap/core/12834 /dev/loop3 224512 224512 0 100% /snap/code/94 vmhgfs-fuse 393942012 340255188 53686824 87% /mnt/hgfs tmpfs 401592 76 401516 1% /run/user/1000 ubuntu16@ubuntu:linux$

再次查看系統(tǒng)設(shè)備情況

ubuntu16@ubuntu:linux$ sudo fdisk -l ......Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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: dos Disk identifier: 0x00000000Device Boot Start End Sectors Size Id Type /dev/sdb1 8192 31116287 31108096 14.9G c W95 FAT32 (LBA) ubuntu16@ubuntu:linux$

從以上信息可以看出,我們需要操作的設(shè)備是/dev/sdb,執(zhí)行分區(qū)命令:

# 注意,此處是sdb,不是sdb1 ubuntu16@ubuntu:linux$ sudo fdisk /dev/sdbWelcome to fdisk (util-linux 2.27.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 #輸入p查看分區(qū) Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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: dos Disk identifier: 0x00000000Device Boot Start End Sectors Size Id Type /dev/sdb1 8192 31116287 31108096 14.9G c W95 FAT32 (LBA)Command (m for help): d #輸入d刪除原有分區(qū) Selected partition 1 Partition 1 has been deleted.Command (m for help): d #輸入d確認分區(qū)是否刪除成功 No partition is defined yet! Could not delete partition 1Command (m for help): n #輸入n創(chuàng)建新分區(qū) Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions) Select (default p): p #輸入p選擇分區(qū)空間 Partition number (1-4, default 1): 1 First sector (2048-31116287, default 2048): 16384 Last sector, +sectors or +size{K,M,G,T,P} (16384-31116287, default 31116287): +3GCreated a new partition 1 of type 'Linux' and of size 3 GiB.Command (m for help): p Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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: dos Disk identifier: 0x00000000Device Boot Start End Sectors Size Id Type /dev/sdb1 16384 6307839 6291456 3G 83 LinuxCommand (m for help): n Partition typep primary (1 primary, 0 extended, 3 free)e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (2048-31116287, default 2048): 6307840 Last sector, +sectors or +size{K,M,G,T,P} (6307840-31116287, default 31116287): Created a new partition 2 of type 'Linux' and of size 11.8 GiB.Command (m for help): p Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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: dos Disk identifier: 0x00000000Device Boot Start End Sectors Size Id Type /dev/sdb1 16384 6307839 6291456 3G 83 Linux /dev/sdb2 6307840 31116287 24808448 11.8G 83 LinuxCommand (m for help): w #輸入w保存分區(qū) The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.

查看剛才的分區(qū)情況,如下:

ubuntu16@ubuntu:linux$ sudo lsblk [sudo] password for ubuntu16: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop1 7:1 0 219.1M 1 loop /snap/code/93 sdb 8:16 1 14.9G 0 disk ├─sdb2 8:18 1 11.8G 0 part └─sdb1 8:17 1 3G 0 part ...... ubuntu16@ubuntu:linux$

3.格式化

ubuntu系統(tǒng)自帶了多種格式化工具,如下圖所示:

ubuntu16@ubuntu:linux$ mkfs mkfs mkfs.cramfs mkfs.ext3 mkfs.ext4dev mkfs.minix mkfs.ntfs mkfs.bfs mkfs.ext2 mkfs.ext4 mkfs.fat mkfs.msdos mkfs.vfat

將卡的兩個分區(qū)格式化成ext3格式:

ubuntu16@ubuntu:linux$ sudo mkfs.ext3 /dev/sdb1 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 786432 4k bloubuntu and 196608 inodes Filesystem UUID: 3fe3147c-e558-46fe-b197-e537e1852122 Superblock backups stored on bloubuntu: 32768, 98304, 163840, 229376, 294912Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (16384 bloubuntu): 完成 Writing superbloubuntu and filesystem accounting information: 完成 ubuntu16@ubuntu:linux$ sudo mkfs.ext3 /dev/sdb2 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 3101056 4k bloubuntu and 776720 inodes Filesystem UUID: d7d23a79-b91b-413d-be42-903d1fc9e5a2 Superblock backups stored on bloubuntu: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 bloubuntu): 完成 Writing superbloubuntu and filesystem accounting information: 完成

查看格式化結(jié)果,如下圖:

4. 寫入文件

將卡掛載,如果不想手動掛載,可以將卡從ubuntu系統(tǒng)中彈出,然后重新連接到ubuntu就會自動掛載。

buntu20@ubuntu:~/rootfs-ubuntu20$ df -l Filesystem 1K-bloubuntu Used Available Use% Mounted on ...... /dev/sdb1 3030800 4676 2868840 1% /media/ubuntu20/3fe3147c-e558-46fe-b197-e537e1852122 /dev/sdb2 12078132 30436 11427488 1% /media/ubuntu20/d7d23a79-b91b-413d-be42-903d1fc9e5a2

將文件拷貝到/dev/sdb1

buntu20@ubuntu:~/rootfs-ubuntu20$ df -l Filesystem 1K-bloubuntu Used Available Use% Mounted on ...... tmpfs 398264 36 398228 1% /run/user/1000 /dev/sdb1 3030800 824180 2049336 29% /media/ubuntu20/3fe3147c-e558-46fe-b197-e537e1852122 /dev/sdb2 12078132 30436 11427488 1% /media/ubuntu20/d7d23a79-b91b-413d-be42-903d1fc9e5a2 ubuntu20@ubuntu:~/rootfs-ubuntu20$ ll /media/ubuntu20/d7d23a79-b91b-413d-be42-903d1fc9e5a2 total 24 drwxr-xr-x 3 root root 4096 Apr 20 00:42 ./ drwxr-x---+ 4 root root 4096 Apr 20 01:44 ../ drwx------ 2 root root 16384 Apr 20 00:42 lost+found/ # cp命令加上-d選項,也可以使用dd命令 ubuntu20@ubuntu:~/rootfs-ubuntu20$ sudo cp -d -rf ./* /media/ubuntu20/d7d23a79-b91b-413d-be42-903d1fc9e5a2

最后需要執(zhí)行sync,以免沒有真正寫入到磁盤中。

ubuntu20@ubuntu:~/rootfs-ubuntu20$ sudo sync

Linux sync命令用于數(shù)據(jù)同步,sync命令是在關(guān)閉Linux系統(tǒng)時使用的。
Linux 系統(tǒng)中欲寫入硬盤的資料有的時候為了效率起見,會寫到 filesystem buffer 中,這個 buffer 是一塊記憶體空間,如果欲寫入硬盤的資料存于此 buffer 中,而系統(tǒng)又突然斷電的話,那么資料就會流失了,sync 指令會將存于 buffer 中的資料強制寫入硬盤中。

總結(jié)

以上是生活随笔為你收集整理的基于Ubuntu的linux环境制作嵌入式SD/TF启动卡的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。