파티션이 설정되어 있는 .img 파일을 SD 카드 또는  USB 등 기타 장치로 이미지를 복사( dd 명령 등..) 할 경우 고정된 사이즈의 파티션으로 설정됩니다. 즉 .img 가 2GB 이고, SD카드는 8GB일 경우 dd 명령으로 이미지를 복사하면 2GB만 사용 가능하고, 나머지 6GB는 따로 사용해야 합니다.

이를 아래의 방법으로 모든 공간을 사용할 수 있게 바꾸어 보도록 하겠습니다.


아래의 내용은 SD카드가 아닌 파일이미지를 가지고 설명하도록 하겠습니다. ( SD 또는 USB 등 기타 장치도 같은 방식으로 하면 됩니다. )


1. 파티션 확인 하기.


    $ sudo fdisk falinux-trusty.img


Welcome to fdisk (util-linux 2.25.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.



Command (m for help): p

Disk falinux-trusty.img: 6.9 GiB, 7340032000 bytes, 14336000 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: 0x229592a6


Device                     Boot Start     End              Sectors        Size Id     Type

falinux-trusty.img1       2048      7372799      7370752    3.5G        83 Linux


        Command (m for help): q


2. 파티션 사이즈 늘리기


    $ sudo fdisk falinux-trusty.img


Welcome to fdisk (util-linux 2.25.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.



Command (m for help): p

Disk falinux-trusty.img: 6.9 GiB, 7340032000 bytes, 14336000 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: 0x229592a6


Device                           Boot Start     End              Sectors         Size        Id Type

falinux-trusty.img1       2048             7372799     7370752      3.5G     83 Linux


Command (m for help): d

Selected partition 1

Partition 1 has been deleted.


Command (m for help): n

Partition type

  p   primary (0 primary, 0 extended, 4 free)

  e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-14335999, default 2048): 2048

Last sector, +sectors or +size{K,M,G,T,P} (2048-14335999, default 14335999): 14335999


Created a new partition 1 of type 'Linux' and of size 6.9 GiB.


Command (m for help): w

The partition table has been altered.

Syncing disks.


   $ sudo fdisk falinux-trusty.img


Welcome to fdisk (util-linux 2.25.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.


Command (m for help): p

Disk falinux-trusty.img: 6.9 GiB, 7340032000 bytes, 14336000 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: 0x229592a6


Device                            Boot Start      End                Sectors         Size         Id Type

falinux-trusty.img1       2048              14335999     14333952     6.9G      83 Linux


Command (m for help): q


   $ sudo losetup -o 1048576 /dev/loop0 falinux-trusty.img

   $ sudo fsck -fv /dev/loop0 

fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
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

     125650 inodes used (54.49%, out of 230608)
 16 non-contiguous files (0.0%)
 43 non-contiguous directories (0.0%)
    # of inodes with ind/dind/tind blocks: 0/0/0
    Extent depth histogram: 96009/4
     581538 blocks used (63.12%, out of 921344)
  0 bad blocks
  1 large file

      80699 regular files
      10098 directories
 56 character device files
 25 block device files
  0 fifos
 31 links
      34763 symbolic links (29548 fast symbolic links)
  0 sockets
------------
     125672 files

   $ sudo resize2fs /dev/loop0

resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/loop0 to 1791744 (4k) blocks.
The filesystem on /dev/loop0 is now 1791744 (4k) blocks long.


3. 확인하기


   $ sudo mkdir tmp

   $ sudo mount /dev/loop0 tmp/

   $ df -h 

Filesystem Size   Used Avail Use% Mounted on
udev             7.8G     0   7.8G   0% /dev
tmpfs           1.6G   21M   1.6G   2% /run
/dev/sda1        77G   12G   61G   16% /
tmpfs           7.8G   326M   7.5G   5% /dev/shm
tmpfs           5.0M   8.0K   5.0M   1% /run/lock
tmpfs           7.8G     0   7.8G   0% /sys/fs/cgroup
/dev/sda6       825G   363G   421G   47% /home
cgmfs           100K     0   100K   0% /run/cgmanager/fs
tmpfs           1.6G   88K   1.6G   1% /run/user/1000
/dev/loop0      6.7G   2.2G   4.3G   34% /imx6/boundary/tmp


4. 마운트 해지 하기

    $ sudo umount tmp
    $ sudo losetup -d /dev/loop0