라즈베리파이 등을 사용할 때, Root Filesystem의 size가 실제 SD 카드의 사이즈 보다 작게 인식 되는 경우가 있다.

라즈베리 파이의 경우에는 raspi-config를 사용하여 resize 할 수 있지만,

일반적인 Command를 사용해서 resize 하는 방법은 아래와 같다.

해당 과정 중에 문제가 생기는 경우 Kernel panic으로 다시 살릴 수 없기에 SD카드를 백업해 둘 것을 추천한다.

 - 백업은 win32 DiskImager로 Read 하면 이미지로 백업 가능. 추후 write로 복원


1. 현재 partition 확인

fdisk 로 device 정보 확인 후,

$ fdisk -l


해당 디바이스의 사이즈가 실제 디바이스의 사이즈보다 작은 경우

partition table을 다시 작성해준다.

이 때, partition table Start sector를 확인해 둔다.

$ fdisk /dev/mmcblk0


우선 기존의 작게 인식되는 partition을 삭제해 준다.

Command (m for help): d

Partition number (1,2, default 2): 2


새로 partition을 추가 한다.

이때, start sector가 위에서 확인한 기존 partition table과 일치해야 kernel panic이 나지 않을 것이다.

Command (m for help): n

Partition type

p    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 (2088450-31116287, default 2088960): 2088450

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


작성된 partition table을 저장 하고 종료한다.

Command (m for help): w


현재 사용 중인 시스템에서는 partition table을 다시 작성한 것이 재부팅 후에 인식이 되므로, 시스템을 재부팅 해준다.

$ shutdown -r now


재부팅 된 시스템에서, partition 사이즈가 제대로 인식이 되는지 확인한다.

$ fdisk -l


제대로 인식이 됐다면, resize를 해준다.

$ resize2fs /dev/mmcblk0p2


끗.

'Programming > RaspberryPi' 카테고리의 다른 글

Rasbian qbittorrent-nox installation  (0) 2019.11.19
SD card image backup  (0) 2018.10.12
RaspberryPi Remote Desktop Client  (0) 2018.06.01
Raspbian Korean(Hangul) Install  (0) 2018.05.18
Raspbian Install  (0) 2018.05.16

wget 등 사용 시 Progress가 프린팅 된다.

Carriage return(\r) 과 fflush를 활용하면 이쁘게 Progress를 print 할 수 있다.


percent = (float)i*100/(MEM_SIZE/sizeof(int));

printf("\r[");

for(j=0; j<50; j++){

if(j<(int)percent/2)

        printf(">");

else

printf(" ");

}

printf("]%.2f%%",percent);

fflush(stdout);


'Programming > C Language' 카테고리의 다른 글

Check the system's Endianness  (0) 2019.04.23
static  (0) 2018.07.13
가변 인자(variable arguments) stdarg.h  (0) 2017.12.11
extern  (0) 2017.06.21
static  (0) 2017.06.20

인터넷이 되지 않는 어떤 머신에

OS가 Ubuntu가 설치 된 경우

apt get을 통해 패키지를 설치하고 싶지만, 인터넷이 되지 않기에 

인터넷이 되는 다른 머신에서 repository에서 필요한 패키지를 찾아 직접 설치 해야 한다.


Python을 이용해 이를 자동화 할 수 있는 코드를 짜보았다.

import gzip

import os

import wget

import sys


repository="old-releases.ubuntu.com/ubuntu"

ARCH="arm64"

release="vivid"

branch="main"


def check_dependency(package_depends):

if package_depends == None:

return;

depends_list_pre = package_depends.split(", ")

depends_list_post = [] #[depend_package, version, comparator]

for depend in depends_list_pre:

if depend.find("(") != -1:

depend_package = depend[:depend.find("(")-1]

version = depend[depend.find(" ", depend.find("("))+1:depend.find(")")]

comparator = depend[depend.find("(")+1: depend.find(" ", depend.find("("))]

else:

depend_package = depend

version = ""

comparator = ""

depends_list_post.append([depend_package, version, comparator])

print(depends_list_post)

for depend, ver, com in depends_list_post:

find_package(depend, ver, com)


def down_pacakge(filename):

file_path_and_name = filename.split("/")

if not os.path.exists("./"+repository+"/"+release+"/"+branch+"/deb/"+file_path_and_name[-1]):

url = "http://"+repository+"/"+filename

print(url)

wget.download(url, "./"+repository+"/"+release+"/"+branch+"/deb/"+file_path_and_name[-1])

return 1;

return 0;

def find_package(package_name, version="", comparator=""):

package_list_file = "./"+repository+"/"+release+"/"+branch+"/binary-"+ARCH+"/Packages.gz"

if not os.path.exists(package_list_file):

if not os.path.exists("./"+repository+"/"+release+"/"+branch+"/binary-"+ARCH):

os.mkdir("./"+repository+"/"+release+"/"+branch+"/binary-"+ARCH)

#download Packages.gz

url = "http://"+repository+"/dists/"+release+"/"+branch+"/binary-"+ARCH+"/Packages.gz"

wget.download(url, package_list_file)

package_list = []

package_info = {}

package_list_filep = gzip.open(package_list_file, 'r')

for line in package_list_filep:

line_str = line.decode("utf-8")

line_str = line_str.replace("\n", "")

if line_str == "":

package_list.append(package_info)

package_info = {}

else:

line_elements = line_str.split(": ")

package_info.update({line_elements[0] : line_elements[1]})

package_list_filep.close()

for package in package_list:

if package.get("Package") == package_name:

if(version==""):

if down_pacakge(package.get("Filename")):

check_dependency(package.get("Depends"))

return package;

elif comparator == "=" and package.get("Version") == version:

if down_pacakge(package.get("Filename")):

check_dependency(package.get("Depends"))

return package;

elif comparator == ">=" and package.get("Version") >= version:

if down_pacakge(package.get("Filename")):

check_dependency(package.get("Depends"))

return package;

print("ERROR::Cannot find package("+package_name+")")


for argument in sys.argv:

if argument == "apt_get.py":

continue;

else:

find_package(argument)


패키지는 해당 머신에 복사해주시고,

설치는 아래와 같이 하면 된다.

$ sudo dpkg -i *.deb


원리는 간단하다.

repository 에는 package 정보가 담긴 파일이 존재하고(architecture / release / branch)

해당 파일에는 Package 의 이름, 버전, dependency, 패키지 파일 경로 등이 담겨 있다.

패키지 설치를 위해서는 각 패키지 파일(.deb)을 다운 받아야하고, 또한 dependency 파일들의 패키지 파일도 다운 받아야 한다.

다운받은 모든 파일을 dpkg 를 통해 한 번에 설치 하면 된다.




+ Recent posts