树莓派挂载U盘
树莓派用的是8g的TF卡,想作为小型NAS有点小,存不了多少东西,于是将一个闲置的32G U盘挂载上,当作存储分区
以下为操作过程:
查看磁盘信息
pi@raspberrypi ~ $ sudo fdisk -l
Disk /dev/mmcblk0: 7990 MB, 7990149120 bytes
4 heads, 16 sectors/track, 243840 cylinders, total 15605760 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 identifier: 0x000981cb
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 15605759 7741440 83 Linux
Disk /dev/sda: 32.2 GB, 32229031936 bytes
255 heads, 63 sectors/track, 3918 cylinders, total 62947328 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 identifier: 0x15a8a090
Device Boot Start End Blocks Id System
/dev/sda1 2048 62947327 31472640 f W95 Ext'd (LBA)
/dev/sda5 4096 62947327 31471616 7 HPFS/NTFS/exFAT
这里看到,/dev/sda为32G的磁盘,分区格式为NTFS,现在就是要将改磁盘挂载为linux分区。
编辑分区
pi@raspberrypi ~ $ sudo fdisk /dev/sda
Command (m for help): p //查看分区信息
Disk /dev/sda: 32.2 GB, 32229031936 bytes
255 heads, 63 sectors/track, 3918 cylinders, total 62947328 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 identifier: 0x15a8a090
Device Boot Start End Blocks Id System
/dev/sda1 2048 62947327 31472640 f W95 Ext'd (LBA)
/dev/sda5 4096 62947327 31471616 7 HPFS/NTFS/exFAT
Command (m for help): d //删除分区
Partition number (1-5): 5
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32229031936 bytes
255 heads, 63 sectors/track, 3918 cylinders, total 62947328 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 identifier: 0x15a8a090
Device Boot Start End Blocks Id System
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)
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-62947327, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62947327, default 62947327):
Using default value 62947327
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32229031936 bytes
255 heads, 63 sectors/track, 3918 cylinders, total 62947328 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 identifier: 0x15a8a090
Device Boot Start End Blocks Id System
/dev/sda1 2048 62947327 31472640 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
以上完成后就会新建**/dev/sda1**分区
格式化分区
pi@raspberrypi ~ $ sudo mkfs.ext3 /dev/sda1
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1970416 inodes, 7868160 blocks
393408 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
241 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载U盘
pi@raspberrypi ~ $ mkdir ussd
pi@raspberrypi ~ $ sudo mount /dev/sda1 ./ussd/
pi@raspberrypi ~ $ df -hal
Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 3.0G 3.9G 44% /
/dev/root 7.3G 3.0G 3.9G 44% /
devtmpfs 211M 0 211M 0% /dev
tmpfs 44M 220K 44M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
tmpfs 88M 0 88M 0% /run/shm
devpts 0 0 0 - /dev/pts
/dev/mmcblk0p1 56M 19M 38M 34% /boot
/dev/sda1 30G 45M 28G 1% /home/pi/ussd
开机自动挂载U盘
编辑**/etc/fstab**
pi@raspberrypi ~ $ cat /etc/fstab
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
/dev/sda1 /home/pi/ussd ext3 defaults 0 0
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that