본문 바로가기

작업일지/Raspberry Pi(라즈베리파이)

USB외장디스크를 Root FS로 사용.

작업개요

 

 

 라즈비안(Raspbian)을 Boot FS와 Root FS로 나누어 사용한다.

 SD를 Boot FS(Swap포함)로, USB외장디스크는 Root FS로 사용한다. 

 

 

 


작업환경


 Boot FS용 SD

 Micro SD 4GByte (SD Adapter사용)

 Root FS용 USB 외장디스크  Micro SD 8GByte (Micro SD리더기 사용)
 작업OS

 Ubuntu (VMWARE)

 

 

 

빈 Root FS용 SD를 Raspberry Pi의 USB에 삽입하고, Boot FS용 SD는 Raspberry Pi SD슬롯에 넣고 Raspberry Pi를 구동한다.

 

 

 

작업할 디스크를 확인한다.

 

 $ sudo fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)      <= Boot FS
/dev/mmcblk0p2          122880     3788799     1832960   83  Linux                  <= 현재 사용중인 Root FS

Disk /dev/sda: 7964 MB, 7964983296 bytes
91 heads, 18 sectors/track, 9497 cylinders, total 15556608 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: 0x000dbfc6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    15556607     7777280   83  Linux            <= Root FS로 사용 예정중인 FS

 

 

[Root FS용 USB 외장디스크 작업]

현재 사용중인 Root FS를 사용 예정중인 FS에 dd를 이용해 복사한다.

그리고 소스와 타겟의 파티션 사이즈가 다를 경우 파티션 사이즈를 재설정 한다.

 


 $ sudo dd if=/dev/mmcblk0p2 of=/dev/sda1

223+1 records in
224+0 records out
1879048192 bytes (1.9 GB) copied, 2701.2 s, 696 kB/s

 

 $ sudo e2fsck -f /dev/sda1

e2fsck 1.42 (29-Nov-2011)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/sdc1: 64777/114688 files (0.1% non-contiguous), 321030/458240 blocks


 $ sudo resize2fs /dev/sda1

resize2fs 1.42 (29-Nov-2011)

Resizing the filesystem on /dev/sdc1 to 1007104 (4k) blocks.

The filesystem on /dev/sdc1 is now 1007104 blocks long.


 

 

 

[Boot FS용 SD작업]

현재 사용중인 Root FS를 삭제 하고 Boot FS를 제외한 나머지 공간을 swap로 한다.

(RootFS삭제 -> Swap파티션 생성)

 $ sudo fdisk /dev/mmcblk0

 

Command (m for help): p

 

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

 

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     3788799     1832960   83  Linux

 

Command (m for help): d
Partition number (1-4): 2

 

Command (m for help): p

 

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

 

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)

 

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (2048-7744511, default 2048): 122880
Last sector, +sectors or +size{K,M,G} (122880-7744511, default 7744511):
Using default value 7744511

 

Command (m for help): p

 

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

 

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7744511     3810816   83  Linux

 

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)

 

Command (m for help): p

 

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

 

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7744511     3810816   82  Linux swap / Solaris

 

Command (m for help): w
The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
 




swap파티션 확인

 

 $ sudo fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x000dbfc6

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7744511     3810816   82  Linux swap / Solaris

Disk /dev/sda: 7964 MB, 7964983296 bytes
91 heads, 18 sectors/track, 9497 cylinders, total 15556608 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: 0x000dbfc6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    15556607     7777280   83  Linux




swap파티션이 생성 되었으면 활성화 작업을 한다.

 

 

 $ sudo mkswap /dev/mmcblk0p2

Setting up swapspace version 1, size = 3810812 KiB
no label, UUID=bb4655e7-404e-4972-9a99-64db8baf7a72

 $ sudo swapon /dev/mmcblk0p2

 


※mkswap시 에러 발생의 경우 다음을 따른다.

 



swap파티션이 있음으로 기존의 swap파일을 제거한다.

 

 $ sudo swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            102396  0       -1                          <= 기존에 사용하던 swap파일
/dev/mmcblk0p2                          partition       3810812 0       -2

 $ sudo swapoff /var/swap       <= swap제거

 $ sudo rm -rf /var/swap          <= swap로 사용하던 파일삭제



 

부팅시 swap파티션을 자동으로 활성화 시키기 위해 fstab를 수정한다.

 

 $ sudo vi /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1       /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
/dev/mmcblk0p2               swap                    swap    defaults        0 0        <= 추가

 

 

 

 

 

작업 완료.

라즈베리 파이를 재구동 해본다.

 




속도에 많이 유리할것으로 기대 했으나 SD카드 하나만 사용하던것 보다 더 느린듯 하다.

※ 개선해볼 사항

  - SD Card를 Class6 -> Class10으로 변경.

  - 리더기를 좀더 성능이 우수한 것으로 변경.

  - SD카드 리더기 대신 USB HDD 외장장치를 사용해봄.

 








[2012.10.08]

Root FS를 MicroSD에서 USB MassStorage로 변경

속도 측정해봄


 $ time dd if=/dev/zero of=test bs=4096 count=10000; time sync
10000+0 records in
10000+0 records out
40960000 bytes (41 MB) copied, 4.1954 s, 9.8 MB/s

real    0m4.226s
user    0m0.020s
sys     0m0.640s

real    0m3.847s
user    0m0.000s
sys     0m0.000s


오래된 USB MassStorage임에도 불구하고 MicroSD보다 나은 속도를 보여줌.